src/HOL/Tools/res_clause.ML
author paulson
Wed, 27 Jul 2005 11:30:34 +0200
changeset 16925 0fd7b1438d28
parent 16903 bf42a9071ad1
child 16953 f025e0dc638b
permissions -rw-r--r--
simpler variable names, and no types for monomorphic constants
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     1
(*  Author: Jia Meng, Cambridge University Computer Laboratory
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     2
    ID: $Id$
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     3
    Copyright 2004 University of Cambridge
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     4
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     5
ML data structure for storing/printing FOL clauses and arity clauses.
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     6
Typed equality is treated differently.
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     7
*)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     8
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     9
signature RES_CLAUSE =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    10
  sig
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    11
    exception ARCLAUSE of string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    12
    exception CLAUSE of string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    13
    type arityClause 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    14
    type classrelClause
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
    15
    val classrelClauses_of : string * string list -> classrelClause list
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    16
    type clause
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
    17
    val init : theory -> unit
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    18
    val keep_types : bool ref
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    19
    val make_axiom_arity_clause :
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    20
       string * (string * string list list) -> arityClause
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    21
    val make_axiom_classrelClause :
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
    22
       string * string option -> classrelClause
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    23
    val make_axiom_clause : Term.term -> string * int -> clause
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    24
    val make_conjecture_clause : Term.term -> clause
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    25
    val make_conjecture_clause_thm : Thm.thm -> clause
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    26
    val make_hypothesis_clause : Term.term -> clause
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    27
    val special_equal : bool ref
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    28
    val tptp_arity_clause : arityClause -> string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    29
    val tptp_classrelClause : classrelClause -> string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    30
    val tptp_clause : clause -> string list
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    31
    val clause_info : clause ->  string * string
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    32
    val tptp_clauses2str : string list -> string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    33
    val typed : unit -> unit
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    34
    val untyped : unit -> unit
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
    35
    val clause2tptp : clause -> string * string list
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
    36
    val tfree_clause : string -> string
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    37
  end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    38
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    39
structure ResClause : RES_CLAUSE =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    40
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    41
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    42
(* Added for typed equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    43
val special_equal = ref false; (* by default,equality does not carry type information *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    44
val eq_typ_wrapper = "typeinfo"; (* default string *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    45
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    46
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    47
val schematic_var_prefix = "V_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    48
val fixed_var_prefix = "v_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    49
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    50
val tvar_prefix = "T_";
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    51
val tfree_prefix = "t_";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    52
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    53
val clause_prefix = "cls_"; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    54
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    55
val arclause_prefix = "arcls_" 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    56
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    57
val const_prefix = "c_";
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    58
val tconst_prefix = "tc_"; 
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    59
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
    60
val class_prefix = "class_"; 
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    61
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    62
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    63
(**** some useful functions ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    64
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    65
val const_trans_table =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    66
      Symtab.make [("op =", "equal"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    67
	  	   ("op <=", "lessequals"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    68
		   ("op <", "less"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    69
		   ("op &", "and"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    70
		   ("op |", "or"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    71
		   ("op -->", "implies"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    72
		   ("op :", "in"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    73
		   ("op Un", "union"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    74
		   ("op Int", "inter")];
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    75
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    76
val type_const_trans_table =
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    77
      Symtab.make [("*", "t_prod"),
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    78
	  	   ("+", "t_sum"),
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
    79
		   ("~=>", "t_map")];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    80
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    81
(*Escaping of special characters.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    82
  Alphanumeric characters are left unchanged.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    83
  The character _ goes to __
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    84
  Characters in the range ASCII space to / go to _A to _P, respectively.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    85
  Other printing characters go to _NNN where NNN is the decimal ASCII code.*)
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    86
local
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    87
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    88
val A_minus_space = Char.ord #"A" - Char.ord #" ";
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    89
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    90
fun ascii_of_c c =
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    91
  if Char.isAlphaNum c then String.str c
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    92
  else if c = #"_" then "__"
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    93
  else if #" " <= c andalso c <= #"/" 
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    94
       then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space))
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    95
  else if Char.isPrint c then ("_" ^ Int.toString (Char.ord c))
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    96
  else ""
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    97
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    98
in
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    99
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   100
val ascii_of = String.translate ascii_of_c;
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   101
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   102
end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   103
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   104
(*Remove the initial ' character from a type variable, if it is present*)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   105
fun trim_type_var s =
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   106
  if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   107
  else error ("trim_type: Malformed type variable encountered: " ^ s);
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   108
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   109
fun ascii_of_indexname (v,0) = ascii_of v
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   110
  | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ string_of_int i;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   111
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   112
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   113
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   114
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   115
(*Type variables contain _H because the character ' translates to that.*)
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   116
fun make_schematic_type_var (x,i) = 
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   117
      tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i));
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   118
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x));
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   119
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   120
fun make_fixed_const c =
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   121
    case Symtab.lookup (const_trans_table,c) of
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   122
        SOME c' => c'
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   123
      | NONE =>  const_prefix ^ (ascii_of c);
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   124
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   125
fun make_fixed_type_const c = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   126
    case Symtab.lookup (type_const_trans_table,c) of
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   127
        SOME c' => c'
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   128
      | NONE =>  tconst_prefix ^ (ascii_of c);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   129
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   130
fun make_type_class clas = class_prefix ^ (ascii_of clas);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   131
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   132
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   133
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   134
(***** definitions and functions for FOL clauses, prepared for conversion into TPTP format or SPASS format. *****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   135
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   136
val keep_types = ref true; (* default is true *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   137
fun untyped () = (keep_types := false);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   138
fun typed () = (keep_types := true);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   139
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   140
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   141
datatype kind = Axiom | Hypothesis | Conjecture;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   142
fun name_of_kind Axiom = "axiom"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   143
  | name_of_kind Hypothesis = "hypothesis"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   144
  | name_of_kind Conjecture = "conjecture";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   145
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   146
type clause_id = int;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   147
type axiom_name = string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   148
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   149
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   150
type polarity = bool;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   151
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   152
type indexname = Term.indexname;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   153
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   154
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   155
(* "tag" is used for vampire specific syntax  *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   156
type tag = bool; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   157
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   158
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   159
val id_ref = ref 0;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   160
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   161
fun generate_id () = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   162
    let val id = !id_ref
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   163
    in id_ref := id + 1; id end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   164
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   165
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   166
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   167
(**** Isabelle FOL clauses ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   168
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   169
(* by default it is false *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   170
val tagged = ref false;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   171
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   172
type pred_name = string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   173
type sort = Term.sort;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   174
type fol_type = string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   175
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   176
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   177
datatype type_literal = LTVar of string | LTFree of string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   178
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   179
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   180
datatype folTerm = UVar of string * fol_type| Fun of string * fol_type * folTerm list;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   181
datatype predicate = Predicate of pred_name * fol_type * folTerm list;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   182
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   183
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   184
datatype literal = Literal of polarity * predicate * tag;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   185
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   186
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   187
datatype typ_var = FOLTVar of indexname | FOLTFree of string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   188
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   189
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   190
(* ML datatype used to repsent one single clause: disjunction of literals. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   191
datatype clause = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   192
	 Clause of {clause_id: clause_id,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   193
		    axiom_name: axiom_name,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   194
		    kind: kind,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   195
		    literals: literal list,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   196
		    types_sorts: (typ_var * sort) list, 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   197
                    tvar_type_literals: type_literal list, 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   198
                    tfree_type_literals: type_literal list };
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   199
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   200
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   201
exception CLAUSE of string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   202
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   203
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   204
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   205
(*** make clauses ***)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   206
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   207
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   208
fun make_clause (clause_id,axiom_name,kind,literals,
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   209
                 types_sorts,tvar_type_literals,
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   210
                 tfree_type_literals) =
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   211
     Clause {clause_id = clause_id, axiom_name = axiom_name, kind = kind, 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   212
             literals = literals, types_sorts = types_sorts,
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   213
             tvar_type_literals = tvar_type_literals,
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   214
             tfree_type_literals = tfree_type_literals};
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   215
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   216
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   217
(*Definitions of the current theory--to allow suppressing types.*)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   218
val curr_defs = ref Defs.empty;
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   219
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   220
(*Initialize the type suppression mechanism with the current theory before
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   221
    producing any clauses!*)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   222
fun init thy = (curr_defs := Theory.defs_of thy);
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   223
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   224
(*Types aren't needed if the constant has at most one definition and is monomorphic*)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   225
fun no_types_needed s =
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   226
  (case Defs.fast_overloading_info (!curr_defs) s of
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   227
      NONE => true
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   228
    | SOME (T,len,_) => len <= 1 andalso null (typ_tvars T))
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   229
    
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   230
(*Flatten a type to a string while accumulating sort constraints on the TFress and
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   231
  TVars it contains.*)    
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   232
fun type_of (Type (a, [])) = (make_fixed_type_const a,[]) 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   233
  | type_of (Type (a, Ts)) = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   234
      let val foltyps_ts = map type_of Ts
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   235
	  val (folTyps,ts) = ListPair.unzip foltyps_ts
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   236
	  val ts' = ResLib.flat_noDup ts
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   237
      in    
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   238
	  (((make_fixed_type_const a) ^ (ResLib.list_to_string folTyps)), ts') 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   239
      end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   240
  | type_of (TFree (a, s)) = (make_fixed_type_var a, [((FOLTFree a),s)])
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   241
  | type_of (TVar (v, s))  = (make_schematic_type_var v, [((FOLTVar v),s)]);
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   242
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   243
fun maybe_type_of c T =
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   244
 if no_types_needed c then ("",[]) else type_of T;
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   245
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   246
(* Any variables created via the METAHYPS tactical should be treated as
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   247
   universal vars, although it is represented as "Free(...)" by Isabelle *)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   248
val isMeta = String.isPrefix "METAHYP1_"
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   249
    
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   250
fun pred_name_type (Const(c,T)) = (make_fixed_const c, maybe_type_of c T)
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   251
  | pred_name_type (Free(x,T))  = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   252
      if isMeta x then raise CLAUSE("Predicate Not First Order") 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   253
      else (make_fixed_var x, type_of T)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   254
  | pred_name_type (Var(_,_))   = raise CLAUSE("Predicate Not First Order")
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   255
  | pred_name_type _          = raise CLAUSE("Predicate input unexpected");
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   256
15615
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   257
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   258
(* For type equality *)
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   259
(* here "arg_typ" is the type of "="'s argument's type, not the type of the equality *)
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   260
(* Find type of equality arg *)
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   261
fun eq_arg_type (Type("fun",[T,_])) = 
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   262
    let val (folT,_) = type_of T;
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   263
    in
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   264
	folT
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   265
    end;
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   266
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   267
fun fun_name_type (Const(c,T)) = (make_fixed_const c, maybe_type_of c T)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   268
  | fun_name_type (Free(x,T)) = (make_fixed_var x,type_of T)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   269
  | fun_name_type _ = raise CLAUSE("Function Not First Order");
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   270
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   271
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   272
(* FIX - add in funcs and stuff to this *)
15615
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   273
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   274
fun term_of (Var(ind_nm,T)) = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   275
      let val (folType,ts) = type_of T
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   276
      in
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   277
	  (UVar(make_schematic_var ind_nm, folType), ts)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   278
      end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   279
  | term_of (Free(x,T)) = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   280
      let val (folType,ts) = type_of T
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   281
      in
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   282
	  if isMeta x then (UVar(make_schematic_var(x,0), folType), ts)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   283
	  else (Fun(make_fixed_var x,folType,[]), ts)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   284
      end
15615
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   285
  | term_of (Const(c,T)) =  (* impossible to be equality *)
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   286
      let val (folType,ts) = type_of T
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   287
      in
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   288
	  (Fun(make_fixed_const c,folType,[]), ts)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   289
      end    
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   290
  | term_of (app as (t $ a)) = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   291
      let val (f,args) = strip_comb app
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   292
	  fun term_of_aux () = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   293
	      let val (funName,(funType,ts1)) = fun_name_type f
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   294
		   val (args',ts2) = ListPair.unzip (map term_of args)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   295
		   val ts3 = ResLib.flat_noDup (ts1::ts2)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   296
	      in
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   297
		  (Fun(funName,funType,args'),ts3)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   298
	      end
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   299
	  fun term_of_eq ((Const ("op =", typ)),args) =
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   300
	      let val arg_typ = eq_arg_type typ
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   301
		  val (args',ts) = ListPair.unzip (map term_of args)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   302
		  val equal_name = make_fixed_const ("op =")
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   303
	      in
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   304
		  (Fun(equal_name,arg_typ,args'),ResLib.flat_noDup ts)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   305
	      end
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   306
      in
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   307
	  case f of Const ("op =", typ) => term_of_eq (f,args)
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   308
		  | Const(_,_) => term_of_aux ()
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   309
		  | Free(s,_)  => if isMeta s 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   310
		                  then raise CLAUSE("Function Not First Order") 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   311
		                  else term_of_aux()
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   312
		  | _          => raise CLAUSE("Function Not First Order")
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   313
      end
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   314
  | term_of _ = raise CLAUSE("Function Not First Order"); 
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   315
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   316
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   317
fun pred_of_eq ((Const ("op =", typ)),args) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   318
    let val arg_typ = eq_arg_type typ 
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15615
diff changeset
   319
	val (args',ts) = ListPair.unzip (map term_of args)
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   320
	val equal_name = make_fixed_const "op ="
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   321
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   322
	(Predicate(equal_name,arg_typ,args'),ResLib.flat_noDup ts)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   323
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   324
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   325
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   326
(* changed for non-equality predicate *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   327
(* The input "pred" cannot be an equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   328
fun pred_of_nonEq (pred,args) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   329
    let val (predName,(predType,ts1)) = pred_name_type pred
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15615
diff changeset
   330
	val (args',ts2) = ListPair.unzip (map term_of args)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   331
	val ts3 = ResLib.flat_noDup (ts1::ts2)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   332
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   333
	(Predicate(predName,predType,args'),ts3)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   334
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   335
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   336
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   337
(* Changed for typed equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   338
(* First check if the predicate is an equality or not, then call different functions for equality and non-equalities *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   339
fun predicate_of term =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   340
    let val (pred,args) = strip_comb term
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   341
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   342
	case pred of (Const ("op =", _)) => pred_of_eq (pred,args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   343
		   | _ => pred_of_nonEq (pred,args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   344
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   345
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   346
 
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   347
fun literals_of_term ((Const("Trueprop",_) $ P),lits_ts) = literals_of_term (P,lits_ts)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   348
  | literals_of_term ((Const("op |",_) $ P $ Q),(lits,ts)) = 
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   349
      let val (lits',ts') = literals_of_term (P,(lits,ts))
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   350
      in
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   351
	  literals_of_term (Q, (lits',ts'))
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   352
      end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   353
  | literals_of_term ((Const("Not",_) $ P),(lits,ts)) = 
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   354
      let val (pred,ts') = predicate_of P
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   355
	  val lits' = Literal(false,pred,false) :: lits
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   356
	  val ts'' = ResLib.no_rep_app ts ts'
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   357
      in
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   358
	  (lits',ts'')
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   359
      end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   360
  | literals_of_term (P,(lits,ts)) = 
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   361
      let val (pred,ts') = predicate_of P
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   362
	  val lits' = Literal(true,pred,false) :: lits
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   363
	  val ts'' = ResLib.no_rep_app ts ts' 
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   364
      in
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   365
	  (lits',ts'')
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   366
      end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   367
     
15956
0da64b5a9a00 theorem names for caching
paulson
parents: 15774
diff changeset
   368
fun literals_of_thm thm = literals_of_term (prop_of thm, ([],[]));
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   369
    
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   370
(*Make literals for sorted type variables*) 
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   371
fun sorts_on_typs (_, []) = []
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   372
  | sorts_on_typs (v, "HOL.type" :: s) =
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   373
      sorts_on_typs (v,s)   (*Ignore sort "type"*)
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   374
  | sorts_on_typs ((FOLTVar(indx)), (s::ss)) =
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   375
      LTVar((make_type_class s) ^ 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   376
        "(" ^ (make_schematic_type_var indx) ^ ")") :: 
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   377
      (sorts_on_typs ((FOLTVar(indx)), ss))
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   378
  | sorts_on_typs ((FOLTFree(x)), (s::ss)) =
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   379
      LTFree((make_type_class s) ^ "(" ^ (make_fixed_type_var(x)) ^ ")") :: 
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   380
      (sorts_on_typs ((FOLTFree(x)), ss));
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   381
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   382
(*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: 16039
diff changeset
   383
  The first is for TVars, the second for TFrees.*)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   384
fun add_typs_aux [] = ([],[])
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   385
  | add_typs_aux ((FOLTVar(indx),s)::tss) = 
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   386
      let val vs = sorts_on_typs (FOLTVar(indx), s)
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   387
	  val (vss,fss) = add_typs_aux tss
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   388
      in
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   389
	  (ResLib.no_rep_app vs vss, fss)
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   390
      end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   391
  | add_typs_aux ((FOLTFree(x),s)::tss) =
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   392
      let val fs = sorts_on_typs (FOLTFree(x), s)
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   393
	  val (vss,fss) = add_typs_aux tss
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   394
      in
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   395
	  (vss, ResLib.no_rep_app fs fss)
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   396
      end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   397
16199
ee95ab217fee no longer emits literals for type class HOL.type; also minor tidying
paulson
parents: 16039
diff changeset
   398
fun add_typs (Clause cls) = add_typs_aux (#types_sorts cls)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   399
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   400
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   401
(** make axiom clauses, hypothesis clauses and conjecture clauses. **)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   402
   
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   403
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   404
fun make_conjecture_clause_thm thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   405
    let val (lits,types_sorts) = literals_of_thm thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   406
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   407
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   408
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   409
	make_clause(cls_id,"",Conjecture,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   410
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   411
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   412
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   413
fun make_axiom_clause term (axname,cls_id) =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   414
    let val (lits,types_sorts) = literals_of_term (term,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   415
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   416
    in 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   417
	make_clause(cls_id,axname,Axiom,lits,types_sorts,tvar_lits,tfree_lits)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   418
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   419
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   420
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   421
fun make_hypothesis_clause term =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   422
    let val (lits,types_sorts) = literals_of_term (term,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   423
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   424
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   425
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   426
	make_clause(cls_id,"",Hypothesis,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   427
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   428
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   429
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   430
fun make_conjecture_clause term =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   431
    let val (lits,types_sorts) = literals_of_term (term,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   432
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   433
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   434
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   435
	make_clause(cls_id,"",Conjecture,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   436
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   437
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   438
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   439
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   440
(**** Isabelle arities ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   441
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   442
exception ARCLAUSE of string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   443
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   444
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   445
type class = string; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   446
type tcons = string; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   447
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   448
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   449
datatype arLit = TConsLit of bool * (class * tcons * string list) | TVarLit of bool * (class * string);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   450
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   451
datatype arityClause =  
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   452
	 ArityClause of {clause_id: clause_id,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   453
			 kind: kind,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   454
			 conclLit: arLit,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   455
			 premLits: arLit list};
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   456
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   457
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   458
fun get_TVars 0 = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   459
  | get_TVars n = ("T_" ^ (string_of_int n)) :: get_TVars (n-1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   460
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   461
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   462
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   463
fun pack_sort(_,[])  = raise ARCLAUSE("Empty Sort Found") 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   464
  | pack_sort(tvar, [cls]) = [(make_type_class cls, tvar)] 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   465
  | pack_sort(tvar, cls::srt) =  (make_type_class cls,tvar) :: (pack_sort(tvar, srt));
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   466
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   467
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   468
fun make_TVarLit (b,(cls,str)) = TVarLit(b,(cls,str));
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   469
fun make_TConsLit (b,(cls,tcons,tvars)) = TConsLit(b,(make_type_class cls,make_fixed_type_const tcons,tvars));
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   470
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   471
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   472
fun make_arity_clause (clause_id,kind,conclLit,premLits) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   473
    ArityClause {clause_id = clause_id, kind = kind, conclLit = conclLit, premLits = premLits};
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   474
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   475
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   476
fun make_axiom_arity_clause (tcons,(res,args)) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   477
     let val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   478
	 val nargs = length args
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   479
	 val tvars = get_TVars nargs
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   480
	 val conclLit = make_TConsLit(true,(res,tcons,tvars))
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15615
diff changeset
   481
         val tvars_srts = ListPair.zip (tvars,args)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   482
	 val tvars_srts' = ResLib.flat_noDup(map pack_sort tvars_srts)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   483
         val false_tvars_srts' = ResLib.pair_ins false tvars_srts'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   484
	 val premLits = map make_TVarLit false_tvars_srts'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   485
     in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   486
	 make_arity_clause (cls_id,Axiom,conclLit,premLits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   487
     end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   488
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   489
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   490
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   491
(**** Isabelle class relations ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   492
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   493
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   494
datatype classrelClause = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   495
	 ClassrelClause of {clause_id: clause_id,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   496
			    subclass: class,
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   497
			    superclass: class option};
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   498
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   499
fun make_classrelClause (clause_id,subclass,superclass) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   500
    ClassrelClause {clause_id = clause_id,subclass = subclass, superclass = superclass};
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   501
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   502
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   503
fun make_axiom_classrelClause (subclass,superclass) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   504
    let val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   505
	val sub = make_type_class subclass
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   506
	val sup = case superclass of NONE => NONE 
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   507
				   | SOME s => SOME (make_type_class s)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   508
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   509
	make_classrelClause(cls_id,sub,sup)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   510
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   511
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   512
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   513
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   514
fun classrelClauses_of_aux (sub,[]) = []
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   515
  | classrelClauses_of_aux (sub,(sup::sups)) = make_axiom_classrelClause(sub,SOME sup) :: (classrelClauses_of_aux (sub,sups));
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   516
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   517
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   518
fun classrelClauses_of (sub,sups) = 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   519
    case sups of [] => [make_axiom_classrelClause (sub,NONE)]
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   520
	       | _ => classrelClauses_of_aux (sub, sups);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   521
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   522
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   523
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   524
(***** convert clauses to tptp format *****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   525
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   526
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   527
fun string_of_clauseID (Clause cls) = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   528
    clause_prefix ^ string_of_int (#clause_id cls);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   529
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   530
fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   531
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   532
fun string_of_axiomName (Clause cls) = #axiom_name cls;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   533
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   534
(****!!!! Changed for typed equality !!!!****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   535
fun wrap_eq_type typ t = eq_typ_wrapper ^"(" ^ t ^ "," ^ typ ^ ")";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   536
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   537
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   538
(****!!!! Changed for typed equality !!!!****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   539
(* Only need to wrap equality's arguments with "typeinfo" if the output clauses are typed && if we specifically ask for types to be included.   *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   540
fun string_of_equality (typ,terms) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   541
    let val [tstr1,tstr2] = map string_of_term terms
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   542
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   543
	if ((!keep_types) andalso (!special_equal)) then 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   544
	    "equal(" ^ (wrap_eq_type typ tstr1) ^ "," ^ (wrap_eq_type typ tstr2) ^ ")"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   545
	else
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   546
	    "equal(" ^ tstr1 ^ "," ^ tstr2 ^ ")"
15615
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   547
    end
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   548
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   549
and
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   550
    string_of_term (UVar(x,_)) = x
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   551
  | string_of_term (Fun("equal",typ,terms)) = string_of_equality(typ,terms)
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   552
  | string_of_term (Fun (name,typ,[])) = name
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   553
  | string_of_term (Fun (name,typ,terms)) = 
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   554
    let val terms' = map string_of_term terms
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   555
    in
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   556
        if !keep_types andalso typ<>"" then name ^ (ResLib.list_to_string (terms' @ [typ]))
15615
d72b1867d09d ensuring that "equal" is not a function
paulson
parents: 15610
diff changeset
   557
        else name ^ (ResLib.list_to_string terms')
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   558
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   559
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   560
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   561
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   562
(* Changed for typed equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   563
(* before output the string of the predicate, check if the predicate corresponds to an equality or not. *)
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   564
fun string_of_predicate (Predicate("equal",typ,terms)) = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   565
       string_of_equality(typ,terms)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   566
  | string_of_predicate (Predicate(name,_,[])) = name 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   567
  | string_of_predicate (Predicate(name,typ,terms)) = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   568
      let val terms_as_strings = map string_of_term terms
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   569
      in
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   570
	  if !keep_types andalso typ<>""
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   571
	  then name ^ (ResLib.list_to_string  (terms_as_strings @ [typ]))
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   572
	  else name ^ (ResLib.list_to_string terms_as_strings) 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   573
      end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   574
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   575
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   576
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   577
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   578
fun tptp_literal (Literal(pol,pred,tag)) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   579
    let val pred_string = string_of_predicate pred
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   580
	val tagged_pol = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   581
	      if (tag andalso !tagged) then (if pol then "+++" else "---")
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   582
	      else (if pol then "++" else "--")
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   583
     in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   584
	tagged_pol ^ pred_string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   585
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   586
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   587
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   588
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   589
fun tptp_of_typeLit (LTVar x) = "--" ^ x
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   590
  | tptp_of_typeLit (LTFree x) = "++" ^ x;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   591
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   592
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   593
fun gen_tptp_cls (cls_id,ax_name,knd,lits) = 
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   594
    let val ax_str = (if ax_name = "" then "" else ("_" ^ ascii_of ax_name))
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   595
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   596
	"input_clause(" ^ cls_id ^ ax_str ^ "," ^ knd ^ "," ^ lits ^ ")."
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   597
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   598
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   599
fun gen_tptp_type_cls (cls_id,knd,tfree_lit,idx) = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   600
    "input_clause(" ^ cls_id ^ "_tcs" ^ (string_of_int idx) ^ "," ^ 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   601
    knd ^ ",[" ^ tfree_lit ^ "]).";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   602
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   603
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   604
fun tptp_clause_aux (Clause cls) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   605
    let val lits = map tptp_literal (#literals cls)
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   606
	val tvar_lits_strs =
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   607
	      if (!keep_types) 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   608
	      then (map tptp_of_typeLit (#tvar_type_literals cls)) 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   609
	      else []
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   610
	val tfree_lits = 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   611
	      if (!keep_types) 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   612
	      then (map tptp_of_typeLit (#tfree_type_literals cls)) 
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   613
	      else []
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   614
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   615
	(tvar_lits_strs @ lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   616
    end; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   617
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   618
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   619
fun tptp_clause cls =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   620
    let val (lits,tfree_lits) = tptp_clause_aux cls (*"lits" includes the typing assumptions (TVars)*)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   621
	val cls_id = string_of_clauseID cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   622
	val ax_name = string_of_axiomName cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   623
	val knd = string_of_kind cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   624
	val lits_str = ResLib.list_to_string' lits
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   625
	val cls_str = gen_tptp_cls(cls_id,ax_name,knd,lits_str) 			fun typ_clss k [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   626
          | typ_clss k (tfree :: tfrees) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   627
            (gen_tptp_type_cls(cls_id,knd,tfree,k)) ::  (typ_clss (k+1) tfrees)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   628
    in 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   629
	cls_str :: (typ_clss 0 tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   630
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   631
16794
paulson
parents: 16767
diff changeset
   632
fun clause_info cls = (string_of_axiomName cls, string_of_clauseID cls);
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
   633
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   634
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   635
fun clause2tptp cls =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   636
    let val (lits,tfree_lits) = tptp_clause_aux cls (*"lits" includes the typing assumptions (TVars)*)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   637
	val cls_id = string_of_clauseID cls
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   638
	val ax_name = string_of_axiomName cls
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   639
	val knd = string_of_kind cls
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   640
	val lits_str = ResLib.list_to_string' lits
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   641
	val cls_str = gen_tptp_cls(cls_id,ax_name,knd,lits_str) 
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   642
    in
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   643
	(cls_str,tfree_lits) 
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   644
    end;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   645
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   646
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   647
fun tfree_clause tfree_lit =
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   648
    "input_clause(" ^ "tfree_tcs," ^ "conjecture" ^ ",[" ^ tfree_lit ^ "]).";
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   649
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   650
val delim = "\n";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   651
val tptp_clauses2str = ResLib.list2str_sep delim; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   652
     
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   653
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   654
fun string_of_arClauseID (ArityClause arcls) = arclause_prefix ^ string_of_int(#clause_id arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   655
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   656
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   657
fun string_of_arLit (TConsLit(b,(c,t,args))) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   658
    let val pol = if b then "++" else "--"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   659
	val  arg_strs = (case args of [] => "" | _ => ResLib.list_to_string args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   660
    in 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   661
	pol ^ c ^ "(" ^ t ^ arg_strs ^ ")"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   662
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   663
  | string_of_arLit (TVarLit(b,(c,str))) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   664
    let val pol = if b then "++" else "--"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   665
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   666
	pol ^ c ^ "(" ^ str ^ ")"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   667
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   668
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   669
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   670
fun string_of_conclLit (ArityClause arcls) = string_of_arLit (#conclLit arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   671
     
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   672
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   673
fun strings_of_premLits (ArityClause arcls) = map string_of_arLit (#premLits arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   674
		
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   675
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   676
fun string_of_arKind (ArityClause arcls) = name_of_kind(#kind arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   677
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   678
fun tptp_arity_clause arcls = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   679
    let val arcls_id = string_of_arClauseID arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   680
	val concl_lit = string_of_conclLit arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   681
	val prems_lits = strings_of_premLits arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   682
	val knd = string_of_arKind arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   683
	val all_lits = concl_lit :: prems_lits
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   684
    in
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15390
diff changeset
   685
	"input_clause(" ^ arcls_id ^ "," ^ knd ^ "," ^ (ResLib.list_to_string' all_lits) ^ ")."
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   686
	
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   687
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   688
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   689
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   690
val clrelclause_prefix = "relcls_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   691
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   692
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   693
fun tptp_classrelLits sub sup = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   694
    let val tvar = "(T)"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   695
    in 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   696
	case sup of NONE => "[++" ^ sub ^ tvar ^ "]"
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   697
		  | (SOME supcls) =>  "[--" ^ sub ^ tvar ^ ",++" ^ supcls ^ tvar ^ "]"
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   698
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   699
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   700
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   701
fun tptp_classrelClause (ClassrelClause cls) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   702
    let val relcls_id = clrelclause_prefix ^ string_of_int(#clause_id cls)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   703
	val sub = #subclass cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   704
	val sup = #superclass cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   705
	val lits = tptp_classrelLits sub sup
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   706
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   707
	"input_clause(" ^ relcls_id ^ ",axiom," ^ lits ^ ")."
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   708
    end; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   709
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   710
end;