src/HOL/Tools/res_clause.ML
author paulson
Tue, 15 Mar 2005 17:07:41 +0100
changeset 15610 f855fd163b62
parent 15608 f161fa6f8fd5
child 15615 d72b1867d09d
permissions -rw-r--r--
more concise ASCII escaping
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
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    33
    val tptp_clauses2str : string list -> string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    34
    val typed : unit -> unit
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    35
    val untyped : unit -> unit
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
    36
    val clause2tptp : clause -> string * string list
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
    37
    val tfree_clause : string -> string
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    38
  end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    39
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    40
structure ResClause : RES_CLAUSE =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    41
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    42
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    43
(* Added for typed equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    44
val special_equal = ref false; (* by default,equality does not carry type information *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    45
val eq_typ_wrapper = "typeinfo"; (* default string *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    46
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    47
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    48
val schematic_var_prefix = "V_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    49
val fixed_var_prefix = "v_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    50
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    51
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    52
val tvar_prefix = "Typ_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    53
val tfree_prefix = "typ_";
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 clause_prefix = "cls_"; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    57
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    58
val arclause_prefix = "arcls_" 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    59
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    60
val const_prefix = "const_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    61
val tconst_prefix = "tconst_"; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    62
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    63
val class_prefix = "clas_"; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    64
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    65
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    66
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    67
(**** some useful functions ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    68
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    69
val const_trans_table =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    70
      Symtab.make [("op =", "equal"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    71
	  	   ("op <=", "lessequals"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    72
		   ("op <", "less"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    73
		   ("op &", "and"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    74
		   ("op |", "or"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    75
		   ("op -->", "implies"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    76
		   ("op :", "in"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    77
		   ("op Un", "union"),
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    78
		   ("op Int", "inter")];
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    79
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    80
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    81
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    82
(*Escaping of special characters.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    83
  Alphanumeric characters are left unchanged.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    84
  The character _ goes to __
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    85
  Characters in the range ASCII space to / go to _A to _P, respectively.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    86
  Other printing characters go to _NNN where NNN is the decimal ASCII code.*)
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    87
local
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    88
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    89
val A_minus_space = Char.ord #"A" - Char.ord #" ";
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    90
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    91
fun ascii_of_c c =
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    92
  if Char.isAlphaNum c then String.str c
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    93
  else if c = #"_" then "__"
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    94
  else if #" " <= c andalso c <= #"/" 
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    95
       then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space))
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    96
  else if Char.isPrint c then ("_" ^ Int.toString (Char.ord c))
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    97
  else ""
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    98
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
    99
in
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   100
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   101
val ascii_of = String.translate ascii_of_c;
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   102
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   103
end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   104
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   105
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   106
(* another version of above functions that remove chars that may not be allowed by Vampire *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   107
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of v);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   108
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   109
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   110
fun make_schematic_type_var v = tvar_prefix ^ (ascii_of v);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   111
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of x);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   112
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   113
fun make_fixed_const c = const_prefix ^ (ascii_of c);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   114
fun make_fixed_type_const c = tconst_prefix ^ (ascii_of c);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   115
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   116
fun make_type_class clas = class_prefix ^ (ascii_of clas);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   117
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   118
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   119
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   120
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   121
fun lookup_const c =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   122
    case Symtab.lookup (const_trans_table,c) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   123
        SOME c' => c'
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   124
      | NONE =>  make_fixed_const 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
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   127
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   128
(***** 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
   129
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   130
val keep_types = ref true; (* default is true *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   131
fun untyped () = (keep_types := false);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   132
fun typed () = (keep_types := true);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   133
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   134
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   135
datatype kind = Axiom | Hypothesis | Conjecture;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   136
fun name_of_kind Axiom = "axiom"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   137
  | name_of_kind Hypothesis = "hypothesis"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   138
  | name_of_kind Conjecture = "conjecture";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   139
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   140
type clause_id = int;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   141
type axiom_name = string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   142
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   143
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   144
type polarity = bool;
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 indexname = Term.indexname;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   147
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   148
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   149
(* "tag" is used for vampire specific syntax  *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   150
type tag = bool; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   151
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   152
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   153
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   154
fun string_of_indexname (name,index) = name ^ "_" ^ (string_of_int index);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   155
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   156
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   157
val id_ref = ref 0;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   158
fun generate_id () = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   159
     let val id = !id_ref
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   160
     in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   161
	 (id_ref:=id + 1; id)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   162
     end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   163
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   164
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   165
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   166
(**** Isabelle FOL clauses ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   167
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   168
(* by default it is false *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   169
val tagged = ref false;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   170
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   171
type pred_name = string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   172
type sort = Term.sort;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   173
type fol_type = 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 type_literal = LTVar of string | LTFree of string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   177
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   178
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   179
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
   180
datatype predicate = Predicate of pred_name * fol_type * folTerm list;
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 literal = Literal of polarity * predicate * tag;
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 typ_var = FOLTVar of indexname | FOLTFree 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
(* ML datatype used to repsent one single clause: disjunction of literals. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   190
datatype clause = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   191
	 Clause of {clause_id: clause_id,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   192
		    axiom_name: axiom_name,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   193
		    kind: kind,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   194
		    literals: literal list,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   195
		    types_sorts: (typ_var * sort) list, 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   196
                    tvar_type_literals: type_literal list, 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   197
                    tfree_type_literals: type_literal list };
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
exception CLAUSE of string;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   201
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   202
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   203
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   204
(*** make clauses ***)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   205
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   206
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   207
fun make_clause (clause_id,axiom_name,kind,literals,types_sorts,tvar_type_literals,tfree_type_literals) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   208
     Clause {clause_id = clause_id, axiom_name = axiom_name, kind = kind, literals = literals, types_sorts = types_sorts,tvar_type_literals = tvar_type_literals,tfree_type_literals = tfree_type_literals};
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   209
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   210
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)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   214
    let val foltyps_ts = map type_of Ts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   215
        val (folTyps,ts) = ResLib.unzip foltyps_ts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   216
        val ts' = ResLib.flat_noDup ts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   217
    in    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   218
        (((make_fixed_type_const a) ^ (ResLib.list_to_string folTyps)),ts') 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   219
    end
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)])
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   221
  | type_of (TVar (v, s))  = (make_schematic_type_var (string_of_indexname v), [((FOLTVar v),s)]);
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   222
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   223
(* added: checkMeta: string -> bool *)
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   224
(* Any meta vars like ?x should be treated as universal vars,although it is represented as "Free(...)" by Isabelle *)
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   225
fun checkMeta s =
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   226
    let val chars = explode s
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   227
    in
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   228
	["M", "E", "T", "A", "H", "Y", "P", "1"] prefix chars
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   229
    end;
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   230
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   231
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   232
fun pred_name_type (Const(c,T)) = (lookup_const c,type_of T)
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   233
  | pred_name_type (Free(x,T))  = 
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   234
    let val is_meta = checkMeta x
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   235
    in
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   236
	if is_meta then (raise CLAUSE("Predicate Not First Order")) else
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   237
	(make_fixed_var x,type_of T)
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   238
    end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   239
  | pred_name_type (Var(_,_))   = raise CLAUSE("Predicate Not First Order")
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   240
  | pred_name_type _          = raise CLAUSE("Predicate input unexpected");
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   241
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   242
fun fun_name_type (Const(c,T)) = (lookup_const c,type_of T)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   243
  | fun_name_type (Free(x,T)) = (make_fixed_var x,type_of T)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   244
  | fun_name_type _ = raise CLAUSE("Function Not First Order");
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   245
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   246
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   247
fun term_of (Var(ind_nm,T)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   248
    let val (folType,ts) = type_of T
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   249
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   250
	(UVar(make_schematic_var(string_of_indexname ind_nm),folType),ts)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   251
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   252
  | term_of (Free(x,T)) = 
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   253
    let val is_meta = checkMeta x
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   254
	val (folType,ts) = type_of T
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   255
    in
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   256
	if is_meta then (UVar(make_schematic_var x,folType),ts)
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   257
	else
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   258
            (Fun(make_fixed_var x,folType,[]),ts)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   259
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   260
  | term_of (Const(c,T)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   261
    let val (folType,ts) = type_of T
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   262
     in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   263
        (Fun(lookup_const c,folType,[]),ts)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   264
    end    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   265
  | term_of (app as (t $ a)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   266
    let val (f,args) = strip_comb app
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   267
        fun term_of_aux () = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   268
            let val (funName,(funType,ts1)) = fun_name_type f
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   269
                 val (args',ts2) = ResLib.unzip (map term_of args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   270
                 val ts3 = ResLib.flat_noDup (ts1::ts2)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   271
            in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   272
		(Fun(funName,funType,args'),ts3)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   273
            end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   274
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   275
        case f of Const(_,_) => term_of_aux ()
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   276
                | Free(s,_)  => if (checkMeta s) then (raise CLAUSE("Function Not First Order")) else term_of_aux ()
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   277
                | _          => raise CLAUSE("Function Not First Order")
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   278
    end
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   279
  | term_of _ = raise CLAUSE("Function Not First Order"); 
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15347
diff changeset
   280
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   281
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   282
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   283
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   284
(* For type equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   285
(* here "arg_typ" is the type of "="'s argument's type, not the type of the equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   286
(* Find type of equality arg *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   287
local
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   288
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   289
fun eq_arg_type (Type("fun",[T,_])) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   290
    let val (folT,_) = type_of T;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   291
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   292
	folT
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   293
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   294
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   295
in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   296
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   297
fun pred_of_eq ((Const ("op =", typ)),args) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   298
    let val arg_typ = eq_arg_type typ 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   299
	val (args',ts) = ResLib.unzip (map term_of args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   300
	val equal_name = lookup_const "op ="
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   301
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   302
	(Predicate(equal_name,arg_typ,args'),ResLib.flat_noDup ts)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   303
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   304
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   305
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   306
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   307
(* changed for non-equality predicate *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   308
(* The input "pred" cannot be an equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   309
fun pred_of_nonEq (pred,args) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   310
    let val (predName,(predType,ts1)) = pred_name_type pred
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   311
	val (args',ts2) = ResLib.unzip (map term_of args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   312
	val ts3 = ResLib.flat_noDup (ts1::ts2)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   313
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   314
	(Predicate(predName,predType,args'),ts3)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   315
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   316
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   317
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   318
(* Changed for typed equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   319
(* 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
   320
fun predicate_of term =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   321
    let val (pred,args) = strip_comb term
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   322
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   323
	case pred of (Const ("op =", _)) => pred_of_eq (pred,args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   324
		   | _ => pred_of_nonEq (pred,args)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   325
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   326
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   327
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   328
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   329
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
   330
  | literals_of_term ((Const("op |",_) $ P $ Q),(lits,ts)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   331
    let val (lits',ts') = literals_of_term(P,(lits,ts))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   332
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   333
        literals_of_term(Q,(lits',ts'))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   334
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   335
  | literals_of_term ((Const("Not",_) $ P),(lits,ts)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   336
    let val (pred,ts') = predicate_of P
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   337
        val lits' = Literal(false,pred,false) :: lits
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   338
        val ts'' = ResLib.no_rep_app ts ts'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   339
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   340
        (lits',ts'')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   341
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   342
  | literals_of_term (P,(lits,ts)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   343
    let val (pred,ts') = predicate_of P
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   344
        val lits' = Literal(true,pred,false) :: lits
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   345
        val ts'' = ResLib.no_rep_app ts ts' 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   346
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   347
        (lits',ts'')
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
  | literals_of_term _ = raise CLAUSE("Unexpected clause format");
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   350
     
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   351
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   352
fun literals_of_thm thm = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   353
    let val term_of_thm = prop_of thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   354
			  
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   355
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   356
	literals_of_term (term_of_thm,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   357
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   358
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   359
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   360
fun sorts_on_typs (_, []) = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   361
  | sorts_on_typs ((FOLTVar(indx)), [s]) = [LTVar((make_type_class s) ^ "(" ^ (make_schematic_type_var(string_of_indexname indx)) ^ ")")]
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   362
  | sorts_on_typs ((FOLTVar(indx)), (s::ss))=  LTVar((make_type_class s) ^ "(" ^ (make_schematic_type_var(string_of_indexname indx)) ^ ")") :: (sorts_on_typs ((FOLTVar(indx)), ss))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   363
  | sorts_on_typs ((FOLTFree(x)), [s]) = [LTFree((make_type_class s) ^ "(" ^ (make_fixed_type_var(x)) ^ ")")]
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   364
  | sorts_on_typs ((FOLTFree(x)), (s::ss)) = LTFree((make_type_class s) ^ "(" ^ (make_fixed_type_var(x)) ^ ")") :: (sorts_on_typs ((FOLTFree(x)), ss));
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   365
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   366
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   367
fun add_typs_aux [] = ([],[])
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   368
  | add_typs_aux ((FOLTVar(indx),s)::tss) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   369
    let val vs = sorts_on_typs (FOLTVar(indx),s)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   370
        val (vss,fss) = add_typs_aux tss
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   371
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   372
        (ResLib.no_rep_app vs vss,fss)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   373
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   374
  | add_typs_aux ((FOLTFree(x),s)::tss) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   375
    let val fs = sorts_on_typs (FOLTFree(x),s)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   376
        val (vss,fss) = add_typs_aux tss
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   377
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   378
        (vss,ResLib.no_rep_app fs fss)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   379
    end;
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
fun add_typs (Clause cls) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   383
    let val ts = #types_sorts cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   384
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   385
	add_typs_aux ts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   386
    end;    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   387
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   388
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   389
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   390
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   391
(** make axiom clauses, hypothesis clauses and conjecture clauses. **)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   392
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   393
local 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   394
    fun replace_dot "." = "_"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   395
      | replace_dot c = c;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   396
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   397
in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   398
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   399
fun proper_ax_name ax_name = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   400
    let val chars = explode ax_name
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   401
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   402
	implode (map replace_dot chars)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   403
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   404
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   405
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   406
fun make_axiom_clause_thm thm (name,number)=
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   407
    let val (lits,types_sorts) = literals_of_thm thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   408
	val cls_id = number
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   409
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   410
	val ax_name = proper_ax_name name
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   411
    in 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   412
	make_clause(cls_id,ax_name,Axiom,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   413
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   414
   
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   415
fun make_hypothesis_clause_thm thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   416
    let val (lits,types_sorts) = literals_of_thm thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   417
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   418
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   419
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   420
	make_clause(cls_id,"",Hypothesis,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   421
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   422
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   423
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   424
fun make_conjecture_clause_thm thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   425
    let val (lits,types_sorts) = literals_of_thm thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   426
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   427
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   428
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   429
	make_clause(cls_id,"",Conjecture,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   430
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   431
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   432
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   433
fun make_axiom_clause term (name,number)=
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   434
    let val (lits,types_sorts) = literals_of_term (term,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   435
	val cls_id = number
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   436
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   437
	val ax_name = proper_ax_name name
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,ax_name,Axiom,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
fun make_hypothesis_clause term =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   444
    let val (lits,types_sorts) = literals_of_term (term,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   445
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   446
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   447
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   448
	make_clause(cls_id,"",Hypothesis,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   449
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   450
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   451
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   452
fun make_conjecture_clause term =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   453
    let val (lits,types_sorts) = literals_of_term (term,([],[]))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   454
	val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   455
	val (tvar_lits,tfree_lits) = add_typs_aux types_sorts
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   456
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   457
	make_clause(cls_id,"",Conjecture,lits,types_sorts,tvar_lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   458
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   459
 
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
(**** Isabelle arities ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   463
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   464
exception ARCLAUSE of string;
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
type class = string; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   468
type tcons = string; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   469
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   470
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   471
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
   472
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   473
datatype arityClause =  
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   474
	 ArityClause of {clause_id: clause_id,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   475
			 kind: kind,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   476
			 conclLit: arLit,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   477
			 premLits: arLit list};
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 get_TVars 0 = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   481
  | get_TVars n = ("T_" ^ (string_of_int n)) :: get_TVars (n-1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   482
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   483
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   484
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   485
fun pack_sort(_,[])  = raise ARCLAUSE("Empty Sort Found") 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   486
  | pack_sort(tvar, [cls]) = [(make_type_class cls, tvar)] 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   487
  | 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
   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
fun make_TVarLit (b,(cls,str)) = TVarLit(b,(cls,str));
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   491
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
   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
fun make_arity_clause (clause_id,kind,conclLit,premLits) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   495
    ArityClause {clause_id = clause_id, kind = kind, conclLit = conclLit, premLits = premLits};
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
fun make_axiom_arity_clause (tcons,(res,args)) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   499
     let val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   500
	 val nargs = length args
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   501
	 val tvars = get_TVars nargs
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   502
	 val conclLit = make_TConsLit(true,(res,tcons,tvars))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   503
         val tvars_srts = ResLib.zip tvars args
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   504
	 val tvars_srts' = ResLib.flat_noDup(map pack_sort tvars_srts)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   505
         val false_tvars_srts' = ResLib.pair_ins false tvars_srts'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   506
	 val premLits = map make_TVarLit false_tvars_srts'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   507
     in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   508
	 make_arity_clause (cls_id,Axiom,conclLit,premLits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   509
     end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   510
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   511
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   512
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   513
(**** Isabelle class relations ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   514
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   515
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   516
datatype classrelClause = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   517
	 ClassrelClause of {clause_id: clause_id,
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   518
			    subclass: class,
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   519
			    superclass: class option};
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
fun make_classrelClause (clause_id,subclass,superclass) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   522
    ClassrelClause {clause_id = clause_id,subclass = subclass, superclass = superclass};
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   523
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   524
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   525
fun make_axiom_classrelClause (subclass,superclass) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   526
    let val cls_id = generate_id()
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   527
	val sub = make_type_class subclass
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   528
	val sup = case superclass of NONE => NONE 
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   529
				   | SOME s => SOME (make_type_class s)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   530
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   531
	make_classrelClause(cls_id,sub,sup)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   532
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   533
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   534
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 classrelClauses_of_aux (sub,[]) = []
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   537
  | 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
   538
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   539
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   540
fun classrelClauses_of (sub,sups) = 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   541
    case sups of [] => [make_axiom_classrelClause (sub,NONE)]
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   542
	       | _ => classrelClauses_of_aux (sub, sups);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   543
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   544
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   545
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   546
(***** convert clauses to tptp format *****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   547
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   548
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   549
fun string_of_clauseID (Clause cls) = clause_prefix ^ (string_of_int (#clause_id cls));
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   550
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   551
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   552
fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   553
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   554
fun string_of_axiomName (Clause cls) = #axiom_name cls;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   555
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   556
fun string_of_term (UVar(x,_)) = x
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   557
  | string_of_term (Fun (name,typ,[])) = name
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   558
  | string_of_term (Fun (name,typ,terms)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   559
    let val terms' = map string_of_term terms
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   560
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   561
        if (!keep_types) then name ^ (ResLib.list_to_string (typ :: terms'))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   562
        else name ^ (ResLib.list_to_string terms')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   563
    end;
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
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   567
(****!!!! Changed for typed equality !!!!****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   568
fun wrap_eq_type typ t = eq_typ_wrapper ^"(" ^ t ^ "," ^ typ ^ ")";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   569
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   570
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   571
(****!!!! Changed for typed equality !!!!****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   572
(* 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
   573
fun string_of_equality (typ,terms) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   574
    let val [tstr1,tstr2] = map string_of_term terms
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   575
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   576
	if ((!keep_types) andalso (!special_equal)) then 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   577
	    "equal(" ^ (wrap_eq_type typ tstr1) ^ "," ^ (wrap_eq_type typ tstr2) ^ ")"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   578
	else
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   579
	    "equal(" ^ tstr1 ^ "," ^ tstr2 ^ ")"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   580
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   581
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
(* Changed for typed equality *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   585
(* before output the string of the predicate, check if the predicate corresponds to an equality or not. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   586
fun string_of_predicate (Predicate("equal",typ,terms)) = string_of_equality(typ,terms)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   587
  | string_of_predicate (Predicate(name,_,[])) = name 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   588
  | string_of_predicate (Predicate(name,typ,terms)) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   589
    let val terms_as_strings = map string_of_term terms
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   590
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   591
        if (!keep_types) then name ^ (ResLib.list_to_string  (typ :: terms_as_strings))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   592
        else name ^ (ResLib.list_to_string terms_as_strings) 
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
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
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   598
fun tptp_literal (Literal(pol,pred,tag)) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   599
    let val pred_string = string_of_predicate pred
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   600
	val tagged_pol = if (tag andalso !tagged) then (if pol then "+++" else "---")
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   601
                         else (if pol then "++" else "--")
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   602
     in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   603
	tagged_pol ^ pred_string
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   604
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   605
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_of_typeLit (LTVar x) = "--" ^ x
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   609
  | tptp_of_typeLit (LTFree x) = "++" ^ x;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   610
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   611
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   612
fun gen_tptp_cls (cls_id,ax_name,knd,lits) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   613
    let val ax_str = (if ax_name = "" then "" else ("_" ^ ax_name))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   614
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   615
	"input_clause(" ^ cls_id ^ ax_str ^ "," ^ knd ^ "," ^ lits ^ ")."
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   616
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   617
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   618
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   619
fun gen_tptp_type_cls (cls_id,knd,tfree_lit,idx) = "input_clause(" ^ cls_id ^ "_tcs" ^ (string_of_int idx) ^ "," ^ knd ^ ",[" ^ tfree_lit ^ "]).";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   620
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   621
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   622
fun tptp_clause_aux (Clause cls) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   623
    let val lits = map tptp_literal (#literals cls)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   624
	val tvar_lits_strs = if (!keep_types) then (map tptp_of_typeLit (#tvar_type_literals cls)) else []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   625
	val tfree_lits = if (!keep_types) then (map tptp_of_typeLit (#tfree_type_literals cls)) else []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   626
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   627
	(tvar_lits_strs @ lits,tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   628
    end; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   629
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   630
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   631
fun tptp_clause cls =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   632
    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
   633
	val cls_id = string_of_clauseID cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   634
	val ax_name = string_of_axiomName cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   635
	val knd = string_of_kind cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   636
	val lits_str = ResLib.list_to_string' lits
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   637
	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
   638
          | typ_clss k (tfree :: tfrees) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   639
            (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
   640
    in 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   641
	cls_str :: (typ_clss 0 tfree_lits)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   642
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   643
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   644
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   645
fun clause2tptp cls =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   646
    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
   647
	val cls_id = string_of_clauseID cls
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   648
	val ax_name = string_of_axiomName cls
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   649
	val knd = string_of_kind cls
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   650
	val lits_str = ResLib.list_to_string' lits
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   651
	val cls_str = gen_tptp_cls(cls_id,ax_name,knd,lits_str) 
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   652
    in
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   653
	(cls_str,tfree_lits) 
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   654
    end;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   655
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   656
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   657
fun tfree_clause tfree_lit = "input_clause(" ^ "tfree_tcs," ^ "conjecture" ^ ",[" ^ tfree_lit ^ "]).";
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15531
diff changeset
   658
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   659
val delim = "\n";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   660
val tptp_clauses2str = ResLib.list2str_sep delim; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   661
     
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   662
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   663
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
   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_arLit (TConsLit(b,(c,t,args))) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   667
    let val pol = if b then "++" else "--"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   668
	val  arg_strs = (case args of [] => "" | _ => ResLib.list_to_string args)
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 ^ "(" ^ t ^ arg_strs ^ ")"
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
  | string_of_arLit (TVarLit(b,(c,str))) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   673
    let val pol = if b then "++" else "--"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   674
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   675
	pol ^ c ^ "(" ^ str ^ ")"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   676
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   677
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   678
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   679
fun string_of_conclLit (ArityClause arcls) = string_of_arLit (#conclLit arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   680
     
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 strings_of_premLits (ArityClause arcls) = map string_of_arLit (#premLits arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   683
		
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   684
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   685
fun string_of_arKind (ArityClause arcls) = name_of_kind(#kind arcls);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   686
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   687
fun tptp_arity_clause arcls = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   688
    let val arcls_id = string_of_arClauseID arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   689
	val concl_lit = string_of_conclLit arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   690
	val prems_lits = strings_of_premLits arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   691
	val knd = string_of_arKind arcls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   692
	val all_lits = concl_lit :: prems_lits
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   693
    in
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15390
diff changeset
   694
	"input_clause(" ^ arcls_id ^ "," ^ knd ^ "," ^ (ResLib.list_to_string' all_lits) ^ ")."
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   695
	
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   696
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   697
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   698
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   699
val clrelclause_prefix = "relcls_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   700
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   701
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   702
fun tptp_classrelLits sub sup = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   703
    let val tvar = "(T)"
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   704
    in 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   705
	case sup of NONE => "[++" ^ sub ^ tvar ^ "]"
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15452
diff changeset
   706
		  | (SOME supcls) =>  "[--" ^ sub ^ tvar ^ ",++" ^ supcls ^ tvar ^ "]"
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   707
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   708
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   709
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   710
fun tptp_classrelClause (ClassrelClause cls) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   711
    let val relcls_id = clrelclause_prefix ^ string_of_int(#clause_id cls)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   712
	val sub = #subclass cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   713
	val sup = #superclass cls
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   714
	val lits = tptp_classrelLits sub sup
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   715
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   716
	"input_clause(" ^ relcls_id ^ ",axiom," ^ lits ^ ")."
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   717
    end; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   718
    
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   719
end;