src/HOL/Tools/res_atp.ML
author paulson
Tue, 20 Sep 2005 18:43:39 +0200
changeset 17525 ae5bb6001afb
parent 17502 8836793df947
child 17690 8ba7c3cd24a8
permissions -rw-r--r--
tidying, and support for axclass/classrel clauses
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
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    15
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    16
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    17
structure ResAtp: RES_ATP =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    18
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    19
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    20
val call_atp = ref false;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    21
val hook_count = ref 0;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    22
17404
d16c3a62c396 the experimental tagging system, and the usual tidying
paulson
parents: 17317
diff changeset
    23
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
    24
val custom_spass =   (*specialized options for SPASS*)
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
    25
      ref ["Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub",
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    26
           "-DocProof","-TimeLimit=60"];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    27
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    28
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
    29
val problem_name = ref "prob";
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    30
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    31
fun prob_pathname() = 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    32
  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
    33
  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
    34
  then !destdir ^ "/" ^ !problem_name
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    35
  else error ("No such directory: " ^ !destdir);
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    36
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    37
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    38
(**** for Isabelle/ML interface  ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    39
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    40
(*Remove unwanted characters such as ? and newline from the textural 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    41
  representation of a theorem (surely they don't need to be produced in 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    42
  the first place?) *)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    43
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    44
fun is_proof_char ch = (#" " <= ch andalso ch <= #"~" andalso ch <> #"?");
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    45
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    46
val proofstring =
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    47
    String.translate (fn c => if is_proof_char c then str c else "");
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    48
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
    49
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    50
(**** For running in Isar ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    51
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    52
(* same function as that in res_axioms.ML *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    53
fun repeat_RS thm1 thm2 =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    54
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    55
    in
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    56
        if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    57
    end;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    58
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    59
(* a special version of repeat_RS *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    60
fun repeat_someI_ex thm = repeat_RS thm someI_ex;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    61
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
    62
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
    63
(* write out a subgoal as tptp clauses to the file "xxxx_N"*)
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    64
fun tptp_inputs_tfrees thms n (axclauses,classrel_clauses,arity_clauses) =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    65
    let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    66
      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
    67
      val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    68
      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
    69
      val classrel_cls = map ResClause.tptp_classrelClause classrel_clauses
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    70
      val arity_cls = map ResClause.tptp_arity_clause arity_clauses
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    71
      val probfile = prob_pathname() ^ "_" ^ Int.toString n
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    72
      val out = TextIO.openOut(probfile)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    73
    in
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    74
      ResLib.writeln_strs out (List.concat (map ResClause.tptp_clause axclauses));
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    75
      ResLib.writeln_strs out (tfree_clss @ tptp_clss @ classrel_cls @ arity_cls);
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    76
      TextIO.closeOut out;
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    77
      debug probfile
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    78
    end;
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
    79
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
    80
(* write out a subgoal in DFG format to the file "xxxx_N"*)
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    81
fun dfg_inputs_tfrees thms n (axclauses,classrel_clauses,arity_clauses) = 
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    82
    let val clss = map (ResClause.make_conjecture_clause_thm) thms
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    83
        val probfile = prob_pathname() ^ "_" ^ (Int.toString n)
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    84
        (*FIXME: classrel_clauses and arity_clauses*)
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
    85
        val _ = debug ("about to write out dfg prob file " ^ probfile)
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
    86
        val probN = ResClause.clauses2dfg clss (!problem_name ^ "_" ^ Int.toString n)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    87
                        axclauses [] [] []    
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    88
	val out = TextIO.openOut(probfile)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    89
    in
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
    90
	(ResLib.writeln_strs out [probN]; TextIO.closeOut out; debug probfile )
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    91
    end;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    92
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
    93
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    94
(*********************************************************************)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
    95
(* call prover with settings and problem file for the current subgoal *)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    96
(*********************************************************************)
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
    97
(* now passing in list of skolemized thms and list of sgterms to go with them *)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    98
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
    99
  let
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   100
    fun make_atp_list [] n = []
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   101
      | 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
   102
          let
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   103
            val goalstring = proofstring (Sign.string_of_term sign sg_term)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   104
            val _ = debug ("goalstring in make_atp_lists is " ^ goalstring)
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   105
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   106
            val probfile = prob_pathname() ^ "_" ^ Int.toString n
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   107
            val _ = debug ("problem file in watcher_call_provers is " ^ probfile)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   108
          in
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
   109
            (*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
   110
              versions of Unix.execute treat them differently!*)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   111
            if !prover = "spass"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   112
            then
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   113
              let val optionline = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   114
		      if !AtpCommunication.reconstruct 
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   115
		          (*Proof reconstruction works for only a limited set of 
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   116
		            inference rules*)
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   117
                      then "-" ^ space_implode "%-" (!custom_spass)
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
   118
                      else "-DocProof%-TimeLimit=60%-SOS%-FullRed=0" (*Auto mode*)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   119
                  val _ = debug ("SPASS option string is " ^ optionline)
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   120
                  val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   121
                    (*We've checked that SPASS is there for ATP/spassshell to run.*)
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   122
              in 
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   123
                  ([("spass", goalstring,
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   124
                     getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell",
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   125
                     optionline, probfile)] @ 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   126
                  (make_atp_list xs (n+1)))
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   127
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   128
            else if !prover = "vampire"
17235
8e55ad29b690 Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents: 17234
diff changeset
   129
	    then 
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   130
              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
   131
              in
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   132
                ([("vampire", goalstring, vampire, "-t 60%-m 100000", probfile)] @
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   133
                 (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
   134
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   135
      	     else if !prover = "E"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   136
      	     then
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   137
	       let val Eprover = ResLib.helper_path "E_HOME" "eproof"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   138
	       in
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   139
		  ([("E", goalstring, Eprover, 
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   140
		     "--tptp-in%-l5%-xAuto%-tAuto%--soft-cpu-limit=60",
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   141
		     probfile)] @
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   142
		   (make_atp_list xs (n+1)))
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   143
	       end
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   144
	     else error ("Invalid prover name: " ^ !prover)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   145
          end
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   146
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   147
    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
   148
  in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   149
    Watcher.callResProvers(childout,atp_list);
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   150
    debug "Sent commands to watcher!"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   151
  end
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   152
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   153
(*We write out problem files for each subgoal*)
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   154
fun write_problem_files clause thm n =
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   155
    if n=0 then ()
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   156
     else
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   157
       (SELECT_GOAL
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   158
        (EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, 
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   159
          METAHYPS(fn negs => 
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   160
            (if !prover = "spass" 
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   161
             then dfg_inputs_tfrees (make_clauses negs) n clause
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   162
             else tptp_inputs_tfrees (make_clauses negs) n clause;
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   163
             write_problem_files clause thm (n-1); 
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   164
             all_tac))]) n thm;
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   165
        ());
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   166
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   167
val last_watcher_pid = ref (NONE : Posix.Process.pid option);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   168
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   169
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   170
(*writes out the current clasimpset to a tptp file;
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   171
  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
   172
val isar_atp = setmp print_mode [] 
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   173
 (fn (ctxt, thm) =>
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   174
  if Thm.no_prems thm then ()
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   175
  else
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   176
    let
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   177
      val _= debug "in isar_atp"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   178
      val thy = ProofContext.theory_of ctxt
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   179
      val prems = Thm.prems_of thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   180
      val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) prems)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   181
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   182
      val _ = (case !last_watcher_pid of NONE => ()
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   183
               | SOME pid => (*FIXME: should kill ATP processes too; at least they time out*)
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   184
                  (debug ("Killing old watcher, pid = " ^ 
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   185
                          Int.toString (ResLib.intOfPid pid));
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   186
                   Watcher.killWatcher pid))
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   187
              handle OS.SysErr _ => debug "Attempt to kill watcher failed";
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   188
      (*set up variables for writing out the clasimps to a tptp file*)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   189
      val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   190
              (*FIXME: hack!! need to consider relevance for all prems*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   191
      val _ = debug ("claset and simprules total clauses = " ^ 
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   192
                     Int.toString (Array.length clause_arr))
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   193
      val classrel_clauses = ResTypesSorts.classrel_clauses_thy thy
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   194
      val _ = debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   195
      val arity_clauses = ResTypesSorts.arity_clause_thy thy
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   196
      val _ = debug ("arity clauses = " ^ Int.toString (length arity_clauses))
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   197
      val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   198
    in
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   199
      last_watcher_pid := SOME pid;
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   200
      debug ("subgoals: " ^ prems_string);
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   201
      debug ("pid: " ^ Int.toString (ResLib.intOfPid pid));
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   202
      write_problem_files (axclauses,classrel_clauses,arity_clauses) thm (length prems);
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   203
      watcher_call_provers (sign_of_thm thm) (Thm.prems_of thm) (childin, childout, pid)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   204
    end);
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   205
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   206
val isar_atp_writeonly = setmp print_mode [] 
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   207
 (fn (ctxt, thm) =>
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   208
  if Thm.no_prems thm then ()
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   209
  else
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   210
    let 
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   211
      val prems = Thm.prems_of thm
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   212
      val (_, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   213
      val thy = ProofContext.theory_of ctxt
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   214
      val classrel_clauses = ResTypesSorts.classrel_clauses_thy thy
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   215
      val arity_clauses = ResTypesSorts.arity_clause_thy thy
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   216
    in
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   217
      write_problem_files (axclauses,classrel_clauses,arity_clauses) thm (length prems)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   218
    end);
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   219
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   220
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   221
(** the Isar toplevel hook **)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   222
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   223
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
   224
  let
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   225
    val proof = Toplevel.proof_of state
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   226
    val (ctxt, (_, goal)) = Proof.get_goal proof
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   227
        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
   228
    val thy = ProofContext.theory_of ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   229
  in
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   230
    debug ("initial thm in isar_atp: " ^ 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   231
           Pretty.string_of (ProofContext.pretty_thm ctxt goal));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   232
    debug ("subgoals in isar_atp: " ^ 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   233
           Pretty.string_of (ProofContext.pretty_term ctxt
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   234
             (Logic.mk_conjunction_list (Thm.prems_of goal))));
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   235
    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
   236
    debug ("current theory: " ^ Context.theory_name thy);
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   237
    hook_count := !hook_count +1;
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   238
    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
   239
    ResClause.init thy;
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   240
    if !destdir = "" then isar_atp (ctxt, goal)
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   241
    else isar_atp_writeonly (ctxt, goal)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   242
  end);
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   243
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   244
val call_atpP =
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   245
  OuterSyntax.improper_command 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   246
    "ProofGeneral.call_atp" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   247
    "call automatic theorem provers" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   248
    OuterKeyword.diag
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   249
    (Scan.succeed (Toplevel.no_timing o invoke_atp));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   250
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   251
val _ = OuterSyntax.add_parsers [call_atpP];
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   252
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   253
end;