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