src/HOL/Tools/res_reconstruct.ML
author wenzelm
Thu Mar 27 14:41:09 2008 +0100 (2008-03-27)
changeset 26424 a6cad32a27b0
parent 26333 68e5eee47a45
child 26928 ca87aff1ad2d
permissions -rwxr-xr-x
eliminated theory ProtoPure;
paulson@21978
     1
(*  ID:         $Id$
paulson@21979
     2
    Author:     L C Paulson and Claire Quigley
paulson@21978
     3
    Copyright   2004  University of Cambridge
paulson@21978
     4
*)
paulson@21978
     5
paulson@21978
     6
(***************************************************************************)
paulson@21979
     7
(*  Code to deal with the transfer of proofs from a prover process         *)
paulson@21978
     8
(***************************************************************************)
paulson@21978
     9
signature RES_RECONSTRUCT =
paulson@24425
    10
sig
paulson@24425
    11
  datatype atp = E | SPASS | Vampire
paulson@25492
    12
  val chained_hint: string
paulson@24425
    13
  val checkEProofFound:
paulson@24425
    14
	TextIO.instream * TextIO.outstream * Posix.Process.pid *
paulson@24425
    15
	string * Proof.context * thm * int * string Vector.vector -> bool
paulson@24425
    16
  val checkVampProofFound:
paulson@24425
    17
	TextIO.instream * TextIO.outstream * Posix.Process.pid *
paulson@24425
    18
	string * Proof.context * thm * int * string Vector.vector -> bool
paulson@24425
    19
  val checkSpassProofFound:
paulson@24425
    20
	TextIO.instream * TextIO.outstream * Posix.Process.pid *
paulson@24425
    21
	string * Proof.context * thm * int * string Vector.vector -> bool
paulson@24425
    22
  val signal_parent: TextIO.outstream * Posix.Process.pid * string * string -> unit
paulson@24425
    23
  val txt_path: string -> Path.T
paulson@24425
    24
  val fix_sorts: sort Vartab.table -> term -> term
paulson@24425
    25
  val invert_const: string -> string
paulson@24425
    26
  val invert_type_const: string -> string
paulson@24425
    27
  val num_typargs: Context.theory -> string -> int
paulson@24425
    28
  val make_tvar: string -> typ
paulson@24425
    29
  val strip_prefix: string -> string -> string option
paulson@25710
    30
  val setup: Context.theory -> Context.theory
paulson@24425
    31
end;
paulson@21978
    32
paulson@24425
    33
structure ResReconstruct : RES_RECONSTRUCT =
paulson@21978
    34
struct
paulson@21978
    35
paulson@21978
    36
val trace_path = Path.basic "atp_trace";
paulson@21978
    37
wenzelm@23139
    38
fun trace s = if !Output.debugging then File.append (File.tmp_path trace_path) s
paulson@21978
    39
              else ();
paulson@21978
    40
paulson@26333
    41
val string_of_thm = PrintMode.setmp [] string_of_thm;
paulson@26333
    42
paulson@25710
    43
(*For generating structured proofs: keep every nth proof line*)
paulson@26333
    44
val (modulus, modulus_setup) = Attrib.config_int "sledgehammer_modulus" 1;
paulson@21978
    45
paulson@25710
    46
(*Indicates whether to include sort information in generated proofs*)
paulson@26333
    47
val (recon_sorts, recon_sorts_setup) = Attrib.config_bool "sledgehammer_sorts" true;
paulson@22491
    48
paulson@26333
    49
(*Indicates whether to generate full proofs or just lemma lists*)
paulson@26333
    50
val (full_proofs, full_proofs_setup) = Attrib.config_bool "sledgehammer_full" false;
paulson@26333
    51
paulson@26333
    52
val setup = modulus_setup #> recon_sorts_setup #> full_proofs_setup;
paulson@25710
    53
paulson@25710
    54
datatype atp = E | SPASS | Vampire;
paulson@22044
    55
paulson@21978
    56
(**** PARSING OF TSTP FORMAT ****)
paulson@21978
    57
paulson@21978
    58
(*Syntax trees, either termlist or formulae*)
paulson@21978
    59
datatype stree = Int of int | Br of string * stree list;
paulson@21978
    60
paulson@21978
    61
fun atom x = Br(x,[]);
paulson@21978
    62
paulson@21978
    63
fun scons (x,y) = Br("cons", [x,y]);
paulson@21978
    64
val listof = foldl scons (atom "nil");
paulson@21978
    65
paulson@21978
    66
(*Strings enclosed in single quotes, e.g. filenames*)
paulson@21978
    67
val quoted = $$"'" |-- Scan.repeat (~$$"'") --| $$"'" >> implode;
paulson@21978
    68
paulson@21978
    69
(*Intended for $true and $false*)
paulson@21978
    70
fun tf s = "c_" ^ str (Char.toUpper (String.sub(s,0))) ^ String.extract(s,1,NONE);
paulson@21978
    71
val truefalse = $$"$" |-- Symbol.scan_id >> (atom o tf);
paulson@21978
    72
paulson@21978
    73
(*Integer constants, typically proof line numbers*)
paulson@21978
    74
fun is_digit s = Char.isDigit (String.sub(s,0));
paulson@21978
    75
val integer = Scan.many1 is_digit >> (valOf o Int.fromString o implode);
paulson@21978
    76
paulson@21978
    77
(*Generalized FO terms, which include filenames, numbers, etc.*)
wenzelm@25999
    78
fun termlist x = (term ::: Scan.repeat ($$"," |-- term)) x
paulson@21978
    79
and term x = (quoted >> atom || integer>>Int || truefalse ||
paulson@21978
    80
              Symbol.scan_id -- Scan.optional ($$"(" |-- termlist --| $$")") [] >> Br ||
paulson@21978
    81
              $$"(" |-- term --| $$")" ||
paulson@24547
    82
              $$"[" |-- Scan.optional termlist [] --| $$"]" >> listof) x;
paulson@21978
    83
paulson@21978
    84
fun negate t = Br("c_Not", [t]);
paulson@21978
    85
fun equate (t1,t2) = Br("c_equal", [t1,t2]);
paulson@21978
    86
paulson@21978
    87
(*Apply equal or not-equal to a term*)
paulson@21978
    88
fun syn_equal (t, NONE) = t
paulson@21978
    89
  | syn_equal (t1, SOME (NONE, t2)) = equate (t1,t2)
paulson@21978
    90
  | syn_equal (t1, SOME (SOME _, t2)) = negate (equate (t1,t2));
paulson@21978
    91
paulson@21978
    92
(*Literals can involve negation, = and !=.*)
paulson@24547
    93
fun literal x = ($$"~" |-- literal >> negate ||
paulson@24547
    94
                 (term -- Scan.option (Scan.option ($$"!") --| $$"=" -- term) >> syn_equal)) x;
paulson@21978
    95
wenzelm@25999
    96
val literals = literal ::: Scan.repeat ($$"|" |-- literal);
paulson@21978
    97
paulson@21978
    98
(*Clause: a list of literals separated by the disjunction sign*)
paulson@24547
    99
val clause = $$"(" |-- literals --| $$")" || Scan.single literal;
paulson@21978
   100
paulson@21978
   101
val annotations = $$"," |-- term -- Scan.option ($$"," |-- termlist);
paulson@21978
   102
wenzelm@25718
   103
(*<cnf_annotated> ::= cnf(<name>,<formula_role>,<cnf_formula><annotations>).
paulson@21978
   104
  The <name> could be an identifier, but we assume integers.*)
wenzelm@23139
   105
val tstp_line = (Scan.this_string "cnf" -- $$"(") |--
wenzelm@23139
   106
                integer --| $$"," -- Symbol.scan_id --| $$"," --
paulson@21978
   107
                clause -- Scan.option annotations --| $$ ")";
paulson@21978
   108
paulson@21978
   109
paulson@21978
   110
(**** INTERPRETATION OF TSTP SYNTAX TREES ****)
paulson@21978
   111
paulson@21978
   112
exception STREE of stree;
paulson@21978
   113
paulson@21978
   114
(*If string s has the prefix s1, return the result of deleting it.*)
wenzelm@23139
   115
fun strip_prefix s1 s =
paulson@24182
   116
  if String.isPrefix s1 s 
paulson@24182
   117
  then SOME (ResClause.undo_ascii_of (String.extract (s, size s1, NONE)))
paulson@21978
   118
  else NONE;
paulson@21978
   119
paulson@21978
   120
(*Invert the table of translations between Isabelle and ATPs*)
paulson@21978
   121
val type_const_trans_table_inv =
paulson@21978
   122
      Symtab.make (map swap (Symtab.dest ResClause.type_const_trans_table));
paulson@21978
   123
paulson@21978
   124
fun invert_type_const c =
paulson@21978
   125
    case Symtab.lookup type_const_trans_table_inv c of
paulson@21978
   126
        SOME c' => c'
paulson@21978
   127
      | NONE => c;
paulson@21978
   128
paulson@21978
   129
fun make_tvar b = TVar(("'" ^ b, 0), HOLogic.typeS);
paulson@21978
   130
fun make_var (b,T) = Var((b,0),T);
paulson@21978
   131
paulson@21978
   132
(*Type variables are given the basic sort, HOL.type. Some will later be constrained
paulson@21978
   133
  by information from type literals, or by type inference.*)
paulson@21978
   134
fun type_of_stree t =
paulson@21978
   135
  case t of
paulson@21978
   136
      Int _ => raise STREE t
wenzelm@23139
   137
    | Br (a,ts) =>
paulson@21978
   138
        let val Ts = map type_of_stree ts
wenzelm@23139
   139
        in
paulson@21978
   140
          case strip_prefix ResClause.tconst_prefix a of
paulson@21978
   141
              SOME b => Type(invert_type_const b, Ts)
wenzelm@23139
   142
            | NONE =>
paulson@21978
   143
                if not (null ts) then raise STREE t  (*only tconsts have type arguments*)
wenzelm@23139
   144
                else
paulson@21978
   145
                case strip_prefix ResClause.tfree_prefix a of
paulson@21978
   146
                    SOME b => TFree("'" ^ b, HOLogic.typeS)
wenzelm@23139
   147
                  | NONE =>
paulson@21978
   148
                case strip_prefix ResClause.tvar_prefix a of
paulson@21978
   149
                    SOME b => make_tvar b
paulson@21978
   150
                  | NONE => make_tvar a   (*Variable from the ATP, say X1*)
paulson@21978
   151
        end;
paulson@21978
   152
paulson@21978
   153
(*Invert the table of translations between Isabelle and ATPs*)
paulson@21978
   154
val const_trans_table_inv =
wenzelm@23139
   155
      Symtab.update ("fequal", "op =")
paulson@22731
   156
        (Symtab.make (map swap (Symtab.dest ResClause.const_trans_table)));
paulson@21978
   157
paulson@21978
   158
fun invert_const c =
paulson@21978
   159
    case Symtab.lookup const_trans_table_inv c of
paulson@21978
   160
        SOME c' => c'
paulson@21978
   161
      | NONE => c;
paulson@21978
   162
paulson@21978
   163
(*The number of type arguments of a constant, zero if it's monomorphic*)
paulson@21978
   164
fun num_typargs thy s = length (Sign.const_typargs thy (s, Sign.the_const_type thy s));
paulson@21978
   165
paulson@21978
   166
(*Generates a constant, given its type arguments*)
paulson@21978
   167
fun const_of thy (a,Ts) = Const(a, Sign.const_instance thy (a,Ts));
paulson@21978
   168
paulson@21978
   169
(*First-order translation. No types are known for variables. HOLogic.typeT should allow
paulson@21978
   170
  them to be inferred.*)
paulson@22428
   171
fun term_of_stree args thy t =
paulson@21978
   172
  case t of
paulson@21978
   173
      Int _ => raise STREE t
paulson@22428
   174
    | Br ("hBOOL",[t]) => term_of_stree [] thy t  (*ignore hBOOL*)
paulson@22428
   175
    | Br ("hAPP",[t,u]) => term_of_stree (u::args) thy t
wenzelm@23139
   176
    | Br (a,ts) =>
paulson@21978
   177
        case strip_prefix ResClause.const_prefix a of
wenzelm@23139
   178
            SOME "equal" =>
paulson@22731
   179
              list_comb(Const ("op =", HOLogic.typeT), List.map (term_of_stree [] thy) ts)
wenzelm@23139
   180
          | SOME b =>
paulson@21978
   181
              let val c = invert_const b
paulson@21978
   182
                  val nterms = length ts - num_typargs thy c
paulson@22428
   183
                  val us = List.map (term_of_stree [] thy) (List.take(ts,nterms) @ args)
paulson@22428
   184
                  (*Extra args from hAPP come AFTER any arguments given directly to the
paulson@22428
   185
                    constant.*)
paulson@21978
   186
                  val Ts = List.map type_of_stree (List.drop(ts,nterms))
paulson@21978
   187
              in  list_comb(const_of thy (c, Ts), us)  end
paulson@21978
   188
          | NONE => (*a variable, not a constant*)
paulson@21978
   189
              let val T = HOLogic.typeT
paulson@21978
   190
                  val opr = (*a Free variable is typically a Skolem function*)
paulson@21978
   191
                    case strip_prefix ResClause.fixed_var_prefix a of
paulson@21978
   192
                        SOME b => Free(b,T)
wenzelm@23139
   193
                      | NONE =>
paulson@21978
   194
                    case strip_prefix ResClause.schematic_var_prefix a of
paulson@21978
   195
                        SOME b => make_var (b,T)
paulson@21978
   196
                      | NONE => make_var (a,T)    (*Variable from the ATP, say X1*)
paulson@23519
   197
              in  list_comb (opr, List.map (term_of_stree [] thy) (ts@args))  end;
paulson@21978
   198
wenzelm@23139
   199
(*Type class literal applied to a type. Returns triple of polarity, class, type.*)
paulson@21978
   200
fun constraint_of_stree pol (Br("c_Not",[t])) = constraint_of_stree (not pol) t
paulson@21978
   201
  | constraint_of_stree pol t = case t of
paulson@21978
   202
        Int _ => raise STREE t
wenzelm@23139
   203
      | Br (a,ts) =>
paulson@21978
   204
            (case (strip_prefix ResClause.class_prefix a, map type_of_stree ts) of
paulson@21978
   205
                 (SOME b, [T]) => (pol, b, T)
paulson@21978
   206
               | _ => raise STREE t);
paulson@21978
   207
paulson@21978
   208
(** Accumulate type constraints in a clause: negative type literals **)
paulson@21978
   209
paulson@21978
   210
fun addix (key,z)  = Vartab.map_default (key,[]) (cons z);
paulson@21978
   211
paulson@21978
   212
fun add_constraint ((false, cl, TFree(a,_)), vt) = addix ((a,~1),cl) vt
paulson@21978
   213
  | add_constraint ((false, cl, TVar(ix,_)), vt) = addix (ix,cl) vt
paulson@21978
   214
  | add_constraint (_, vt) = vt;
paulson@21978
   215
paulson@21978
   216
(*False literals (which E includes in its proofs) are deleted*)
paulson@21978
   217
val nofalses = filter (not o equal HOLogic.false_const);
paulson@21978
   218
paulson@22491
   219
(*Final treatment of the list of "real" literals from a clause.*)
paulson@22491
   220
fun finish [] = HOLogic.true_const  (*No "real" literals means only type information*)
wenzelm@23139
   221
  | finish lits =
paulson@22491
   222
      case nofalses lits of
paulson@22491
   223
          [] => HOLogic.false_const  (*The empty clause, since we started with real literals*)
paulson@22491
   224
        | xs => foldr1 HOLogic.mk_disj (rev xs);
paulson@22491
   225
paulson@21978
   226
(*Accumulate sort constraints in vt, with "real" literals in lits.*)
paulson@22491
   227
fun lits_of_strees ctxt (vt, lits) [] = (vt, finish lits)
wenzelm@23139
   228
  | lits_of_strees ctxt (vt, lits) (t::ts) =
paulson@22012
   229
      lits_of_strees ctxt (add_constraint (constraint_of_stree true t, vt), lits) ts
wenzelm@23139
   230
      handle STREE _ =>
paulson@22428
   231
      lits_of_strees ctxt (vt, term_of_stree [] (ProofContext.theory_of ctxt) t :: lits) ts;
paulson@21978
   232
paulson@21978
   233
(*Update TVars/TFrees with detected sort constraints.*)
paulson@21978
   234
fun fix_sorts vt =
paulson@21978
   235
  let fun tysubst (Type (a, Ts)) = Type (a, map tysubst Ts)
paulson@21978
   236
        | tysubst (TVar (xi, s)) = TVar (xi, getOpt (Vartab.lookup vt xi, s))
paulson@21978
   237
        | tysubst (TFree (x, s)) = TFree (x, getOpt (Vartab.lookup vt (x,~1), s))
paulson@21978
   238
      fun tmsubst (Const (a, T)) = Const (a, tysubst T)
paulson@21978
   239
        | tmsubst (Free (a, T)) = Free (a, tysubst T)
paulson@21978
   240
        | tmsubst (Var (xi, T)) = Var (xi, tysubst T)
paulson@21978
   241
        | tmsubst (t as Bound _) = t
paulson@21978
   242
        | tmsubst (Abs (a, T, t)) = Abs (a, tysubst T, tmsubst t)
paulson@21978
   243
        | tmsubst (t $ u) = tmsubst t $ tmsubst u;
paulson@21978
   244
  in fn t => if Vartab.is_empty vt then t else tmsubst t end;
paulson@21978
   245
paulson@21978
   246
(*Interpret a list of syntax trees as a clause, given by "real" literals and sort constraints.
paulson@21978
   247
  vt0 holds the initial sort constraints, from the conjecture clauses.*)
paulson@23519
   248
fun clause_of_strees ctxt vt0 ts =
wenzelm@22728
   249
  let val (vt, dt) = lits_of_strees ctxt (vt0,[]) ts in
wenzelm@24680
   250
    singleton (Syntax.check_terms ctxt) (TypeInfer.constrain HOLogic.boolT (fix_sorts vt dt))
wenzelm@22728
   251
  end;
paulson@21978
   252
paulson@23519
   253
(*Quantification over a list of Vars. FIXME: for term.ML??*)
paulson@21978
   254
fun list_all_var ([], t: term) = t
paulson@21978
   255
  | list_all_var ((v as Var(ix,T)) :: vars, t) =
paulson@21979
   256
      (all T) $ Abs(string_of_indexname ix, T, abstract_over (v, list_all_var (vars,t)));
paulson@21978
   257
paulson@21978
   258
fun gen_all_vars t = list_all_var (term_vars t, t);
paulson@21978
   259
paulson@21978
   260
fun ints_of_stree_aux (Int n, ns) = n::ns
paulson@21978
   261
  | ints_of_stree_aux (Br(_,ts), ns) = foldl ints_of_stree_aux ns ts;
paulson@21978
   262
paulson@21978
   263
fun ints_of_stree t = ints_of_stree_aux (t, []);
paulson@21978
   264
paulson@25086
   265
fun decode_tstp vt0 (name, role, ts, annots) ctxt =
paulson@21978
   266
  let val deps = case annots of NONE => [] | SOME (source,_) => ints_of_stree source
paulson@25086
   267
      val cl = clause_of_strees ctxt vt0 ts
paulson@25086
   268
  in  ((name, role, cl, deps), fold Variable.declare_term (term_frees cl) ctxt)  end;
paulson@21978
   269
paulson@21978
   270
fun dest_tstp ((((name, role), ts), annots), chs) =
paulson@21978
   271
  case chs of
paulson@21978
   272
          "."::_ => (name, role, ts, annots)
paulson@21978
   273
        | _ => error ("TSTP line not terminated by \".\": " ^ implode chs);
paulson@21978
   274
paulson@21978
   275
paulson@21978
   276
(** Global sort constraints on TFrees (from tfree_tcs) are positive unit clauses. **)
paulson@21978
   277
paulson@21978
   278
fun add_tfree_constraint ((true, cl, TFree(a,_)), vt) = addix ((a,~1),cl) vt
paulson@21978
   279
  | add_tfree_constraint (_, vt) = vt;
paulson@21978
   280
paulson@21978
   281
fun tfree_constraints_of_clauses vt [] = vt
wenzelm@23139
   282
  | tfree_constraints_of_clauses vt ([lit]::tss) =
paulson@21978
   283
      (tfree_constraints_of_clauses (add_tfree_constraint (constraint_of_stree true lit, vt)) tss
paulson@21978
   284
       handle STREE _ => (*not a positive type constraint: ignore*)
paulson@21978
   285
       tfree_constraints_of_clauses vt tss)
paulson@21978
   286
  | tfree_constraints_of_clauses vt (_::tss) = tfree_constraints_of_clauses vt tss;
paulson@21978
   287
paulson@21978
   288
paulson@21978
   289
(**** Translation of TSTP files to Isar Proofs ****)
paulson@21978
   290
paulson@22012
   291
fun decode_tstp_list ctxt tuples =
paulson@21978
   292
  let val vt0 = tfree_constraints_of_clauses Vartab.empty (map #3 tuples)
paulson@25086
   293
  in  #1 (fold_map (decode_tstp vt0) tuples ctxt) end;
paulson@21978
   294
paulson@23519
   295
(** Finding a matching assumption. The literals may be permuted, and variable names
paulson@23519
   296
    may disagree. We have to try all combinations of literals (quadratic!) and 
paulson@23519
   297
    match up the variable names consistently. **)
paulson@23519
   298
paulson@23519
   299
fun strip_alls_aux n (Const("all",_)$Abs(a,T,t))  =  
paulson@23519
   300
      strip_alls_aux (n+1) (subst_bound (Var ((a,n), T), t))
paulson@23519
   301
  | strip_alls_aux _ t  =  t;
paulson@23519
   302
paulson@23519
   303
val strip_alls = strip_alls_aux 0;
paulson@23519
   304
paulson@23519
   305
exception MATCH_LITERAL;
paulson@22012
   306
paulson@23519
   307
(*Ignore types: they are not to be trusted...*)
paulson@23519
   308
fun match_literal (t1$u1) (t2$u2) env =
paulson@23519
   309
      match_literal t1 t2 (match_literal u1 u2 env)
paulson@23519
   310
  | match_literal (Abs (_,_,t1)) (Abs (_,_,t2)) env = 
paulson@23519
   311
      match_literal t1 t2 env
paulson@23519
   312
  | match_literal (Bound i1) (Bound i2) env = 
paulson@23519
   313
      if i1=i2 then env else raise MATCH_LITERAL
paulson@23519
   314
  | match_literal (Const(a1,_)) (Const(a2,_)) env = 
paulson@23519
   315
      if a1=a2 then env else raise MATCH_LITERAL
paulson@23519
   316
  | match_literal (Free(a1,_)) (Free(a2,_)) env = 
paulson@23519
   317
      if a1=a2 then env else raise MATCH_LITERAL
paulson@23519
   318
  | match_literal (Var(ix1,_)) (Var(ix2,_)) env = insert (op =) (ix1,ix2) env
paulson@23519
   319
  | match_literal _ _ env = raise MATCH_LITERAL;
paulson@23519
   320
paulson@23519
   321
(*Checking that all variable associations are unique. The list env contains no
paulson@23519
   322
  repetitions, but does it contain say (x,y) and (y,y)? *)
paulson@23519
   323
fun good env = 
paulson@23519
   324
  let val (xs,ys) = ListPair.unzip env
paulson@23519
   325
  in  not (has_duplicates (op=) xs orelse has_duplicates (op=) ys)  end;
paulson@23519
   326
paulson@23519
   327
(*Match one list of literals against another, ignoring types and the order of
paulson@23519
   328
  literals. Sorting is unreliable because we don't have types or variable names.*)
paulson@23519
   329
fun matches_aux _ [] [] = true
paulson@23519
   330
  | matches_aux env (lit::lits) ts =
paulson@23519
   331
      let fun match1 us [] = false
paulson@23519
   332
            | match1 us (t::ts) =
paulson@23519
   333
                let val env' = match_literal lit t env
paulson@23519
   334
                in  (good env' andalso matches_aux env' lits (us@ts)) orelse 
paulson@23519
   335
                    match1 (t::us) ts  
paulson@23519
   336
                end
paulson@23519
   337
                handle MATCH_LITERAL => match1 (t::us) ts
paulson@23519
   338
      in  match1 [] ts  end; 
paulson@23519
   339
paulson@23519
   340
(*Is this length test useful?*)
paulson@23519
   341
fun matches (lits1,lits2) = 
paulson@23519
   342
  length lits1 = length lits2  andalso  
paulson@23519
   343
  matches_aux [] (map Envir.eta_contract lits1) (map Envir.eta_contract lits2);
paulson@21999
   344
paulson@21999
   345
fun permuted_clause t =
paulson@24958
   346
  let val lits = HOLogic.disjuncts t
paulson@21999
   347
      fun perm [] = NONE
wenzelm@23139
   348
        | perm (ctm::ctms) =
paulson@24958
   349
            if matches (lits, HOLogic.disjuncts (HOLogic.dest_Trueprop (strip_alls ctm)))
paulson@23519
   350
            then SOME ctm else perm ctms
paulson@21999
   351
  in perm end;
paulson@21999
   352
paulson@22470
   353
fun have_or_show "show " lname = "show \""
paulson@22470
   354
  | have_or_show have lname = have ^ lname ^ ": \""
paulson@22470
   355
paulson@21999
   356
(*ctms is a list of conjecture clauses as yielded by Isabelle. Those returned by the
paulson@21999
   357
  ATP may have their literals reordered.*)
paulson@21999
   358
fun isar_lines ctxt ctms =
wenzelm@24920
   359
  let val string_of = Syntax.string_of_term ctxt
paulson@26333
   360
      val _ = trace ("\n\nisar_lines: start\n")
paulson@22470
   361
      fun doline have (lname, t, []) =  (*No deps: it's a conjecture clause, with no proof.*)
paulson@21999
   362
           (case permuted_clause t ctms of
paulson@21999
   363
                SOME u => "assume " ^ lname ^ ": \"" ^ string_of u ^ "\"\n"
paulson@21999
   364
              | NONE => "assume? " ^ lname ^ ": \"" ^ string_of t ^ "\"\n")  (*no match!!*)
paulson@22470
   365
        | doline have (lname, t, deps) =
paulson@23519
   366
            have_or_show have lname ^ string_of (gen_all_vars (HOLogic.mk_Trueprop t)) ^
paulson@22372
   367
            "\"\n  by (metis " ^ space_implode " " deps ^ ")\n"
paulson@21978
   368
      fun dolines [(lname, t, deps)] = [doline "show " (lname, t, deps)]
paulson@21978
   369
        | dolines ((lname, t, deps)::lines) = doline "have " (lname, t, deps) :: dolines lines
paulson@25710
   370
  in setmp show_sorts (Config.get ctxt recon_sorts) dolines end;
paulson@21978
   371
paulson@21978
   372
fun notequal t (_,t',_) = not (t aconv t');
paulson@21978
   373
paulson@22491
   374
(*No "real" literals means only type information*)
paulson@23519
   375
fun eq_types t = t aconv HOLogic.true_const;
paulson@21978
   376
paulson@22731
   377
fun replace_dep (old:int, new) dep = if dep=old then new else [dep];
paulson@21978
   378
wenzelm@23139
   379
fun replace_deps (old:int, new) (lno, t, deps) =
paulson@22731
   380
      (lno, t, foldl (op union_int) [] (map (replace_dep (old, new)) deps));
paulson@21978
   381
paulson@22491
   382
(*Discard axioms; consolidate adjacent lines that prove the same clause, since they differ
paulson@22491
   383
  only in type information.*)
paulson@21978
   384
fun add_prfline ((lno, "axiom", t, []), lines) =  (*axioms are not proof lines*)
paulson@22491
   385
      if eq_types t (*must be clsrel/clsarity: type information, so delete refs to it*)
wenzelm@23139
   386
      then map (replace_deps (lno, [])) lines
paulson@22470
   387
      else
paulson@22470
   388
       (case take_prefix (notequal t) lines of
paulson@22470
   389
           (_,[]) => lines                  (*no repetition of proof line*)
paulson@22470
   390
         | (pre, (lno',t',deps')::post) =>  (*repetition: replace later line by earlier one*)
paulson@22470
   391
             pre @ map (replace_deps (lno', [lno])) post)
paulson@21978
   392
  | add_prfline ((lno, role, t, []), lines) =  (*no deps: conjecture clause*)
paulson@22470
   393
      (lno, t, []) :: lines
paulson@21978
   394
  | add_prfline ((lno, role, t, deps), lines) =
paulson@22491
   395
      if eq_types t then (lno, t, deps) :: lines
paulson@22491
   396
      (*Type information will be deleted later; skip repetition test.*)
paulson@22491
   397
      else (*FIXME: Doesn't this code risk conflating proofs involving different types??*)
paulson@22044
   398
      case take_prefix (notequal t) lines of
paulson@22044
   399
         (_,[]) => (lno, t, deps) :: lines  (*no repetition of proof line*)
wenzelm@23139
   400
       | (pre, (lno',t',deps')::post) =>
paulson@22044
   401
           (lno, t', deps) ::               (*repetition: replace later line by earlier one*)
paulson@22044
   402
           (pre @ map (replace_deps (lno', [lno])) post);
paulson@22044
   403
paulson@22470
   404
(*Recursively delete empty lines (type information) from the proof.*)
paulson@22470
   405
fun add_nonnull_prfline ((lno, t, []), lines) = (*no dependencies, so a conjecture clause*)
paulson@22491
   406
     if eq_types t (*must be type information, tfree_tcs, clsrel, clsarity: delete refs to it*)
wenzelm@23139
   407
     then delete_dep lno lines
wenzelm@23139
   408
     else (lno, t, []) :: lines
paulson@22470
   409
  | add_nonnull_prfline ((lno, t, deps), lines) = (lno, t, deps) :: lines
paulson@22470
   410
and delete_dep lno lines = foldr add_nonnull_prfline [] (map (replace_deps (lno, [])) lines);
paulson@22470
   411
paulson@24937
   412
fun bad_free (Free (a,_)) = String.isPrefix "sko_" a
paulson@22731
   413
  | bad_free _ = false;
paulson@22731
   414
wenzelm@23139
   415
(*TVars are forbidden in goals. Also, we don't want lines with <2 dependencies.
paulson@22491
   416
  To further compress proofs, setting modulus:=n deletes every nth line, and nlines
paulson@22491
   417
  counts the number of proof lines processed so far.
paulson@22491
   418
  Deleted lines are replaced by their own dependencies. Note that the "add_nonnull_prfline"
paulson@22044
   419
  phase may delete some dependencies, hence this phase comes later.*)
paulson@25710
   420
fun add_wanted_prfline ctxt ((lno, t, []), (nlines, lines)) =
paulson@22491
   421
      (nlines, (lno, t, []) :: lines)   (*conjecture clauses must be kept*)
paulson@25710
   422
  | add_wanted_prfline ctxt ((lno, t, deps), (nlines, lines)) =
paulson@22545
   423
      if eq_types t orelse not (null (term_tvars t)) orelse
paulson@24937
   424
         exists bad_free (term_frees t) orelse
paulson@24937
   425
         (not (null lines) andalso   (*final line can't be deleted for these reasons*)
paulson@25710
   426
          (length deps < 2 orelse nlines mod (Config.get ctxt modulus) <> 0))   
paulson@22491
   427
      then (nlines+1, map (replace_deps (lno, deps)) lines) (*Delete line*)
paulson@22491
   428
      else (nlines+1, (lno, t, deps) :: lines);
paulson@21978
   429
paulson@21999
   430
(*Replace numeric proof lines by strings, either from thm_names or sequential line numbers*)
paulson@21978
   431
fun stringify_deps thm_names deps_map [] = []
paulson@21978
   432
  | stringify_deps thm_names deps_map ((lno, t, deps) :: lines) =
paulson@21978
   433
      if lno <= Vector.length thm_names  (*axiom*)
wenzelm@23139
   434
      then (Vector.sub(thm_names,lno-1), t, []) :: stringify_deps thm_names deps_map lines
paulson@21979
   435
      else let val lname = Int.toString (length deps_map)
wenzelm@23139
   436
               fun fix lno = if lno <= Vector.length thm_names
paulson@21978
   437
                             then SOME(Vector.sub(thm_names,lno-1))
paulson@21978
   438
                             else AList.lookup op= deps_map lno;
paulson@22731
   439
           in  (lname, t, List.mapPartial fix (distinct (op=) deps)) ::
paulson@21978
   440
               stringify_deps thm_names ((lno,lname)::deps_map) lines
paulson@21978
   441
           end;
paulson@21978
   442
paulson@24547
   443
val proofstart = "proof (neg_clausify)\n";
paulson@21979
   444
paulson@21979
   445
fun isar_header [] = proofstart
paulson@21999
   446
  | isar_header ts = proofstart ^ "fix " ^ space_implode " " ts ^ "\n";
paulson@21979
   447
paulson@22012
   448
fun decode_tstp_file cnfs ctxt th sgno thm_names =
paulson@26333
   449
  let val _ = trace "\ndecode_tstp_file: start\n"
paulson@26333
   450
      val tuples = map (dest_tstp o tstp_line o explode) cnfs
paulson@26333
   451
      val _ = trace (Int.toString (length tuples) ^ " tuples extracted\n")
paulson@24552
   452
      val ctxt = ProofContext.set_mode ProofContext.mode_schematic ctxt
paulson@26333
   453
      val raw_lines = foldr add_prfline [] (decode_tstp_list ctxt tuples)
paulson@26333
   454
      val _ = trace (Int.toString (length raw_lines) ^ " raw_lines extracted\n")
paulson@26333
   455
      val nonnull_lines = foldr add_nonnull_prfline [] raw_lines
paulson@26333
   456
      val _ = trace (Int.toString (length nonnull_lines) ^ " nonnull_lines extracted\n")
paulson@25710
   457
      val (_,lines) = foldr (add_wanted_prfline ctxt) (0,[]) nonnull_lines
paulson@26333
   458
      val _ = trace (Int.toString (length lines) ^ " lines extracted\n")
paulson@21999
   459
      val (ccls,fixes) = ResAxioms.neg_conjecture_clauses th sgno
paulson@26333
   460
      val _ = trace (Int.toString (length ccls) ^ " conjecture clauses\n")
paulson@21999
   461
      val ccls = map forall_intr_vars ccls
paulson@26333
   462
      val _ = if !Output.debugging then app (fn th => trace ("\nccl: " ^ string_of_thm th)) ccls
paulson@26333
   463
              else ()
paulson@26333
   464
      val ilines = isar_lines ctxt (map prop_of ccls) (stringify_deps thm_names [] lines)
paulson@26333
   465
      val _ = trace "\ndecode_tstp_file: finishing\n"
wenzelm@23139
   466
  in
paulson@26333
   467
    isar_header (map #1 fixes) ^ String.concat ilines ^ "qed\n"
paulson@24547
   468
  end
paulson@24547
   469
  handle e => (*FIXME: exn handler is too general!*)
paulson@26333
   470
    let val msg = "Translation of TSTP raised an exception: " ^ Toplevel.exn_message e
paulson@26333
   471
    in  trace msg; msg  end;
paulson@21978
   472
paulson@21978
   473
(*Could use split_lines, but it can return blank lines...*)
paulson@21978
   474
val lines = String.tokens (equal #"\n");
paulson@21978
   475
paulson@21978
   476
val nospaces = String.translate (fn c => if Char.isSpace c then "" else str c);
paulson@21978
   477
paulson@23519
   478
val txt_path = Path.ext "txt" o Path.explode o nospaces;
paulson@21978
   479
wenzelm@23139
   480
fun signal_success probfile toParent ppid msg =
paulson@23519
   481
  let val _ = trace ("\nReporting Success for " ^ probfile ^ "\n" ^ msg)
paulson@23519
   482
  in
paulson@23519
   483
    (*We write the proof to a file because sending very long lines may fail...*)
paulson@23519
   484
    File.write (txt_path probfile) msg;
paulson@23519
   485
    TextIO.output (toParent, "Success.\n");
paulson@23519
   486
    TextIO.output (toParent, probfile ^ "\n");
paulson@23519
   487
    TextIO.flushOut toParent;
wenzelm@25414
   488
    Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
paulson@23833
   489
    (*Give the parent time to respond before possibly sending another signal*)
paulson@23833
   490
    OS.Process.sleep (Time.fromMilliseconds 600)
paulson@23519
   491
  end;
paulson@21978
   492
paulson@21978
   493
paulson@21978
   494
(**** retrieve the axioms that were used in the proof ****)
paulson@21978
   495
paulson@24547
   496
(*PureThy.get_name_hint returns "??.unknown" if no name is available.*)
paulson@24547
   497
fun goodhint x = (x <> "??.unknown");  
paulson@24547
   498
paulson@21978
   499
(*Get names of axioms used. Axioms are indexed from 1, while the vector is indexed from 0*)
wenzelm@23139
   500
fun get_axiom_names (thm_names: string vector) step_nums =
wenzelm@23139
   501
    let fun is_axiom n = n <= Vector.length thm_names
paulson@24547
   502
        fun getname i = Vector.sub(thm_names, i-1)
paulson@21978
   503
    in
paulson@24547
   504
	sort_distinct string_ord (filter goodhint (map getname (filter is_axiom step_nums)))
paulson@24547
   505
    end;
paulson@21978
   506
wenzelm@23139
   507
 (*String contains multiple lines. We want those of the form
paulson@21978
   508
     "253[0:Inp] et cetera..."
paulson@21978
   509
  A list consisting of the first number in each line is returned. *)
paulson@24425
   510
fun get_spass_linenums proofextract =
paulson@21978
   511
  let val toks = String.tokens (not o Char.isAlphaNum)
paulson@21978
   512
      fun inputno (ntok::"0"::"Inp"::_) = Int.fromString ntok
paulson@21978
   513
        | inputno _ = NONE
paulson@24425
   514
      val lines = String.tokens (fn c => c = #"\n") proofextract
paulson@21978
   515
  in  List.mapPartial (inputno o toks) lines  end
paulson@21978
   516
paulson@24425
   517
fun get_axiom_names_spass proofextract thm_names =
paulson@24425
   518
   get_axiom_names thm_names (get_spass_linenums proofextract);
wenzelm@23139
   519
paulson@21978
   520
fun not_comma c = c <>  #",";
paulson@21978
   521
paulson@21978
   522
(*A valid TSTP axiom line has the form  cnf(NNN,axiom,...) where NNN is a positive integer.*)
paulson@21978
   523
fun parse_tstp_line s =
paulson@21978
   524
  let val ss = Substring.full (unprefix "cnf(" (nospaces s))
paulson@21978
   525
      val (intf,rest) = Substring.splitl not_comma ss
paulson@21978
   526
      val (rolef,rest) = Substring.splitl not_comma (Substring.triml 1 rest)
paulson@21978
   527
      (*We only allow negated_conjecture because the line number will be removed in
paulson@21978
   528
        get_axiom_names above, while suppressing the UNSOUND warning*)
paulson@21978
   529
      val ints = if Substring.string rolef mem_string ["axiom","negated_conjecture"]
wenzelm@23139
   530
                 then Substring.string intf
wenzelm@23139
   531
                 else "error"
paulson@21978
   532
  in  Int.fromString ints  end
wenzelm@23139
   533
  handle Fail _ => NONE;
paulson@21978
   534
paulson@24425
   535
fun get_axiom_names_tstp proofextract thm_names =
paulson@24425
   536
   get_axiom_names thm_names (List.mapPartial parse_tstp_line (split_lines proofextract));
wenzelm@23139
   537
wenzelm@23139
   538
 (*String contains multiple lines. We want those of the form
paulson@24632
   539
     "*********** [448, input] ***********"
paulson@24632
   540
   or possibly those of the form
paulson@24632
   541
     "cnf(108, axiom, ..."
paulson@21978
   542
  A list consisting of the first number in each line is returned. *)
paulson@24425
   543
fun get_vamp_linenums proofextract =
paulson@21978
   544
  let val toks = String.tokens (not o Char.isAlphaNum)
paulson@21978
   545
      fun inputno [ntok,"input"] = Int.fromString ntok
paulson@24632
   546
        | inputno ("cnf"::ntok::"axiom"::_) = Int.fromString ntok
paulson@21978
   547
        | inputno _ = NONE
paulson@24425
   548
      val lines = String.tokens (fn c => c = #"\n") proofextract
paulson@21978
   549
  in  List.mapPartial (inputno o toks) lines  end
paulson@21978
   550
paulson@24425
   551
fun get_axiom_names_vamp proofextract thm_names =
paulson@24425
   552
   get_axiom_names thm_names (get_vamp_linenums proofextract);
paulson@24425
   553
paulson@24547
   554
fun get_axiom_names_for E       = get_axiom_names_tstp
paulson@24547
   555
  | get_axiom_names_for SPASS   = get_axiom_names_spass
paulson@24547
   556
  | get_axiom_names_for Vampire = get_axiom_names_vamp;
wenzelm@23139
   557
paulson@24547
   558
fun metis_line [] = "apply metis"
paulson@24547
   559
  | metis_line xs = "apply (metis " ^ space_implode " " xs ^ ")"
paulson@21978
   560
paulson@25492
   561
(*Used to label theorems chained into the sledgehammer call*)
paulson@25492
   562
val chained_hint = "CHAINED";
paulson@25492
   563
paulson@25492
   564
val nochained = filter_out (fn y => y = chained_hint);
paulson@25492
   565
paulson@21978
   566
(*The signal handler in watcher.ML must be able to read the output of this.*)
paulson@24425
   567
fun lemma_list atp proofextract thm_names probfile toParent ppid =
paulson@26333
   568
 (trace "\nlemma_list: ready to signal success";
paulson@24547
   569
  signal_success probfile toParent ppid 
paulson@26333
   570
                 (metis_line (nochained (get_axiom_names_for atp proofextract thm_names))));
paulson@21978
   571
paulson@24547
   572
fun tstp_extract proofextract thm_names probfile toParent ppid ctxt th sgno =
paulson@26333
   573
  let val _ = trace "\nAttempting to extract structured proof from TSTP\n"
paulson@26333
   574
      val cnfs = filter (String.isPrefix "cnf(") (map nospaces (lines proofextract))
paulson@26333
   575
      val _ = trace (Int.toString (length cnfs) ^ " cnfs found")
paulson@25492
   576
      val names = get_axiom_names_tstp proofextract thm_names
paulson@25492
   577
      val line1 = metis_line (nochained names)
paulson@26333
   578
      val _ = trace ("\nExtracted one-line proof: " ^ line1)
paulson@25492
   579
      val line2 = if chained_hint mem_string names then ""
paulson@25492
   580
                  else decode_tstp_file cnfs ctxt th sgno thm_names
paulson@26333
   581
      val _ = trace "\ntstp_extract: ready to signal success"
paulson@24425
   582
  in
paulson@25492
   583
    signal_success probfile toParent ppid (line1 ^ "\n" ^ line2)
paulson@24425
   584
  end;
paulson@21978
   585
paulson@21978
   586
(**** Extracting proofs from an ATP's output ****)
paulson@21978
   587
paulson@24547
   588
val start_TSTP = "SZS output start CNFRefutation"
paulson@24547
   589
val end_TSTP   = "SZS output end CNFRefutation"
paulson@21978
   590
val start_E = "# Proof object starts here."
paulson@21978
   591
val end_E   = "# Proof object ends here."
paulson@21978
   592
val start_V8 = "=========== Refutation =========="
paulson@21978
   593
val end_V8 = "======= End of refutation ======="
paulson@24547
   594
val start_SPASS = "Here is a proof"
paulson@21978
   595
val end_SPASS = "Formulae used in the proof"
paulson@21978
   596
paulson@24547
   597
fun any_substring ss ln = exists (fn s => String.isSubstring s ln) ss;
paulson@24547
   598
paulson@21978
   599
(*********************************************************************************)
paulson@21978
   600
(*  Inspect the output of an ATP process to see if it has found a proof,     *)
paulson@21978
   601
(*  and if so, transfer output to the input pipe of the main Isabelle process    *)
paulson@21978
   602
(*********************************************************************************)
paulson@21978
   603
paulson@21978
   604
(*Returns "true" if it successfully returns a lemma list, otherwise "false", but this
paulson@21978
   605
  return value is currently never used!*)
paulson@22012
   606
fun startTransfer endS (fromChild, toParent, ppid, probfile, ctxt, th, sgno, thm_names) =
paulson@24547
   607
 let val atp = if endS = end_V8 then Vampire
paulson@24547
   608
	       else if endS = end_SPASS then SPASS
paulson@24547
   609
	       else E
paulson@24547
   610
     fun transferInput proofextract =
paulson@24547
   611
       case TextIO.inputLine fromChild of
paulson@24547
   612
	   NONE =>  (*end of file?*)
paulson@24547
   613
	     (trace ("\n extraction_failed.  End bracket: " ^ endS ^
paulson@24547
   614
		     "\naccumulated text: " ^ proofextract);
paulson@24547
   615
	      false)
paulson@24547
   616
	 | SOME thisLine =>
paulson@24547
   617
	     if any_substring [endS,end_TSTP] thisLine
paulson@24547
   618
	     then
paulson@24547
   619
	      (trace ("\nExtracted proof:\n" ^ proofextract);
paulson@26333
   620
	       if Config.get ctxt full_proofs andalso String.isPrefix "cnf(" proofextract
paulson@24547
   621
	       then tstp_extract proofextract thm_names probfile toParent ppid ctxt th sgno
paulson@24425
   622
	       else lemma_list atp proofextract thm_names probfile toParent ppid;
paulson@24425
   623
	       true)
paulson@24547
   624
	     else transferInput (proofextract ^ thisLine)
paulson@21978
   625
 in
paulson@21978
   626
     transferInput ""
wenzelm@23139
   627
 end
paulson@21978
   628
paulson@21978
   629
paulson@21978
   630
(*The signal handler in watcher.ML must be able to read the output of this.*)
paulson@21978
   631
fun signal_parent (toParent, ppid, msg, probfile) =
paulson@21978
   632
 (TextIO.output (toParent, msg);
paulson@21978
   633
  TextIO.output (toParent, probfile ^ "\n");
paulson@21978
   634
  TextIO.flushOut toParent;
paulson@21978
   635
  trace ("\nSignalled parent: " ^ msg ^ probfile);
wenzelm@25414
   636
  Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
paulson@21978
   637
  (*Give the parent time to respond before possibly sending another signal*)
paulson@21978
   638
  OS.Process.sleep (Time.fromMilliseconds 600));
paulson@21978
   639
paulson@22012
   640
(*FIXME: once TSTP output is produced by all ATPs, these three functions can be combined.*)
paulson@22012
   641
paulson@21978
   642
(*Called from watcher. Returns true if the Vampire process has returned a verdict.*)
paulson@22012
   643
fun checkVampProofFound (arg as (fromChild, toParent, ppid, probfile, ctxt, th, sgno, thm_names)) =
wenzelm@23139
   644
  (case TextIO.inputLine fromChild of
wenzelm@23139
   645
    NONE => (trace "\nNo proof output seen"; false)
wenzelm@23139
   646
  | SOME thisLine =>
paulson@24547
   647
     if any_substring [start_V8,start_TSTP] thisLine
paulson@22012
   648
     then startTransfer end_V8 arg
paulson@24547
   649
     else if (String.isSubstring "Satisfiability detected" thisLine) orelse
paulson@24956
   650
             (String.isSubstring "Refutation not found" thisLine) orelse
paulson@24956
   651
             (String.isSubstring "CANNOT PROVE" thisLine)
paulson@21978
   652
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
paulson@21978
   653
	   true)
wenzelm@23139
   654
     else checkVampProofFound arg);
paulson@21978
   655
paulson@21978
   656
(*Called from watcher. Returns true if the E process has returned a verdict.*)
wenzelm@23139
   657
fun checkEProofFound (arg as (fromChild, toParent, ppid, probfile, ctxt, th, sgno, thm_names)) =
wenzelm@23139
   658
  (case TextIO.inputLine fromChild of
wenzelm@23139
   659
    NONE => (trace "\nNo proof output seen"; false)
wenzelm@23139
   660
  | SOME thisLine =>
paulson@24547
   661
     if any_substring [start_E,start_TSTP] thisLine 
paulson@22012
   662
     then startTransfer end_E arg
paulson@24547
   663
     else if String.isSubstring "SZS status: Satisfiable" thisLine
paulson@21978
   664
     then (signal_parent (toParent, ppid, "Invalid\n", probfile);
paulson@21978
   665
	   true)
paulson@24956
   666
     else if String.isSubstring "SZS status: ResourceOut" thisLine orelse
paulson@24956
   667
             String.isSubstring "# Cannot determine problem status" thisLine
paulson@21978
   668
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
paulson@21978
   669
	   true)
wenzelm@23139
   670
     else checkEProofFound arg);
paulson@21978
   671
paulson@21978
   672
(*Called from watcher. Returns true if the SPASS process has returned a verdict.*)
wenzelm@23139
   673
fun checkSpassProofFound (arg as (fromChild, toParent, ppid, probfile, ctxt, th, sgno, thm_names)) =
wenzelm@23139
   674
  (case TextIO.inputLine fromChild of
wenzelm@23139
   675
    NONE => (trace "\nNo proof output seen"; false)
wenzelm@23139
   676
  | SOME thisLine =>
paulson@24547
   677
     if any_substring [start_SPASS,start_TSTP] thisLine
paulson@22012
   678
     then startTransfer end_SPASS arg
paulson@21978
   679
     else if thisLine = "SPASS beiseite: Completion found.\n"
paulson@21978
   680
     then (signal_parent (toParent, ppid, "Invalid\n", probfile);
paulson@21978
   681
	   true)
paulson@21978
   682
     else if thisLine = "SPASS beiseite: Ran out of time.\n" orelse
paulson@21978
   683
             thisLine = "SPASS beiseite: Maximal number of loops exceeded.\n"
paulson@21978
   684
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
paulson@21978
   685
	   true)
wenzelm@23139
   686
    else checkSpassProofFound arg);
paulson@21978
   687
paulson@21978
   688
end;