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