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