src/HOL/Tools/res_atp.ML
author paulson
Fri, 07 Oct 2005 11:29:24 +0200
changeset 17773 a7258e1020b7
parent 17772 818cec5f82a4
child 17775 2679ba74411f
permissions -rw-r--r--
more tidying. Fixed process management bugs and race condition
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
     1
(*  Author: Jia Meng, Cambridge University Computer Laboratory
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
     2
    ID: $Id$
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
     3
    Copyright 2004 University of Cambridge
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     4
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     5
ATPs with TPTP format input.
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     6
*)
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
     7
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
     8
signature RES_ATP =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
     9
sig
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
    10
  val prover: string ref
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    11
  val custom_spass: string list ref
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    12
  val destdir: string ref
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    13
  val hook_count: int ref
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    14
  val problem_name: string ref
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
    15
  val time_limit: int ref
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    16
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    17
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    18
structure ResAtp: RES_ATP =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    19
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    20
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    21
val call_atp = ref false;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    22
val hook_count = ref 0;
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
    23
val time_limit = ref 60;
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    24
17404
d16c3a62c396 the experimental tagging system, and the usual tidying
paulson
parents: 17317
diff changeset
    25
val prover = ref "E";   (* use E as the default prover *)
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    26
val custom_spass =   (*specialized options for SPASS*)
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
    27
      ref ["-Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub"];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    28
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    29
val destdir = ref "";   (*Empty means write files to /tmp*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    30
val problem_name = ref "prob";
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    31
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    32
fun probfile_nosuffix _ = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    33
  if !destdir = "" then File.platform_path (File.tmp_path (Path.basic (!problem_name)))
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    34
  else if File.exists (File.unpack_platform_path (!destdir))
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    35
  then !destdir ^ "/" ^ !problem_name
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    36
  else error ("No such directory: " ^ !destdir);
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    37
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    38
fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n;
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    39
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    40
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    41
(**** For running in Isar ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    42
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    43
(* same function as that in res_axioms.ML *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    44
fun repeat_RS thm1 thm2 =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    45
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    46
    in
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    47
        if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    48
    end;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    49
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    50
(* a special version of repeat_RS *)
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    51
fun repeat_someI_ex th = repeat_RS th someI_ex;
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    52
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    53
fun writeln_strs _   []      = ()
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    54
  | writeln_strs out (s::ss) = (TextIO.output (out, s); TextIO.output (out, "\n"); writeln_strs out ss);
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
    55
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
    56
(* write out a subgoal as tptp clauses to the file "xxxx_N"*)
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    57
fun tptp_inputs_tfrees thms pf n (axclauses,classrel_clauses,arity_clauses) =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    58
    let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    59
      val clss = map (ResClause.make_conjecture_clause_thm) thms
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    60
      val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    61
      val tfree_clss = map ResClause.tfree_clause (ResLib.flat_noDup tfree_litss)
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    62
      val classrel_cls = map ResClause.tptp_classrelClause classrel_clauses
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    63
      val arity_cls = map ResClause.tptp_arity_clause arity_clauses
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    64
      val out = TextIO.openOut(pf n)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    65
    in
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    66
      writeln_strs out (List.concat (map ResClause.tptp_clause axclauses));
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    67
      writeln_strs out (tfree_clss @ tptp_clss @ classrel_cls @ arity_cls);
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    68
      TextIO.closeOut out
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    69
    end;
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
    70
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
    71
(* write out a subgoal in DFG format to the file "xxxx_N"*)
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    72
fun dfg_inputs_tfrees thms pf n (axclauses,classrel_clauses,arity_clauses) = 
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    73
    let val clss = map (ResClause.make_conjecture_clause_thm) thms
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    74
        (*FIXME: classrel_clauses and arity_clauses*)
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    75
        val probN = ResClause.clauses2dfg clss (!problem_name ^ "_" ^ Int.toString n)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    76
                        axclauses [] [] []    
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    77
	val out = TextIO.openOut(pf n)
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    78
    in
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    79
	writeln_strs out [probN]; TextIO.closeOut out
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    80
    end;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    81
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
    82
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    83
(*********************************************************************)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
    84
(* call prover with settings and problem file for the current subgoal *)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    85
(*********************************************************************)
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
    86
(* now passing in list of skolemized thms and list of sgterms to go with them *)
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    87
fun watcher_call_provers sign sg_terms (childin, childout, pid) =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    88
  let
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    89
    fun make_atp_list [] n = []
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    90
      | make_atp_list (sg_term::xs) n =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    91
          let
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    92
            val probfile = prob_pathname n
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
    93
            val time = Int.toString (!time_limit)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    94
          in
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    95
            debug ("problem file in watcher_call_provers is " ^ probfile);
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
    96
            (*Avoid command arguments containing spaces: Poly/ML and SML/NJ
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
    97
              versions of Unix.execute treat them differently!*)
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
    98
            (*options are separated by Watcher.setting_sep, currently #"%"*)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
    99
            if !prover = "spass"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   100
            then
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   101
              let val optionline = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   102
		      if !AtpCommunication.reconstruct 
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   103
		          (*Proof reconstruction works for only a limited set of 
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   104
		            inference rules*)
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   105
                      then space_implode "%" (!custom_spass) ^
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   106
                           "%-DocProof%-TimeLimit=" ^ time
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   107
                      else "-DocProof%-SOS%-FullRed=0%-TimeLimit=" ^ time (*Auto mode*)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   108
                  val _ = debug ("SPASS option string is " ^ optionline)
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   109
                  val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   110
                    (*We've checked that SPASS is there for ATP/spassshell to run.*)
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   111
              in 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   112
                  ([("spass", 
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   113
                     getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell",
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   114
                     optionline, probfile)] @ 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   115
                  (make_atp_list xs (n+1)))
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   116
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   117
            else if !prover = "vampire"
17235
8e55ad29b690 Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents: 17234
diff changeset
   118
	    then 
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   119
              let val vampire = ResLib.helper_path "VAMPIRE_HOME" "vampire"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   120
              in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   121
                ([("vampire", vampire, "-m 100000%-t " ^ time, probfile)] @
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   122
                 (make_atp_list xs (n+1)))       (*BEWARE! spaces in options!*)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   123
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   124
      	     else if !prover = "E"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   125
      	     then
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   126
	       let val Eprover = ResLib.helper_path "E_HOME" "eproof"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   127
	       in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   128
		  ([("E", Eprover, 
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   129
		     "--tptp-in%-l5%-xAuto%-tAuto%--cpu-limit=" ^ time,
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   130
		     probfile)] @
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   131
		   (make_atp_list xs (n+1)))
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   132
	       end
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   133
	     else error ("Invalid prover name: " ^ !prover)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   134
          end
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   135
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   136
    val atp_list = make_atp_list sg_terms 1
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   137
  in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   138
    Watcher.callResProvers(childout,atp_list);
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   139
    debug "Sent commands to watcher!"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   140
  end
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   141
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   142
(*We write out problem files for each subgoal. Argument pf generates filenames,
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   143
  and allows the suppression of the suffix "_1" in problem-generation mode.*)
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   144
fun write_problem_files pf (ctxt,th)  =
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   145
  let val prems = Thm.prems_of th
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   146
      val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   147
              (*FIXME: hack!! need to consider relevance for all prems*)
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   148
      val _ = debug ("claset and simprules total clauses = " ^ 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   149
                     Int.toString (Array.length clause_arr))
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   150
      val thy = ProofContext.theory_of ctxt
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   151
      val classrel_clauses = ResTypesSorts.classrel_clauses_thy thy
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   152
      val _ = debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   153
      val arity_clauses = ResTypesSorts.arity_clause_thy thy
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   154
      val _ = debug ("arity clauses = " ^ Int.toString (length arity_clauses))
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   155
      val write = if !prover = "spass" then dfg_inputs_tfrees else tptp_inputs_tfrees
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   156
      fun writenext n =
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   157
	if n=0 then []
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   158
	 else
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   159
	   (SELECT_GOAL
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   160
	    (EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   161
	      METAHYPS(fn negs => 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   162
		(write (make_clauses negs) pf n 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   163
		       (axclauses,classrel_clauses,arity_clauses);
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   164
		 all_tac))]) n th;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   165
	    pf n :: writenext (n-1))
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   166
      in (writenext (length prems), clause_arr) end;
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   167
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   168
val last_watcher_pid =
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   169
  ref (NONE : (TextIO.instream * TextIO.outstream * 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   170
               Posix.Process.pid * string list) option);
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   171
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   172
(*writes out the current clasimpset to a tptp file;
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   173
  turns off xsymbol at start of function, restoring it at end    *)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   174
val isar_atp = setmp print_mode [] 
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   175
 (fn (ctxt, th) =>
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   176
  if Thm.no_prems th then ()
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   177
  else
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   178
    let
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   179
      val _ = (case !last_watcher_pid of NONE => ()
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   180
               | SOME (_, childout, pid, files) => 
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   181
                  (debug ("Killing old watcher, pid = " ^ 
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   182
                          Int.toString (ResLib.intOfPid pid));
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   183
                   Watcher.killWatcher pid;  
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   184
                   ignore (map (try OS.FileSys.remove) files)))
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   185
              handle OS.SysErr _ => debug "Attempt to kill watcher failed";
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   186
      val (files,clause_arr) = write_problem_files prob_pathname (ctxt,th)
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   187
      val (childin, childout, pid) = Watcher.createWatcher (th, clause_arr)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   188
    in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   189
      last_watcher_pid := SOME (childin, childout, pid, files);
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   190
      debug ("problem files: " ^ space_implode ", " files); 
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   191
      debug ("pid: " ^ Int.toString (ResLib.intOfPid pid));
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   192
      watcher_call_provers (sign_of_thm th) (Thm.prems_of th) (childin, childout, pid)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   193
    end);
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   194
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   195
val isar_atp_writeonly = setmp print_mode [] 
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   196
      (fn (ctxt,th) =>
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   197
       if Thm.no_prems th then ()
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   198
       else 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   199
         let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   200
         	      else prob_pathname
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   201
         in ignore (write_problem_files pf (ctxt,th)) end);
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   202
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   203
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   204
(** the Isar toplevel hook **)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   205
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   206
val invoke_atp = Toplevel.unknown_proof o Toplevel.keep (fn state =>
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   207
  let
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   208
    val proof = Toplevel.proof_of state
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   209
    val (ctxt, (_, goal)) = Proof.get_goal proof
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   210
        handle Proof.STATE _ => error "No goal present";
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   211
    val thy = ProofContext.theory_of ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   212
  in
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   213
    debug ("subgoals in isar_atp:\n" ^ 
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   214
           Pretty.string_of (ProofContext.pretty_term ctxt
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   215
             (Logic.mk_conjunction_list (Thm.prems_of goal))));
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   216
    debug ("number of subgoals in isar_atp: " ^ Int.toString (Thm.nprems_of goal));
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   217
    debug ("current theory: " ^ Context.theory_name thy);
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   218
    hook_count := !hook_count +1;
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   219
    debug ("in hook for time: " ^ Int.toString (!hook_count));
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
   220
    ResClause.init thy;
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   221
    if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal)
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   222
    else isar_atp_writeonly (ctxt, goal)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   223
  end);
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   224
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   225
val call_atpP =
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17717
diff changeset
   226
  OuterSyntax.command 
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   227
    "ProofGeneral.call_atp" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   228
    "call automatic theorem provers" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   229
    OuterKeyword.diag
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   230
    (Scan.succeed (Toplevel.no_timing o invoke_atp));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   231
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   232
val _ = OuterSyntax.add_parsers [call_atpP];
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   233
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   234
end;