src/HOL/Tools/res_atp.ML
author paulson
Fri, 02 Sep 2005 15:25:44 +0200
changeset 17231 f42bc4f7afdf
parent 17150 ce2a1aeb42aa
child 17234 12a9393c5d77
permissions -rw-r--r--
tidying up the Isabelle/ATP interface
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
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    10
  val axiom_file : Path.T
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    11
  val hyps_file : Path.T
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    12
  val prob_file : Path.T;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    13
(*val atp_ax_tac : thm list -> int -> Tactical.tactic*)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    14
(*val atp_tac : int -> Tactical.tactic*)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    15
  val full_spass: bool ref
16478
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    16
(*val spass: bool ref*)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    17
  val vampire: bool ref
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    18
  val custom_spass: string list ref
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    19
  val hook_count: int ref
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    20
(*  val invoke_atp: Toplevel.transition -> Toplevel.transition*)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    21
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    22
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    23
structure ResAtp: RES_ATP =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    24
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    25
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    26
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    27
val call_atp = ref false;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    28
val hook_count = ref 0;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    29
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
    30
fun debug_tac tac = (debug "testing"; tac);
16478
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    31
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
    32
val full_spass = ref false;
16478
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    33
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    34
(* use spass as default prover *)
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    35
(*val spass = ref true;*)
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    36
16520
7a9cda53bfa2 Integrated vampire lemma code.
quigley
parents: 16515
diff changeset
    37
val custom_spass = ref ["Auto=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub","-DocProof","-TimeLimit=60"];
16478
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    38
val vampire = ref false;
d0a1f6231e2f Added VampCommunication.ML.
quigley
parents: 16475
diff changeset
    39
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    40
val skolem_tac = skolemize_tac;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    41
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    42
val num_of_clauses = ref 0;
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    43
val clause_arr = Array.array (3500, ("empty", 0));
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    44
15347
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
val atomize_tac =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    47
    SUBGOAL
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    48
     (fn (prop,_) =>
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    49
         let val ts = Logic.strip_assums_hyp prop
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    50
         in EVERY1
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    51
                [METAHYPS
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    52
                     (fn hyps => (cut_facts_tac (map (ObjectLogic.atomize_thm o forall_intr_vars) hyps) 1)),
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    53
          REPEAT_DETERM_N (length ts) o (etac thin_rl)]
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    54
     end);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    55
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    56
(* temporarily use these files, which will be loaded by Vampire *)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    57
val file_id_num = ref 0;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    58
fun new_prob_file () = "prob" ^ string_of_int (inc file_id_num);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    59
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    60
val axiom_file = File.tmp_path (Path.basic "axioms");
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    61
val clasimp_file = File.tmp_path (Path.basic "clasimp");
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    62
val hyps_file = File.tmp_path (Path.basic "hyps");
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    63
val prob_file = File.tmp_path (Path.basic "prob");
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    64
val dummy_tac = all_tac;
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    65
val _ =debug  (File.platform_path prob_file);
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    66
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    67
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    68
(**** for Isabelle/ML interface  ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    69
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    70
(*Remove unwanted characters such as ? and newline from the textural 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    71
  representation of a theorem (surely they don't need to be produced in 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    72
  the first place?) *)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    73
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    74
fun is_proof_char ch = (#" " <= ch andalso ch <= #"~" andalso ch <> #"?");
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    75
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    76
val proofstring =
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
    77
    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
    78
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
    79
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    80
(**** For running in Isar ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    81
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    82
(* same function as that in res_axioms.ML *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    83
fun repeat_RS thm1 thm2 =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    84
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    85
    in
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    86
        if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    87
    end;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    88
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    89
(* a special version of repeat_RS *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    90
fun repeat_someI_ex thm = repeat_RS thm someI_ex;
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    91
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
    92
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
    93
(*FIXME: is function isar_atp_h used? If not, delete!*)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    94
(*********************************************************************)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    95
(* convert clauses from "assume" to conjecture. write to file "hyps" *)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    96
(* hypotheses of the goal currently being proved                     *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    97
(*********************************************************************)
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
    98
(*perhaps have 2 different versions of this, depending on whether or not SpassComm.spass is set *)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
    99
fun isar_atp_h thms =
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   100
    let val prems = map (skolemize o make_nnf o ObjectLogic.atomize_thm) thms
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   101
        val prems' = map repeat_someI_ex prems
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   102
        val prems'' = make_clauses prems'
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   103
        val prems''' = ResAxioms.rm_Eps [] prems''
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   104
        val clss = map ResClause.make_conjecture_clause prems'''
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15736
diff changeset
   105
	val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss) 
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   106
	val tfree_lits = ResLib.flat_noDup tfree_litss
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   107
        (* tfree clause is different in tptp and dfg versions *)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   108
	val tfree_clss = map ResClause.tfree_clause tfree_lits 
16259
aed1a8ae4b23 File.platform_path;
wenzelm
parents: 16185
diff changeset
   109
        val hypsfile = File.platform_path hyps_file
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   110
        val out = TextIO.openOut(hypsfile)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   111
    in
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   112
        ResLib.writeln_strs out (tfree_clss @ tptp_clss);
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   113
        TextIO.closeOut out; debug hypsfile;
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   114
        tfree_lits
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   115
    end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   116
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   117
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   118
(*********************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   119
(* write out a subgoal as tptp clauses to the file "probN"           *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   120
(* where N is the number of this subgoal                             *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   121
(*********************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   122
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   123
fun tptp_inputs_tfrees thms n tfrees =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   124
    let
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   125
      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
   126
      val clss = map (ResClause.make_conjecture_clause_thm) thms
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   127
      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
   128
      val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   129
      val _ = debug ("in tptp_inputs_tfrees 2")
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   130
      val tfree_clss = map ResClause.tfree_clause ((ResLib.flat_noDup tfree_litss) \\ tfrees)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   131
      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
   132
      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
   133
      val out = TextIO.openOut(probfile)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   134
    in
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   135
      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
   136
      TextIO.closeOut out;
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   137
      debug probfile
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   138
    end;
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   139
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   140
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   141
(*********************************************************************)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   142
(* write out a subgoal as DFG clauses to the file "probN"           *)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   143
(* where N is the number of this subgoal                             *)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   144
(*********************************************************************)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   145
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   146
fun dfg_inputs_tfrees thms n tfrees axclauses = 
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   147
    let val clss = map (ResClause.make_conjecture_clause_thm) thms
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   148
        val probfile = (File.platform_path prob_file) ^ "_" ^ (string_of_int n)
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   149
        val _ = debug ("about to write out dfg prob file " ^ probfile)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   150
       	(*val (dfg_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2dfg clss)
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   151
        val tfree_clss = map ResClause.tfree_dfg_clause ((ResLib.flat_noDup tfree_litss) \\ tfrees) *)   
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   152
        val filestr = ResClause.clauses2dfg clss ("prob" ^ (string_of_int n)) 
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   153
                        axclauses [] [] [] tfrees   
16767
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   154
	val out = TextIO.openOut(probfile)
2d4433759b8d Fixed some problems with the signal handler.
quigley
parents: 16741
diff changeset
   155
    in
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   156
	(ResLib.writeln_strs out [filestr]; TextIO.closeOut out; debug probfile )
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   157
(* (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
   158
    end;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   159
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   160
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   161
(*********************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   162
(* call SPASS with settings and problem file for the current subgoal *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   163
(* should be modified to allow other provers to be called            *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   164
(*********************************************************************)
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   165
(* now passing in list of skolemized thms and list of sgterms to go with them *)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   166
fun call_resolve_tac  (thms: thm list list)  sign (sg_terms:  term list) (childin, childout,pid) n  =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   167
  let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   168
    val axfile = (File.platform_path axiom_file)
16520
7a9cda53bfa2 Integrated vampire lemma code.
quigley
parents: 16515
diff changeset
   169
7a9cda53bfa2 Integrated vampire lemma code.
quigley
parents: 16515
diff changeset
   170
    val hypsfile = (File.platform_path hyps_file)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   171
    val clasimpfile = (File.platform_path clasimp_file)
16520
7a9cda53bfa2 Integrated vampire lemma code.
quigley
parents: 16515
diff changeset
   172
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   173
    fun make_atp_list [] sign n = []
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   174
      | make_atp_list ((sko_thm, sg_term)::xs) sign n =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   175
          let
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   176
            val thmstr = proofstring (Meson.concat_with_and (map string_of_thm sko_thm))
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   177
            val _ = debug ("thmstring in make_atp_lists is " ^ thmstr)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   178
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   179
            val goalstring = proofstring (Sign.string_of_term sign sg_term)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   180
            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
   181
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   182
            val probfile = File.platform_path prob_file ^ "_" ^ (string_of_int n)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   183
            val _ = debug ("prob file in call_resolve_tac is " ^ probfile)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   184
          in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   185
            if !SpassComm.spass
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   186
            then
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   187
              let val optionline = (*Custom SPASS options, or default?*)
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   188
		      if !full_spass (*Auto mode: all SPASS inference rules*)
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   189
                      then "-DocProof%-TimeLimit=60%-SOS"
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   190
                      else "-" ^ space_implode "%-" (!custom_spass)
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   191
                  val _ = debug ("SPASS option string is " ^ optionline)
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   192
                  val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   193
                    (*We've checked that SPASS is there for ATP/spassshell to run.*)
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   194
              in 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   195
                  ([("spass", thmstr, goalstring,
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   196
                     getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell",
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   197
                     optionline, clasimpfile, axfile, hypsfile, probfile)] @ 
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   198
                  (make_atp_list xs sign (n+1)))
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   199
              end
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   200
            else
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   201
              let val vampire = ResLib.helper_path "VAMPIRE_HOME" "vkernel"
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   202
              in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   203
                ([("vampire", thmstr, goalstring, vampire, "-t 60%-m 100000",
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   204
                   clasimpfile, axfile, hypsfile, probfile)] @
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   205
                 (make_atp_list xs sign (n+1)))
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   206
              end
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   207
          end
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   208
16897
7e5319d0f418 code streamlining
paulson
parents: 16802
diff changeset
   209
    val atp_list = make_atp_list (ListPair.zip (thms, sg_terms)) sign 1
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   210
  in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   211
    Watcher.callResProvers(childout,atp_list);
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   212
    debug "Sent commands to watcher!";
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   213
    dummy_tac
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   214
  end
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   215
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   216
(**********************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   217
(* write out the current subgoal as a tptp file, probN,   *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   218
(* then call dummy_tac - should be call_res_tac           *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   219
(**********************************************************)
15679
28eb0fe50533 Integrating the reconstruction files into the building of HOL
quigley
parents: 15657
diff changeset
   220
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   221
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   222
fun get_sko_thms tfrees sign sg_terms (childin, childout,pid) thm n sko_thms axclauses =
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   223
    if n=0 then 
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   224
       (call_resolve_tac  (rev sko_thms)
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   225
        sign  sg_terms (childin, childout, pid) (List.length sg_terms);
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   226
        dummy_tac thm)
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   227
     else
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   228
	
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   229
     ( SELECT_GOAL
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   230
        (EVERY1 [rtac ccontr,atomize_tac, skolemize_tac, 
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   231
          METAHYPS(fn negs => 
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   232
            (if !SpassComm.spass 
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   233
             then dfg_inputs_tfrees (make_clauses negs) n tfrees axclauses
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   234
             else tptp_inputs_tfrees (make_clauses negs) n tfrees;
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   235
             get_sko_thms tfrees sign sg_terms (childin, childout, pid) 
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   236
                          thm  (n -1) (negs::sko_thms) axclauses; 
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   237
             dummy_tac))]) n thm )
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   238
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   239
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   240
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   241
(**********************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   242
(* recursively call atp_tac_g on all subgoals *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   243
(* sg_term is the nth subgoal as a term - used*)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   244
(* in proof reconstruction                    *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   245
(**********************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   246
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   247
fun isar_atp_goal' thm n tfree_lits (childin, childout, pid)  axclauses =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   248
  let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   249
    val prems = Thm.prems_of thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   250
    (*val sg_term = get_nth k prems*)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   251
    val sign = sign_of_thm thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   252
    val thmstring = string_of_thm thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   253
  in
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   254
    debug("in isar_atp_goal'");
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   255
    debug("thmstring in isar_atp_goal': " ^ thmstring);
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   256
    (* go and call callResProvers with this subgoal *)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   257
    (* isar_atp_g tfree_lits  sg_term (childin, childout, pid) k thm; *)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   258
    (* recursive call to pick up the remaining subgoals *)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   259
    (* isar_atp_goal' thm (k+1) n tfree_lits  (childin, childout, pid) *)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   260
    get_sko_thms tfree_lits sign prems (childin, childout, pid) thm n []  axclauses
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   261
  end;
16520
7a9cda53bfa2 Integrated vampire lemma code.
quigley
parents: 16515
diff changeset
   262
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   263
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   264
(**************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   265
(* convert clauses from "assume" to conjecture.   *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   266
(* i.e. apply make_clauses and then get tptp for  *)
15679
28eb0fe50533 Integrating the reconstruction files into the building of HOL
quigley
parents: 15657
diff changeset
   267
(* any hypotheses in the goal produced by assume  *)
28eb0fe50533 Integrating the reconstruction files into the building of HOL
quigley
parents: 15657
diff changeset
   268
(* statements;                                    *)
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   269
(* write to file "hyps"                           *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   270
(**************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   271
17231
f42bc4f7afdf tidying up the Isabelle/ATP interface
paulson
parents: 17150
diff changeset
   272
fun isar_atp_aux thms thm n_subgoals  (childin, childout, pid) axclauses =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   273
  let val tfree_lits = isar_atp_h thms
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   274
  in
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   275
    debug ("in isar_atp_aux");
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   276
    isar_atp_goal' thm n_subgoals tfree_lits (childin, childout, pid)  axclauses
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   277
  end;
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   278
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   279
(******************************************************************)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   280
(* called in Isar automatically                                   *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   281
(* writes out the current clasimpset to a tptp file               *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   282
(* passes all subgoals on to isar_atp_aux for further processing  *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   283
(* turns off xsymbol at start of function, restoring it at end    *)
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   284
(******************************************************************)
15779
aed221aff642 Removed remaining references to Main.thy in reconstruction code.
quigley
parents: 15774
diff changeset
   285
(*FIX changed to clasimp_file *)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   286
val isar_atp' = setmp print_mode [] (fn (ctxt, thms, thm) =>
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   287
  if Thm.no_prems thm then ()
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   288
  else
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   289
    let
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   290
      val _= debug ("in isar_atp'")
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   291
      val thy = ProofContext.theory_of ctxt
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   292
      val prems = Thm.prems_of thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   293
      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
   294
      val thm_string = string_of_thm thm
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   295
      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
   296
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   297
      (*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
   298
      val (clause_arr, num_of_clauses, axclauses) =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   299
        ResClasimp.write_out_clasimp (File.platform_path clasimp_file) thy
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   300
          (hd prems) (*FIXME: hack!! need to do all prems*)
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   301
      val _ = debug ("clasimp_file is " ^ File.platform_path clasimp_file ^ " with " ^ (string_of_int num_of_clauses)^ " clauses")
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   302
      val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr, num_of_clauses)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   303
      val pid_string =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   304
        string_of_int (Word.toInt (Word.fromLargeWord (Posix.Process.pidToWord pid)))
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   305
    in
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   306
      debug ("initial thms: " ^ thms_string);
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   307
      debug ("initial thm: " ^ thm_string);
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   308
      debug ("subgoals: " ^ prems_string);
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   309
      debug ("pid: "^ pid_string);
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   310
      isar_atp_aux thms thm (length prems) (childin, childout, pid) axclauses;
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   311
      ()
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   312
    end);
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   313
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   314
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   315
fun get_thms_cs claset =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   316
  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
   317
  in safeEs @ safeIs @ hazEs @ hazIs end;
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   318
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   319
fun append_name name [] _ = []
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   320
  | append_name name (thm :: thms) k =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   321
      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
   322
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   323
fun append_names (name :: names) (thms :: thmss) =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   324
  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
   325
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   326
fun get_thms_ss [] = []
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   327
  | get_thms_ss thms =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   328
      let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   329
        val names = map Thm.name_of_thm thms
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   330
        val thms' = map (mksimps mksimps_pairs) thms
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   331
        val thms'' = append_names names thms'
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   332
      in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   333
        ResLib.flat_noDup thms''
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   334
      end;
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   335
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   336
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   337
(* convert locally declared rules to axiom clauses *)
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   338
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   339
fun subtract_simpset thy ctxt =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   340
  let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   341
    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
   342
    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
   343
  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
   344
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   345
fun subtract_claset thy ctxt =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   346
  let
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   347
    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
   348
    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
   349
    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
   350
  in subtract netI1 netI2 @ subtract netE1 netE2 end;
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   351
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   352
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   353
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   354
(** the Isar toplevel hook **)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   355
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   356
val invoke_atp = Toplevel.unknown_proof o Toplevel.keep (fn state =>
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   357
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   358
  let
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   359
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   360
    val proof = Toplevel.proof_of state
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   361
    val (ctxt, (_, goal)) = Proof.get_goal proof
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   362
        handle Proof.STATE _ => error "No goal present";
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   363
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   364
    val thy = ProofContext.theory_of ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   365
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   366
    (* FIXME presently unused *)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   367
    val ss_thms = subtract_simpset thy ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   368
    val cs_thms = subtract_claset thy ctxt;
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   369
  in
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   370
    debug ("initial thm in isar_atp: " ^ 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   371
           Pretty.string_of (ProofContext.pretty_thm ctxt goal));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   372
    debug ("subgoals in isar_atp: " ^ 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   373
           Pretty.string_of (ProofContext.pretty_term ctxt
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   374
             (Logic.mk_conjunction_list (Thm.prems_of goal))));
16904
6fb188ca5f91 tidied up the tracing output
paulson
parents: 16897
diff changeset
   375
    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
   376
    hook_count := !hook_count +1;
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   377
    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
   378
    ResClause.init thy;
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   379
    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
   380
  end);
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   381
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   382
val call_atpP =
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   383
  OuterSyntax.improper_command 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   384
    "ProofGeneral.call_atp" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   385
    "call automatic theorem provers" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   386
    OuterKeyword.diag
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   387
    (Scan.succeed (Toplevel.no_timing o invoke_atp));
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   388
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   389
val _ = OuterSyntax.add_parsers [call_atpP];
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   390
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   391
end;