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