src/HOL/Tools/res_atp.ML
author paulson
Fri, 16 Sep 2005 11:39:09 +0200
changeset 17435 0eed5a1c00c1
parent 17422 3b237822985d
child 17484 f6a225f97f0a
permissions -rw-r--r--
PARTIAL conversion to Vampire8
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
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    12
  val hook_count: int ref
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    13
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    14
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    15
structure ResAtp: RES_ATP =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    16
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    17
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    18
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    19
val call_atp = ref false;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    20
val hook_count = ref 0;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    21
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    22
fun debug_tac tac = (debug "testing"; tac);
16478
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    23
17404
d16c3a62c396 the experimental tagging system, and the usual tidying
paulson
parents: 17317
diff changeset
    24
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
    25
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
    26
      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
    27
           "-DocProof","-TimeLimit=60"];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    28
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    29
val prob_file = File.tmp_path (Path.basic "prob");
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    30
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    31
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    32
(**** for Isabelle/ML interface  ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    33
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    34
(*Remove unwanted characters such as ? and newline from the textural 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    35
  representation of a theorem (surely they don't need to be produced in 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    36
  the first place?) *)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    37
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    38
fun is_proof_char ch = (#" " <= ch andalso ch <= #"~" andalso ch <> #"?");
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    39
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    40
val proofstring =
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    41
    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
    42
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
    43
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    44
(**** For running in Isar ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    45
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    46
(* same function as that in res_axioms.ML *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    47
fun repeat_RS thm1 thm2 =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    48
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    49
    in
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    50
        if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    51
    end;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    52
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    53
(* a special version of repeat_RS *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    54
fun repeat_someI_ex thm = repeat_RS thm someI_ex;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    55
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
    56
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    57
(*********************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    58
(* write out a subgoal as tptp clauses to the file "probN"           *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    59
(* where N is the number of this subgoal                             *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    60
(*********************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    61
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    62
fun tptp_inputs_tfrees thms n axclauses =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    63
    let
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    64
      val _ = debug ("in tptp_inputs_tfrees 0")
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    65
      val clss = map (ResClause.make_conjecture_clause_thm) thms
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    66
      val _ = debug ("in tptp_inputs_tfrees 1")
16802
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)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    68
      val _ = debug ("in tptp_inputs_tfrees 2")
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    69
      val tfree_clss = map ResClause.tfree_clause (ResLib.flat_noDup tfree_litss)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    70
      val _ = debug ("in tptp_inputs_tfrees 3")
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    71
      val probfile = File.platform_path prob_file ^ "_" ^ string_of_int n
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));
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    75
      ResLib.writeln_strs out (tfree_clss @ tptp_clss);
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
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    80
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    81
(*********************************************************************)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    82
(* write out a subgoal as DFG clauses to the file "probN"           *)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    83
(* where N is the number of this subgoal                             *)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    84
(*********************************************************************)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    85
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    86
fun dfg_inputs_tfrees thms n axclauses = 
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    87
    let val clss = map (ResClause.make_conjecture_clause_thm) thms
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    88
        val probfile = (File.platform_path prob_file) ^ "_" ^ (string_of_int n)
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
    89
        val _ = debug ("about to write out dfg prob file " ^ probfile)
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
    90
        val probN = ResClause.clauses2dfg clss ("prob" ^ (string_of_int n)) 
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
    91
                        axclauses [] [] []    
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    92
	val out = TextIO.openOut(probfile)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    93
    in
17234
12a9393c5d77 further tidying up of Isabelle-ATP link
paulson
parents: 17231
diff changeset
    94
	(ResLib.writeln_strs out [probN]; TextIO.closeOut out; debug probfile )
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
    95
(* (ResLib.writeln_strs out (tfree_clss @ dfg_clss); *)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    96
    end;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    97
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
    98
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    99
(*********************************************************************)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   100
(* call prover with settings and problem file for the current subgoal *)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   101
(*********************************************************************)
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   102
(* 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
   103
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
   104
  let
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   105
    fun make_atp_list [] n = []
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   106
      | 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
   107
          let
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   108
            val goalstring = proofstring (Sign.string_of_term sign sg_term)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   109
            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
   110
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   111
            val probfile = File.platform_path prob_file ^ "_" ^ (string_of_int n)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   112
            val _ = debug ("prob 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
   113
          in
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
   114
            (*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
   115
              versions of Unix.execute treat them differently!*)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   116
            if !prover = "spass"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   117
            then
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   118
              let val optionline = 
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   119
		      if !SpassComm.reconstruct 
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   120
		          (*Proof reconstruction works for only a limited set of 
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   121
		            inference rules*)
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   122
                      then "-" ^ space_implode "%-" (!custom_spass)
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
   123
                      else "-DocProof%-TimeLimit=60%-SOS%-FullRed=0" (*Auto mode*)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   124
                  val _ = debug ("SPASS option string is " ^ optionline)
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   125
                  val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   126
                    (*We've checked that SPASS is there for ATP/spassshell to run.*)
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   127
              in 
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   128
                  ([("spass", goalstring,
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   129
                     getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell",
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   130
                     optionline, probfile)] @ 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   131
                  (make_atp_list xs (n+1)))
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   132
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   133
            else if !prover = "vampire"
17235
8e55ad29b690 Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents: 17234
diff changeset
   134
	    then 
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   135
              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
   136
              in
17435
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   137
                ([("vampire", goalstring, vampire, "-t 60%-m 100000", probfile)] @
0eed5a1c00c1 PARTIAL conversion to Vampire8
paulson
parents: 17422
diff changeset
   138
                 (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
   139
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   140
      	     else if !prover = "E"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   141
      	     then
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   142
	       let val Eprover = ResLib.helper_path "E_HOME" "eproof"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   143
	       in
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   144
		  ([("E", goalstring, Eprover, 
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   145
		     "--tptp-in%-l5%-xAuto%-tAuto%--soft-cpu-limit=60",
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   146
		     probfile)] @
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   147
		   (make_atp_list xs (n+1)))
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   148
	       end
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   149
	     else error ("Invalid prover name: " ^ !prover)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   150
          end
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   151
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   152
    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
   153
  in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   154
    Watcher.callResProvers(childout,atp_list);
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   155
    debug "Sent commands to watcher!"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   156
  end
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   157
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   158
(*We write out problem files for each subgoal, but work is repeated (skolemize)*)
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   159
fun write_problem_files axclauses thm n =
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   160
    if n=0 then ()
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   161
     else
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   162
       (SELECT_GOAL
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
   163
        (EVERY1 [rtac ccontr, ResLib.atomize_tac, skolemize_tac, 
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   164
          METAHYPS(fn negs => 
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   165
            (if !prover = "spass" 
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   166
             then dfg_inputs_tfrees (make_clauses negs) n axclauses
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   167
             else tptp_inputs_tfrees (make_clauses negs) n axclauses;
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   168
             write_problem_files axclauses thm (n-1); 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   169
             all_tac))]) n thm;
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   170
        ());
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   171
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   172
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   173
(******************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   174
(* called in Isar automatically                                   *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   175
(* writes out the current clasimpset to a tptp file               *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   176
(* turns off xsymbol at start of function, restoring it at end    *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   177
(******************************************************************)
15779
aed221aff642 Removed remaining references to Main.thy in reconstruction code.
quigley
parents: 15774
diff changeset
   178
(*FIX changed to clasimp_file *)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   179
val isar_atp' = setmp print_mode [] 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   180
 (fn (ctxt, thms, thm) =>
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   181
  if Thm.no_prems thm then ()
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   182
  else
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   183
    let
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   184
      val _= debug ("in isar_atp'")
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   185
      val thy = ProofContext.theory_of ctxt
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   186
      val prems = Thm.prems_of thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   187
      val thms_string = Meson.concat_with_and (map string_of_thm thms)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   188
      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
   189
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   190
      (*set up variables for writing out the clasimps to a tptp file*)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   191
      val (clause_arr, num_of_clauses, axclauses) =
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
   192
        ResClasimp.get_clasimp_lemmas thy (hd prems) (*FIXME: hack!! need to do all prems*)
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   193
      val _ = debug ("claset and simprules total " ^ (string_of_int num_of_clauses)^
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   194
                  " clauses")
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   195
      val (childin, childout, pid) = 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   196
          Watcher.createWatcher (thm, clause_arr, num_of_clauses)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   197
      val pid_string =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   198
        string_of_int (Word.toInt (Word.fromLargeWord (Posix.Process.pidToWord pid)))
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   199
    in
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   200
      debug ("initial thms: " ^ thms_string);
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   201
      debug ("subgoals: " ^ prems_string);
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   202
      debug ("pid: "^ pid_string);
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   203
      write_problem_files axclauses thm (length prems);
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   204
      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
   205
    end);
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   206
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   207
val isar_atp_writeonly = setmp print_mode [] 
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   208
 (fn (ctxt, thms, thm) =>
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   209
  if Thm.no_prems thm then ()
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   210
  else
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   211
    let
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   212
      val thy = ProofContext.theory_of ctxt
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   213
      val prems = Thm.prems_of thm
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   214
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   215
      (*set up variables for writing out the clasimps to a tptp file*)
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   216
      val (clause_arr, num_of_clauses, axclauses) =
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   217
        ResClasimp.get_clasimp_lemmas thy (hd prems) (*FIXME: hack!! need to do all prems*)
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   218
    in
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   219
      write_problem_files axclauses thm (length prems)
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   220
    end);
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   221
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   222
fun get_thms_cs claset =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   223
  let val {safeEs, safeIs, hazEs, hazIs, ...} = rep_cs claset
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   224
  in safeEs @ safeIs @ hazEs @ hazIs end;
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   225
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   226
fun append_name name [] _ = []
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   227
  | append_name name (thm :: thms) k =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   228
      Thm.name_thm ((name ^ "_" ^ string_of_int k), thm) :: append_name name thms (k + 1);
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   229
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   230
fun append_names (name :: names) (thms :: thmss) =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   231
  append_name name thms 0 :: append_names names thmss;
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   232
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   233
fun get_thms_ss [] = []
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   234
  | get_thms_ss thms =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   235
      let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   236
        val names = map Thm.name_of_thm thms
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   237
        val thms' = map (mksimps mksimps_pairs) thms
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   238
        val thms'' = append_names names thms'
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   239
      in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   240
        ResLib.flat_noDup thms''
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   241
      end;
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   242
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   243
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   244
(* convert locally declared rules to axiom clauses *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   245
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   246
fun subtract_simpset thy ctxt =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   247
  let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   248
    val rules1 = #rules (#1 (rep_ss (simpset_of thy)));
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   249
    val rules2 = #rules (#1 (rep_ss (local_simpset_of ctxt)));
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   250
  in map #thm (Net.subtract MetaSimplifier.eq_rrule rules1 rules2) end;
15679
28eb0fe50533 Integrating the reconstruction files into the building of HOL
quigley
parents: 15657
diff changeset
   251
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   252
fun subtract_claset thy ctxt =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   253
  let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   254
    val (netI1, netE1) = #xtra_netpair (rep_cs (claset_of thy));
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   255
    val (netI2, netE2) = #xtra_netpair (rep_cs (local_claset_of ctxt));
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   256
    val subtract = map (#2 o #2) oo Net.subtract Tactic.eq_kbrl;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   257
  in subtract netI1 netI2 @ subtract netE1 netE2 end;
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   258
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   259
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   260
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   261
(** the Isar toplevel hook **)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   262
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   263
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
   264
  let
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   265
    val proof = Toplevel.proof_of state
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   266
    val (ctxt, (_, goal)) = Proof.get_goal proof
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   267
        handle Proof.STATE _ => error "No goal present";
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   268
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   269
    val thy = ProofContext.theory_of ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   270
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   271
    (* FIXME presently unused *)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   272
    val ss_thms = subtract_simpset thy ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   273
    val cs_thms = subtract_claset thy ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   274
  in
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   275
    debug ("initial thm in isar_atp: " ^ 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   276
           Pretty.string_of (ProofContext.pretty_thm ctxt goal));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   277
    debug ("subgoals in isar_atp: " ^ 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   278
           Pretty.string_of (ProofContext.pretty_term ctxt
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   279
             (Logic.mk_conjunction_list (Thm.prems_of goal))));
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   280
    debug ("number of subgoals in isar_atp: " ^ string_of_int (Thm.nprems_of goal));
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   281
    hook_count := !hook_count +1;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   282
    debug ("in hook for time: " ^(string_of_int (!hook_count)) );
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
   283
    ResClause.init thy;
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   284
    isar_atp' (ctxt, ProofContext.prems_of ctxt, goal)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   285
  end);
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   286
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   287
val call_atpP =
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   288
  OuterSyntax.improper_command 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   289
    "ProofGeneral.call_atp" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   290
    "call automatic theorem provers" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   291
    OuterKeyword.diag
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   292
    (Scan.succeed (Toplevel.no_timing o invoke_atp));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   293
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   294
val _ = OuterSyntax.add_parsers [call_atpP];
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   295
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   296
end;