src/HOL/Tools/res_atp.ML
author wenzelm
Wed Jul 13 16:07:23 2005 +0200 (2005-07-13 ago)
changeset 16802 6eeee59dac4c
parent 16767 2d4433759b8d
child 16897 7e5319d0f418
permissions -rw-r--r--
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
added call_atp: bool ref;
do 'setmp print_mode []', which is more robust than manual ref manipulation;
added subtract_simpset, subtract_claset (supercede delta approximation);
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 call_atp: bool ref
wenzelm@16802
    11
  val trace_res : bool ref
wenzelm@16802
    12
  val traceflag : bool ref
wenzelm@16802
    13
  val axiom_file : Path.T
wenzelm@16802
    14
  val hyps_file : Path.T
wenzelm@16802
    15
  val prob_file : Path.T;
wenzelm@16802
    16
(*val atp_ax_tac : thm list -> int -> Tactical.tactic*)
quigley@15644
    17
(*val atp_tac : int -> Tactical.tactic*)
wenzelm@16802
    18
  val debug: bool ref
wenzelm@16802
    19
  val full_spass: bool ref
quigley@16478
    20
(*val spass: bool ref*)
wenzelm@16802
    21
  val vampire: bool ref
wenzelm@16802
    22
  val custom_spass: string list ref
paulson@15347
    23
end;
paulson@15347
    24
wenzelm@16802
    25
structure ResAtp: RES_ATP =
paulson@15347
    26
struct
paulson@15347
    27
wenzelm@16802
    28
val call_atp = ref false;
quigley@15644
    29
quigley@15779
    30
val traceflag = ref true;
quigley@16357
    31
val debug = ref false;
paulson@16172
    32
wenzelm@16802
    33
fun debug_tac tac = (warning "testing"; tac);
quigley@16478
    34
quigley@16357
    35
val full_spass = ref false;
quigley@16478
    36
quigley@16478
    37
(* use spass as default prover *)
quigley@16478
    38
(*val spass = ref true;*)
quigley@16478
    39
quigley@16520
    40
val custom_spass = ref ["Auto=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub","-DocProof","-TimeLimit=60"];
quigley@16478
    41
val vampire = ref false;
quigley@16478
    42
paulson@15608
    43
val trace_res = ref false;
paulson@15347
    44
paulson@15608
    45
val skolem_tac = skolemize_tac;
paulson@15608
    46
quigley@15644
    47
val num_of_clauses = ref 0;
wenzelm@16802
    48
val clause_arr = Array.array (3500, ("empty", 0));
quigley@15644
    49
paulson@15347
    50
paulson@15608
    51
val atomize_tac =
paulson@15608
    52
    SUBGOAL
paulson@15608
    53
     (fn (prop,_) =>
wenzelm@16802
    54
         let val ts = Logic.strip_assums_hyp prop
wenzelm@16802
    55
         in EVERY1
wenzelm@16802
    56
                [METAHYPS
wenzelm@16802
    57
                     (fn hyps => (cut_facts_tac (map (ObjectLogic.atomize_thm o forall_intr_vars) hyps) 1)),
wenzelm@16802
    58
          REPEAT_DETERM_N (length ts) o (etac thin_rl)]
paulson@15608
    59
     end);
paulson@15347
    60
paulson@15608
    61
(* temporarily use these files, which will be loaded by Vampire *)
wenzelm@16802
    62
val file_id_num = ref 0;
wenzelm@16802
    63
fun new_prob_file () = "prob" ^ string_of_int (inc file_id_num);
paulson@15347
    64
quigley@15644
    65
val axiom_file = File.tmp_path (Path.basic "axioms");
quigley@15644
    66
val clasimp_file = File.tmp_path (Path.basic "clasimp");
quigley@15644
    67
val hyps_file = File.tmp_path (Path.basic "hyps");
quigley@15644
    68
val prob_file = File.tmp_path (Path.basic "prob");
wenzelm@16802
    69
val dummy_tac = all_tac;
quigley@15644
    70
wenzelm@16802
    71
paulson@15347
    72
(**** for Isabelle/ML interface  ****)
paulson@15347
    73
wenzelm@16802
    74
fun is_proof_char ch =
wenzelm@16802
    75
  (33 <= ord ch andalso ord ch <= 126 andalso ord ch <> 63)
wenzelm@16802
    76
  orelse ch = " ";
paulson@15608
    77
wenzelm@16802
    78
val proofstring = List.filter is_proof_char o explode;
paulson@15608
    79
paulson@15452
    80
quigley@15644
    81
(*
quigley@15644
    82
fun call_atp_tac thms n = (tptp_inputs thms ; dummy_tac);
paulson@15347
    83
quigley@15644
    84
*)
paulson@15347
    85
paulson@15347
    86
(**** For running in Isar ****)
paulson@15347
    87
paulson@15608
    88
(* same function as that in res_axioms.ML *)
paulson@15608
    89
fun repeat_RS thm1 thm2 =
paulson@15608
    90
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
paulson@15608
    91
    in
wenzelm@16802
    92
        if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
paulson@15608
    93
    end;
paulson@15608
    94
paulson@15608
    95
(* a special version of repeat_RS *)
paulson@15608
    96
fun repeat_someI_ex thm = repeat_RS thm someI_ex;
paulson@15608
    97
quigley@15644
    98
(*********************************************************************)
paulson@15608
    99
(* convert clauses from "assume" to conjecture. write to file "hyps" *)
quigley@15644
   100
(* hypotheses of the goal currently being proved                     *)
quigley@15644
   101
(*********************************************************************)
quigley@16767
   102
(*perhaps have 2 different versions of this, depending on whether or not SpassComm.spass is set *)
paulson@15608
   103
fun isar_atp_h thms =
paulson@15608
   104
    let val prems = map (skolemize o make_nnf o ObjectLogic.atomize_thm) thms
quigley@15644
   105
        val prems' = map repeat_someI_ex prems
quigley@15644
   106
        val prems'' = make_clauses prems'
quigley@15644
   107
        val prems''' = ResAxioms.rm_Eps [] prems''
quigley@15644
   108
        val clss = map ResClause.make_conjecture_clause prems'''
paulson@15774
   109
	val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss) 
paulson@15608
   110
	val tfree_lits = ResLib.flat_noDup tfree_litss
quigley@16767
   111
        (* tfree clause is different in tptp and dfg versions *)
paulson@15608
   112
	val tfree_clss = map ResClause.tfree_clause tfree_lits 
wenzelm@16259
   113
        val hypsfile = File.platform_path hyps_file
wenzelm@16802
   114
        val out = TextIO.openOut(hypsfile)
paulson@15608
   115
    in
wenzelm@16802
   116
      (ResLib.writeln_strs out (tfree_clss @ tptp_clss);
wenzelm@16802
   117
        TextIO.closeOut out; if !trace_res then (warning hypsfile) else ());
wenzelm@16802
   118
      tfree_lits
paulson@15608
   119
    end;
paulson@15347
   120
quigley@15644
   121
quigley@15644
   122
(*********************************************************************)
quigley@15644
   123
(* write out a subgoal as tptp clauses to the file "probN"           *)
quigley@15644
   124
(* where N is the number of this subgoal                             *)
quigley@15644
   125
(*********************************************************************)
quigley@15644
   126
wenzelm@16802
   127
fun tptp_inputs_tfrees thms n tfrees =
wenzelm@16802
   128
    let
wenzelm@16802
   129
      val _ = warning ("in tptp_inputs_tfrees 0")
wenzelm@16802
   130
      val clss = map (ResClause.make_conjecture_clause_thm) thms
wenzelm@16802
   131
      val _ = warning ("in tptp_inputs_tfrees 1")
wenzelm@16802
   132
      val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss)
wenzelm@16802
   133
      val _ = warning ("in tptp_inputs_tfrees 2")
wenzelm@16802
   134
      val tfree_clss = map ResClause.tfree_clause ((ResLib.flat_noDup tfree_litss) \\ tfrees)
wenzelm@16802
   135
      val _ = warning ("in tptp_inputs_tfrees 3")
wenzelm@16802
   136
      val probfile = File.platform_path prob_file ^ "_" ^ string_of_int n
wenzelm@16802
   137
      val out = TextIO.openOut(probfile)
paulson@15608
   138
    in
wenzelm@16802
   139
      ResLib.writeln_strs out (tfree_clss @ tptp_clss);
wenzelm@16802
   140
      TextIO.closeOut out;
wenzelm@16802
   141
      if !trace_res then (warning probfile) else ()
paulson@15608
   142
    end;
paulson@15452
   143
paulson@15608
   144
quigley@16767
   145
(*********************************************************************)
quigley@16767
   146
(* write out a subgoal as DFG clauses to the file "probN"           *)
quigley@16767
   147
(* where N is the number of this subgoal                             *)
quigley@16767
   148
(*********************************************************************)
quigley@16767
   149
(*
quigley@16767
   150
fun dfg_inputs_tfrees thms n tfrees = 
quigley@16767
   151
    let val _ = (warning ("in dfg_inputs_tfrees 0"))
quigley@16767
   152
        val clss = map (ResClause.make_conjecture_clause_thm) thms
quigley@16767
   153
         val _ = (warning ("in dfg_inputs_tfrees 1"))
quigley@16767
   154
	val (dfg_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2dfg clss)
quigley@16767
   155
        val _ = (warning ("in dfg_inputs_tfrees 2"))
quigley@16767
   156
	val tfree_clss = map ResClause.tfree_clause ((ResLib.flat_noDup tfree_litss) \\ tfrees) 
quigley@16767
   157
         val _ = (warning ("in dfg_inputs_tfrees 3"))
quigley@16767
   158
        val probfile = (File.platform_path prob_file) ^ "_" ^ (string_of_int n)
quigley@16767
   159
	val out = TextIO.openOut(probfile)
quigley@16767
   160
    in
quigley@16767
   161
	(ResLib.writeln_strs out (tfree_clss @ dfg_clss); TextIO.closeOut out; (if !trace_res then (warning probfile) else ()))
quigley@16767
   162
    end;*)
quigley@16357
   163
quigley@15644
   164
(*********************************************************************)
quigley@15644
   165
(* call SPASS with settings and problem file for the current subgoal *)
quigley@15644
   166
(* should be modified to allow other provers to be called            *)
quigley@15644
   167
(*********************************************************************)
quigley@16357
   168
(* now passing in list of skolemized thms and list of sgterms to go with them *)
wenzelm@16802
   169
fun call_resolve_tac  (thms: thm list list)  sign (sg_terms:  term list) (childin, childout,pid) n  =
wenzelm@16802
   170
  let
wenzelm@16802
   171
    val axfile = (File.platform_path axiom_file)
quigley@16520
   172
quigley@16520
   173
    val hypsfile = (File.platform_path hyps_file)
wenzelm@16802
   174
    val clasimpfile = (File.platform_path clasimp_file)
quigley@16520
   175
wenzelm@16802
   176
    fun make_atp_list [] sign n = []
wenzelm@16802
   177
      | make_atp_list ((sko_thm, sg_term)::xs) sign  n =
wenzelm@16802
   178
          let
wenzelm@16802
   179
            val skothmstr = Meson.concat_with_and (map string_of_thm sko_thm)
wenzelm@16802
   180
            val thmproofstr = proofstring ( skothmstr)
wenzelm@16802
   181
            val no_returns = filter_out (equal "\n") thmproofstr
wenzelm@16802
   182
            val thmstr = implode no_returns
wenzelm@16802
   183
            val _ = warning ("thmstring in make_atp_lists is: "^thmstr)
paulson@15608
   184
wenzelm@16802
   185
            val sgstr = Sign.string_of_term sign sg_term
wenzelm@16802
   186
            val goalproofstring = proofstring sgstr
wenzelm@16802
   187
            val no_returns = filter_out (equal "\n") goalproofstring
wenzelm@16802
   188
            val goalstring = implode no_returns
wenzelm@16802
   189
            val _ = warning ("goalstring in make_atp_lists is: "^goalstring)
quigley@16357
   190
wenzelm@16802
   191
            val probfile = (File.platform_path prob_file) ^ "_" ^ (string_of_int n)
quigley@16520
   192
wenzelm@16802
   193
            val _ = (warning ("prob file in cal_res_tac is: "^probfile))
wenzelm@16802
   194
          in
wenzelm@16802
   195
            if !SpassComm.spass
wenzelm@16802
   196
            then
wenzelm@16802
   197
              let val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
wenzelm@16802
   198
              in  (*We've checked that SPASS is there for ATP/spassshell to run.*)
wenzelm@16802
   199
                if !full_spass
wenzelm@16802
   200
                then (*Allow SPASS to run in Auto mode, using all its inference rules*)
wenzelm@16802
   201
                  ([("spass", thmstr, goalstring (*,spass_home*),
quigley@16520
   202
wenzelm@16802
   203
                     getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell"(*( getenv "SPASS_HOME")^"/SPASS"*),
wenzelm@16802
   204
                     "-DocProof%-TimeLimit=60%-SOS",
wenzelm@16802
   205
                     
wenzelm@16802
   206
                     clasimpfile, axfile, hypsfile, probfile)]@(make_atp_list xs sign (n+1)))
wenzelm@16802
   207
                else (*Restrict SPASS to a small set of rules that we can parse*)
wenzelm@16802
   208
                  ([("spass", thmstr, goalstring (*,spass_home*),
wenzelm@16802
   209
                     getenv "ISABELLE_HOME" ^"/src/HOL/Tools/ATP/spassshell"(* (getenv "SPASS_HOME")^"/SPASS"*),
wenzelm@16802
   210
                     ("-" ^ space_implode "%-" (!custom_spass)),
wenzelm@16802
   211
                     clasimpfile, axfile, hypsfile, probfile)]@(make_atp_list xs sign (n+1)))
wenzelm@16802
   212
              end
wenzelm@16802
   213
            else
wenzelm@16802
   214
              let val vampire = ResLib.helper_path "VAMPIRE_HOME" "vkernel"
wenzelm@16802
   215
              in
wenzelm@16802
   216
                ([("vampire", thmstr, goalstring, vampire, "-t 60%-m 100000",
wenzelm@16802
   217
                   clasimpfile, axfile, hypsfile, probfile)] @
wenzelm@16802
   218
                 (make_atp_list xs sign (n+1)))
wenzelm@16802
   219
              end
wenzelm@16802
   220
          end
paulson@15452
   221
wenzelm@16802
   222
    val thms_goals = ListPair.zip( thms, sg_terms)
wenzelm@16802
   223
    val atp_list = make_atp_list  thms_goals sign 1
wenzelm@16802
   224
  in
wenzelm@16802
   225
    Watcher.callResProvers(childout,atp_list);
wenzelm@16802
   226
    warning "Sent commands to watcher!";
wenzelm@16802
   227
    dummy_tac
wenzelm@16802
   228
  end
quigley@16357
   229
quigley@15644
   230
(**********************************************************)
quigley@15644
   231
(* write out the current subgoal as a tptp file, probN,   *)
quigley@15644
   232
(* then call dummy_tac - should be call_res_tac           *)
quigley@15644
   233
(**********************************************************)
quigley@15679
   234
wenzelm@16802
   235
fun get_sko_thms tfrees sign sg_terms (childin, childout, pid) thm n sko_thms =
wenzelm@16802
   236
  if n = 0 then
wenzelm@16802
   237
    (call_resolve_tac (rev sko_thms)
wenzelm@16802
   238
      sign sg_terms (childin, childout, pid) (List.length sg_terms);
wenzelm@16802
   239
     dummy_tac thm)
wenzelm@16802
   240
  else
wenzelm@16802
   241
    SELECT_GOAL
wenzelm@16802
   242
      (EVERY1 [rtac ccontr, atomize_tac, skolemize_tac,
wenzelm@16802
   243
        METAHYPS (fn negs =>
wenzelm@16802
   244
          (tptp_inputs_tfrees (make_clauses negs) n tfrees;
wenzelm@16802
   245
           get_sko_thms tfrees sign sg_terms (childin, childout, pid) thm (n - 1)
wenzelm@16802
   246
             (negs::sko_thms); dummy_tac))]) n thm;
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
wenzelm@16802
   255
fun isar_atp_goal' thm n tfree_lits (childin, childout, pid) =
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
wenzelm@16802
   262
    warning("in isar_atp_goal'");
wenzelm@16802
   263
    warning("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) *)
wenzelm@16802
   268
    get_sko_thms tfree_lits sign prems (childin, childout, pid) thm n []
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
wenzelm@16802
   280
fun isar_atp_aux thms thm n_subgoals  (childin, childout, pid) =
wenzelm@16802
   281
  let val tfree_lits = isar_atp_h thms
wenzelm@16802
   282
  in
wenzelm@16802
   283
    warning ("in isar_atp_aux");
wenzelm@16802
   284
    isar_atp_goal' thm n_subgoals tfree_lits (childin, childout, pid)
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
wenzelm@16802
   298
      val _= warning ("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*)
wenzelm@16802
   306
      val (clause_arr, num_of_clauses) =
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*)
wenzelm@16802
   309
      val _ = warning ("clasimp_file is " ^ File.platform_path clasimp_file)
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
wenzelm@16802
   314
      warning ("initial thms: " ^ thms_string);
wenzelm@16802
   315
      warning ("initial thm: " ^ thm_string);
wenzelm@16802
   316
      warning ("subgoals: " ^ prems_string);
wenzelm@16802
   317
      warning ("pid: "^ pid_string);
wenzelm@16802
   318
      isar_atp_aux thms thm (length prems) (childin, childout, pid);
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
(* write axiom clauses to ax_file *)
quigley@15644
   347
(* what about clasimpset - it should already be in the ax file - perhaps append to ax file rather than just *)
quigley@15644
   348
(* write out ? Or keep as a separate file and then cat them all together in the watcher, like we do with the *)
quigley@15644
   349
(*claset file and prob file*)
quigley@16357
   350
(* FIX*)
quigley@16039
   351
(*fun isar_local_thms (delta_cs, delta_ss_thms) =
paulson@15608
   352
    let val thms_cs = get_thms_cs delta_cs
wenzelm@16802
   353
        val thms_ss = get_thms_ss delta_ss_thms
wenzelm@16802
   354
        val thms_clauses = ResLib.flat_noDup (map ResAxioms.clausify_axiom (thms_cs @ thms_ss))
wenzelm@16802
   355
        val clauses_strs = ResLib.flat_noDup (map ResClause.tptp_clause thms_clauses) (*string list*)
wenzelm@16802
   356
        val ax_file = File.platform_path axiom_file
wenzelm@16802
   357
        val out = TextIO.openOut ax_file
paulson@15608
   358
    in
wenzelm@16802
   359
        (ResLib.writeln_strs out clauses_strs; (warning ("axiom file is: "^ax_file));TextIO.closeOut out)
paulson@15608
   360
    end;
quigley@16039
   361
*)
paulson@15608
   362
paulson@15608
   363
wenzelm@16802
   364
fun subtract_simpset thy ctxt =
wenzelm@16802
   365
  let
wenzelm@16802
   366
    val rules1 = #rules (#1 (rep_ss (simpset_of thy)));
wenzelm@16802
   367
    val rules2 = #rules (#1 (rep_ss (local_simpset_of ctxt)));
wenzelm@16802
   368
  in map #thm (Net.subtract MetaSimplifier.eq_rrule rules1 rules2) end;
quigley@15679
   369
wenzelm@16802
   370
fun subtract_claset thy ctxt =
wenzelm@16802
   371
  let
wenzelm@16802
   372
    val (netI1, netE1) = #xtra_netpair (rep_cs (claset_of thy));
wenzelm@16802
   373
    val (netI2, netE2) = #xtra_netpair (rep_cs (local_claset_of ctxt));
wenzelm@16802
   374
    val subtract = map (#2 o #2) oo Net.subtract Tactic.eq_kbrl;
wenzelm@16802
   375
  in subtract netI1 netI2 @ subtract netE1 netE2 end;
paulson@15608
   376
paulson@15608
   377
quigley@16357
   378
wenzelm@16802
   379
(** the Isar toplevel hook **)
wenzelm@16802
   380
wenzelm@16802
   381
val _ = Toplevel.print_state_hook (fn _ => fn state =>
wenzelm@16802
   382
  let
wenzelm@16802
   383
    val _ = if ! call_atp then () else raise Toplevel.UNDEF;
wenzelm@16802
   384
    val prf =
wenzelm@16802
   385
      (case Toplevel.node_of state of Toplevel.Proof prf => prf | _ => raise Toplevel.UNDEF);
wenzelm@16802
   386
    val _ = Proof.assert_backward (the (ProofHistory.previous prf));
wenzelm@16802
   387
    val proof = Proof.assert_forward (ProofHistory.current prf);
wenzelm@16802
   388
    val (ctxt, (_, goal)) = Proof.get_goal proof;
wenzelm@16802
   389
wenzelm@16802
   390
    val thy = ProofContext.theory_of ctxt;
wenzelm@16802
   391
    val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) (Thm.prems_of goal));
wenzelm@16802
   392
wenzelm@16802
   393
    (* FIXME presently unused *)
wenzelm@16802
   394
    val ss_thms = subtract_simpset thy ctxt;
wenzelm@16802
   395
    val cs_thms = subtract_claset thy ctxt;
wenzelm@16802
   396
  in
wenzelm@16802
   397
    warning ("initial thm in isar_atp: " ^ string_of_thm goal);
wenzelm@16802
   398
    warning ("subgoals in isar_atp: " ^ prems_string);
wenzelm@16802
   399
    warning ("number of subgoals in isar_atp: " ^ string_of_int (Thm.nprems_of goal));
wenzelm@16802
   400
    (*isar_local_thms (d_cs,d_ss_thms);*)
wenzelm@16802
   401
    isar_atp' (ctxt, ProofContext.prems_of ctxt, goal)
wenzelm@16802
   402
  end);
quigley@16357
   403
paulson@15347
   404
end;