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