src/HOL/Tools/res_atp.ML
author mengj
Thu, 09 Mar 2006 06:05:01 +0100
changeset 19227 d15f2baa7ecc
parent 19205 4ec788c69f82
child 19352 1a07f6cf1e6c
permissions -rw-r--r--
Added more functions to the signature and tidied up some functions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
     1
(*  Author: Jia Meng, Cambridge University Computer Laboratory, NICTA
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
     2
    ID: $Id$
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
     3
    Copyright 2004 University of Cambridge
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     4
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     5
ATPs with TPTP format input.
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     6
*)
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
     7
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
     8
signature RES_ATP =
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
     9
sig
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
    10
  val prover: string ref
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
    11
  val custom_spass: string list ref
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    12
  val destdir: string ref
17849
d7619ccf22e6 signature changes
paulson
parents: 17845
diff changeset
    13
  val helper_path: string -> string -> string
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    14
  val problem_name: string ref
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
    15
  val time_limit: int ref
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    16
   
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    17
  datatype mode = Auto | Fol | Hol
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
    18
  val write_subgoal_file: mode -> Proof.context -> thm list -> thm list -> int -> string
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    19
  val vampire_time: int ref
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    20
  val eprover_time: int ref
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    21
  val run_vampire: int -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    22
  val run_eprover: int -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    23
  val vampireLimit: unit -> int
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    24
  val eproverLimit: unit -> int
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
    25
  val atp_method: (ProofContext.context -> thm list -> int -> Tactical.tactic) ->
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    26
		  Method.src -> ProofContext.context -> Method.method
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    27
  val cond_rm_tmp: string -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    28
  val keep_atp_input: bool ref
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    29
  val fol_keep_types: bool ref
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    30
  val hol_full_types: unit -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    31
  val hol_partial_types: unit -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    32
  val hol_const_types_only: unit -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    33
  val hol_no_types: unit -> unit
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    34
  val hol_typ_level: unit -> ResHolClause.type_level
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    35
  val run_relevance_filter: bool ref
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
    36
  val invoke_atp_ml : ProofContext.context * thm -> unit
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    37
  val add_claset : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    38
  val add_simpset : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    39
  val add_clasimp : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    40
  val add_atpset : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    41
  val rm_claset : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    42
  val rm_simpset : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    43
  val rm_atpset : unit -> unit
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
    44
  val rm_clasimp : unit -> unit
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    45
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    46
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
    47
structure ResAtp : RES_ATP =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    48
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    49
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    50
(********************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    51
(* some settings for both background automatic ATP calling procedure*)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    52
(* and also explicit ATP invocation methods                         *)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    53
(********************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    54
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    55
(*** background linkup ***)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    56
val call_atp = ref false; 
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
    57
val hook_count = ref 0;
18675
333a73034023 more practical time limit
paulson
parents: 18404
diff changeset
    58
val time_limit = ref 30;
17404
d16c3a62c396 the experimental tagging system, and the usual tidying
paulson
parents: 17317
diff changeset
    59
val prover = ref "E";   (* use E as the default prover *)
17305
6cef3aedd661 axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents: 17235
diff changeset
    60
val custom_spass =   (*specialized options for SPASS*)
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
    61
      ref ["-Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub"];
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    62
val destdir = ref "";   (*Empty means write files to /tmp*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    63
val problem_name = ref "prob";
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    64
17819
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    65
(*Return the path to a "helper" like SPASS or tptp2X, first checking that
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    66
  it exists.  FIXME: modify to use Path primitives and move to some central place.*)  
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    67
fun helper_path evar base =
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    68
  case getenv evar of
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    69
      "" => error  ("Isabelle environment variable " ^ evar ^ " not defined")
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    70
    | home => 
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    71
        let val path = home ^ "/" ^ base
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    72
        in  if File.exists (File.unpack_platform_path path) then path 
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    73
	    else error ("Could not find the file " ^ path)
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    74
	end;  
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
    75
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    76
fun probfile_nosuffix _ = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    77
  if !destdir = "" then File.platform_path (File.tmp_path (Path.basic (!problem_name)))
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    78
  else if File.exists (File.unpack_platform_path (!destdir))
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    79
  then !destdir ^ "/" ^ !problem_name
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
    80
  else error ("No such directory: " ^ !destdir);
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
    81
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    82
fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n;
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
    83
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    84
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    85
(*** ATP methods ***)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    86
val vampire_time = ref 60;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    87
val eprover_time = ref 60;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    88
fun run_vampire time =  
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    89
    if (time >0) then vampire_time:= time
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    90
    else vampire_time:=60;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    91
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    92
fun run_eprover time = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    93
    if (time > 0) then eprover_time:= time
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    94
    else eprover_time:=60;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    95
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    96
fun vampireLimit () = !vampire_time;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    97
fun eproverLimit () = !eprover_time;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    98
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
    99
val keep_atp_input = ref false;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   100
val fol_keep_types = ResClause.keep_types;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   101
val hol_full_types = ResHolClause.full_types;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   102
val hol_partial_types = ResHolClause.partial_types;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   103
val hol_const_types_only = ResHolClause.const_types_only;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   104
val hol_no_types = ResHolClause.no_types;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   105
fun hol_typ_level () = ResHolClause.find_typ_level ();
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   106
fun is_typed_hol () = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   107
    let val tp_level = hol_typ_level()
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   108
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   109
	not (tp_level = ResHolClause.T_NONE)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   110
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   111
val include_combS = ResHolClause.include_combS;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   112
val include_min_comb = ResHolClause.include_min_comb;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   113
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   114
fun atp_input_file () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   115
    let val file = !problem_name 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   116
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   117
	if !destdir = "" then File.platform_path (File.tmp_path (Path.basic file))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   118
	else if File.exists (File.unpack_platform_path (!destdir))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   119
	then !destdir ^ "/" ^ file
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   120
	else error ("No such directory: " ^ !destdir)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   121
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   122
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   123
val include_simpset = ref false;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   124
val include_claset = ref false; 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   125
val include_atpset = ref true;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   126
val add_simpset = (fn () => include_simpset:=true);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   127
val add_claset = (fn () => include_claset:=true);
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   128
val add_clasimp = (fn () => (include_simpset:=true;include_claset:=true));
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   129
val add_atpset = (fn () => include_atpset:=true);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   130
val rm_simpset = (fn () => include_simpset:=false);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   131
val rm_claset = (fn () => include_claset:=false);
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   132
val rm_clasimp = (fn () => (include_simpset:=false;include_claset:=false));
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   133
val rm_atpset = (fn () => include_atpset:=false);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   134
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   135
(*** paths for HOL helper files ***)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   136
fun full_typed_comb_inclS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   137
    helper_path "E_HOME" "additionals/full_comb_inclS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   138
    handle _ => helper_path "VAMPIRE_HOME" "additionals/full_comb_inclS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   139
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   140
fun full_typed_comb_noS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   141
    helper_path "E_HOME" "additionals/full_comb_noS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   142
    handle _ => helper_path "VAMPIRE_HOME" "additionals/full_comb_noS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   143
									      
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   144
fun partial_typed_comb_inclS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   145
    helper_path "E_HOME" "additionals/par_comb_inclS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   146
    handle _ => helper_path "VAMPIRE_HOME" "additionals/par_comb_inclS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   147
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   148
fun partial_typed_comb_noS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   149
    helper_path "E_HOME" "additionals/par_comb_noS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   150
    handle _ => helper_path "VAMPIRE_HOME" "additionals/par_comb_noS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   151
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   152
fun const_typed_comb_inclS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   153
    helper_path "E_HOME" "additionals/const_comb_inclS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   154
    handle _ => helper_path "VAMPIRE_HOME" "additionals/const_comb_inclS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   155
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   156
fun const_typed_comb_noS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   157
    helper_path "E_HOME" "additionals/const_comb_noS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   158
    handle _ => helper_path "VAMPIRE_HOME" "additionals/const_comb_noS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   159
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   160
fun untyped_comb_inclS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   161
    helper_path "E_HOME" "additionals/u_comb_inclS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   162
    handle _ => helper_path "VAMPIRE_HOME" "additionals/u_comb_inclS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   163
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   164
fun untyped_comb_noS () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   165
    helper_path "E_HOME" "additionals/u_comb_noS"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   166
    handle _ => helper_path "VAMPIRE_HOME" "additionals/u_comb_noS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   167
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   168
fun full_typed_HOL_helper1 () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   169
    helper_path "E_HOME" "additionals/full_helper1"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   170
    handle _ => helper_path "VAMPIRE_HOME" "additionals/full_helper1";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   171
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   172
fun partial_typed_HOL_helper1 () = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   173
    helper_path "E_HOME" "additionals/par_helper1"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   174
    handle _ => helper_path "VAMPIRE_HOME" "additionals/par_helper1";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   175
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   176
fun const_typed_HOL_helper1 () = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   177
    helper_path "E_HOME" "additionals/const_helper1"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   178
    handle _ => helper_path "VAMPIRE_HOME" "additionals/const_helper1";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   179
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   180
fun untyped_HOL_helper1 () = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   181
    helper_path "E_HOME" "additionals/u_helper1"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   182
    handle _ => helper_path "VAMPIRE_HOME" "additionals/u_helper1";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   183
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   184
fun get_full_typed_helpers () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   185
    (full_typed_HOL_helper1 (), full_typed_comb_noS (), full_typed_comb_inclS ());
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   186
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   187
fun get_partial_typed_helpers () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   188
    (partial_typed_HOL_helper1 (), partial_typed_comb_noS (), partial_typed_comb_inclS ());
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   189
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   190
fun get_const_typed_helpers () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   191
    (const_typed_HOL_helper1 (), const_typed_comb_noS (), const_typed_comb_inclS ());
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   192
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   193
fun get_untyped_helpers () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   194
    (untyped_HOL_helper1 (), untyped_comb_noS (), untyped_comb_inclS ());
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   195
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   196
fun get_all_helpers () =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   197
    (get_full_typed_helpers (), get_partial_typed_helpers (), get_const_typed_helpers (), get_untyped_helpers ());
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   198
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   199
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   200
(**** relevance filter ****)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   201
val run_relevance_filter = ref true;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   202
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   203
(******************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   204
(* detect whether a given problem (clauses) is FOL/HOL/HOLC/HOLCS *)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   205
(******************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   206
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   207
datatype logic = FOL | HOL | HOLC | HOLCS;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   208
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   209
fun string_of_logic FOL = "FOL"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   210
  | string_of_logic HOL = "HOL"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   211
  | string_of_logic HOLC = "HOLC"
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   212
  | string_of_logic HOLCS = "HOLCS";
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   213
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   214
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   215
fun is_fol_logic FOL = true
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   216
  | is_fol_logic  _ = false
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   217
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   218
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   219
(*HOLCS will not occur here*)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   220
fun upgrade_lg HOLC _ = HOLC
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   221
  | upgrade_lg HOL HOLC = HOLC
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   222
  | upgrade_lg HOL _ = HOL
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   223
  | upgrade_lg FOL lg = lg; 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   224
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   225
(* check types *)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   226
fun has_bool (Type("bool",_)) = true
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   227
  | has_bool (Type(_, Ts)) = exists has_bool Ts
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   228
  | has_bool _ = false;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   229
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   230
fun has_bool_arg tp = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   231
    let val (targs,tr) = strip_type tp
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   232
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   233
	exists has_bool targs
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   234
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   235
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   236
fun is_fn_tp (Type("fun",_)) = true
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   237
  | is_fn_tp _ = false;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   238
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   239
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   240
exception FN_LG of term;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   241
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   242
fun fn_lg (t as Const(f,tp)) (lg,seen) = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   243
    if has_bool tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   244
  | fn_lg (t as Free(f,tp)) (lg,seen) = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   245
    if has_bool tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   246
  | fn_lg (t as Var(f,tp)) (lg,seen) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   247
    if is_fn_tp tp orelse has_bool tp then (upgrade_lg HOL lg,t ins seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   248
    else (lg,t ins seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   249
  | fn_lg (t as Abs(_,_,_)) (lg,seen) = (upgrade_lg HOLC lg,t ins seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   250
  | fn_lg f _ = raise FN_LG(f); 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   251
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   252
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   253
fun term_lg [] (lg,seen) = (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   254
  | term_lg (tm::tms) (FOL,seen) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   255
    let val (f,args) = strip_comb tm
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   256
	val (lg',seen') = if f mem seen then (FOL,seen) 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   257
			  else fn_lg f (FOL,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   258
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   259
	 in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   260
	     term_lg (args@tms) (lg',seen')
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   261
    end
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   262
  | term_lg _ (lg,seen) = (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   263
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   264
exception PRED_LG of term;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   265
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   266
fun pred_lg (t as Const(P,tp)) (lg,seen)= 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   267
    if has_bool_arg tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen) 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   268
  | pred_lg (t as Free(P,tp)) (lg,seen) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   269
    if has_bool_arg tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   270
  | pred_lg (t as Var(_,_)) (lg,seen) = (upgrade_lg HOL lg, t ins seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   271
  | pred_lg P _ = raise PRED_LG(P);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   272
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   273
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   274
fun lit_lg (Const("Not",_) $ P) (lg,seen) = lit_lg P (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   275
  | lit_lg P (lg,seen) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   276
    let val (pred,args) = strip_comb P
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   277
	val (lg',seen') = if pred mem seen then (lg,seen) 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   278
			  else pred_lg pred (lg,seen)
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   279
	val _ = if is_fol_logic lg' then () else warning ("Found a HOL predicate: " ^ (Term.str_of_term pred))
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   280
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   281
	term_lg args (lg',seen')
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   282
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   283
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   284
fun lits_lg [] (lg,seen) = (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   285
  | lits_lg (lit::lits) (FOL,seen) =
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   286
    let val (lg,seen') = lit_lg lit (FOL,seen)
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   287
	val _ =  if is_fol_logic lg then () else warning ("Found a HOL literal: " ^ (Term.str_of_term lit))
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   288
    in
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   289
	lits_lg lits (lg,seen')
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   290
    end
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   291
  | lits_lg lits (lg,seen) = (lg,seen);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   292
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   293
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   294
fun dest_disj_aux (Const ("op |", _) $ t $ t') disjs = 
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   295
    dest_disj_aux t (dest_disj_aux t' disjs)
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   296
  | dest_disj_aux t disjs = t::disjs;
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   297
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   298
fun dest_disj t = dest_disj_aux t [];
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   299
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   300
fun logic_of_clause tm (lg,seen) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   301
    let val tm' = HOLogic.dest_Trueprop tm
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   302
	val disjs = dest_disj tm'
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   303
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   304
	lits_lg disjs (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   305
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   306
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   307
fun logic_of_clauses [] (lg,seen) = (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   308
  | logic_of_clauses (cls::clss) (FOL,seen) =
19227
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   309
    let val (lg,seen') = logic_of_clause cls (FOL,seen)
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   310
	val _ = if is_fol_logic lg then () else warning ("Found a HOL clause: " ^ (Term.str_of_term cls))
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   311
    in
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   312
	logic_of_clauses clss (lg,seen')
d15f2baa7ecc Added more functions to the signature and tidied up some functions.
mengj
parents: 19205
diff changeset
   313
    end
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   314
  | logic_of_clauses (cls::clss) (lg,seen) = (lg,seen);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   315
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   316
fun logic_of_nclauses [] (lg,seen) = (lg,seen)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   317
  | logic_of_nclauses (cls::clss) (FOL,seen) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   318
    logic_of_nclauses clss (logic_of_clauses (snd cls) (FOL,seen))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   319
  | logic_of_nclauses clss (lg,seen) = (lg,seen);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   320
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   321
fun problem_logic (goal_cls,rules_cls) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   322
    let val (lg1,seen1) = logic_of_clauses goal_cls (FOL,[])
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   323
	val (lg2,seen2) = logic_of_nclauses rules_cls (lg1,seen1)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   324
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   325
	lg2
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   326
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   327
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   328
fun problem_logic_goals_aux [] (lg,seen) = lg
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   329
  | problem_logic_goals_aux (subgoal::subgoals) (lg,seen) = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   330
    problem_logic_goals_aux subgoals (logic_of_clauses subgoal (lg,seen));
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   331
    
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   332
fun problem_logic_goals subgoals = problem_logic_goals_aux subgoals (FOL,[]);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   333
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   334
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   335
(***************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   336
(* ATP invocation methods setup                                *)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   337
(***************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   338
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   339
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   340
(**** prover-specific format: TPTP ****)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   341
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   342
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   343
fun cnf_hyps_thms ctxt = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   344
    let val ths = ProofContext.prems_of ctxt
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   345
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   346
	ResClause.union_all (map ResAxioms.skolem_thm ths)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   347
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   348
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   349
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   350
(**** write to files ****)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   351
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   352
datatype mode = Auto | Fol | Hol;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   353
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   354
val linkup_logic_mode = ref Fol;
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   355
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   356
fun tptp_writer logic goals filename (axioms,classrels,arities) =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   357
    if is_fol_logic logic then ResClause.tptp_write_file goals filename (axioms, classrels, arities)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   358
    else
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   359
	ResHolClause.tptp_write_file goals filename (axioms, classrels, arities) (get_all_helpers());
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   360
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   361
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   362
fun write_subgoal_file mode ctxt conjectures user_thms n =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   363
    let val conj_cls = map prop_of (make_clauses conjectures) 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   364
	val hyp_cls = map prop_of (cnf_hyps_thms ctxt)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   365
	val goal_cls = conj_cls@hyp_cls
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   366
	val user_rules = map ResAxioms.pairname user_thms
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   367
	val (names_arr,axclauses_as_tms) = ResClasimp.get_clasimp_atp_lemmas ctxt (goal_cls) user_rules (!include_claset,!include_simpset,!include_atpset) (!run_relevance_filter)  
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   368
	val thy = ProofContext.theory_of ctxt
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   369
	val prob_logic = case mode of Auto => problem_logic_goals [goal_cls]
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   370
				    | Fol => FOL
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   371
				    | Hol => HOL
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   372
	val keep_types = if is_fol_logic prob_logic then !fol_keep_types else is_typed_hol ()
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   373
	val classrel_clauses = if keep_types then ResClause.classrel_clauses_thy thy else []
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   374
	val arity_clauses = if keep_types then ResClause.arity_clause_thy thy else []
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   375
	val writer = tptp_writer
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   376
	val file = atp_input_file()
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   377
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   378
	(writer prob_logic goal_cls file (axclauses_as_tms,classrel_clauses,arity_clauses);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   379
	 warning ("Writing to " ^ file);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   380
	 file)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   381
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   382
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   383
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   384
(**** remove tmp files ****)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   385
fun cond_rm_tmp file = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   386
    if !keep_atp_input then warning "ATP input kept..." 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   387
    else if !destdir <> "" then warning ("ATP input kept in directory " ^ (!destdir))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   388
    else (warning "deleting ATP inputs..."; OS.FileSys.remove file);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   389
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   390
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   391
(****** setup ATPs as Isabelle methods ******)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   392
fun atp_meth' tac ths ctxt = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   393
    Method.SIMPLE_METHOD' HEADGOAL
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   394
    (tac ctxt ths);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   395
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   396
fun atp_meth tac ths ctxt = 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   397
    let val thy = ProofContext.theory_of ctxt
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   398
	val _ = ResClause.init thy
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   399
	val _ = ResHolClause.init thy
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   400
    in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   401
	atp_meth' tac ths ctxt
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   402
    end;
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   403
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   404
fun atp_method tac = Method.thms_ctxt_args (atp_meth tac);
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   405
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   406
(***************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   407
(* automatic ATP invocation                                    *)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   408
(***************************************************************)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   409
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   410
(* call prover with settings and problem file for the current subgoal *)
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   411
fun watcher_call_provers sign sg_terms (childin, childout, pid) =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   412
  let
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   413
    fun make_atp_list [] n = []
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   414
      | make_atp_list (sg_term::xs) n =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   415
          let
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   416
            val probfile = prob_pathname n
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   417
            val time = Int.toString (!time_limit)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   418
          in
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   419
            Output.debug ("problem file in watcher_call_provers is " ^ probfile);
17317
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
   420
            (*Avoid command arguments containing spaces: Poly/ML and SML/NJ
3f12de2e2e6e Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents: 17306
diff changeset
   421
              versions of Unix.execute treat them differently!*)
17764
fde495b9e24b improved process handling. tidied
paulson
parents: 17746
diff changeset
   422
            (*options are separated by Watcher.setting_sep, currently #"%"*)
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   423
            if !prover = "spass"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   424
            then
18700
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   425
              let val baseopts = "%-PGiven=0%-PProblem=0%-Splits=0%-FullRed=0%-DocProof%-TimeLimit=" ^ time
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   426
              val infopts = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   427
		      if !AtpCommunication.reconstruct 
18700
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   428
		          (*Proof reconstruction needs a limited set of inf rules*)
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   429
                      then space_implode "%" (!custom_spass)                           
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   430
                      else "-Auto%-SOS=1"
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   431
                  val spass = helper_path "SPASS_HOME" "SPASS"
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   432
            in 
f04a8755d6ca improved SPASS support
paulson
parents: 18680
diff changeset
   433
                ([("spass", spass, infopts ^ baseopts, probfile)] @ 
18798
ca02a2077955 tidying up SPASS output
paulson
parents: 18753
diff changeset
   434
                  make_atp_list xs (n+1))
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   435
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   436
            else if !prover = "vampire"
17235
8e55ad29b690 Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents: 17234
diff changeset
   437
	    then 
17819
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
   438
              let val vampire = helper_path "VAMPIRE_HOME" "vampire"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   439
              in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   440
                ([("vampire", vampire, "-m 100000%-t " ^ time, probfile)] @
18798
ca02a2077955 tidying up SPASS output
paulson
parents: 18753
diff changeset
   441
                 make_atp_list xs (n+1))       (*BEWARE! spaces in options!*)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   442
              end
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   443
      	     else if !prover = "E"
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   444
      	     then
17819
1241e5d31d5b small tidy-up of utility functions
paulson
parents: 17775
diff changeset
   445
	       let val Eprover = helper_path "E_HOME" "eproof"
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   446
	       in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   447
		  ([("E", Eprover, 
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   448
		     "--tptp-in%-l5%-xAuto%-tAuto%--cpu-limit=" ^ time,
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   449
		     probfile)] @
18798
ca02a2077955 tidying up SPASS output
paulson
parents: 18753
diff changeset
   450
		   make_atp_list xs (n+1))
17306
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   451
	       end
5cde710a8a23 Progress on eprover linkup, also massive tidying
paulson
parents: 17305
diff changeset
   452
	     else error ("Invalid prover name: " ^ !prover)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   453
          end
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   454
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   455
    val atp_list = make_atp_list sg_terms 1
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   456
  in
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   457
    Watcher.callResProvers(childout,atp_list);
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   458
    Output.debug "Sent commands to watcher!"
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   459
  end
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   460
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   461
(*We write out problem files for each subgoal. Argument pf generates filenames,
18986
5060ca625e02 tidying
paulson
parents: 18863
diff changeset
   462
  and allows the suppression of the suffix "_1" in problem-generation mode.
5060ca625e02 tidying
paulson
parents: 18863
diff changeset
   463
  FIXME: does not cope with &&, and it isn't easy because one could have multiple
5060ca625e02 tidying
paulson
parents: 18863
diff changeset
   464
  subgoals, each involving &&.*)
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   465
fun write_problem_files pf (ctxt,th)  =
18753
aa82bd41555d ResClasimp.get_clasimp_lemmas now takes all subgoals rather than only the first
paulson
parents: 18700
diff changeset
   466
  let val goals = Thm.prems_of th
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   467
      val _ = Output.debug ("number of subgoals = " ^ Int.toString (length goals))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   468
      val (names_arr, axclauses_as_terms) = ResClasimp.get_clasimp_atp_lemmas ctxt goals [] (true,true,true) (!run_relevance_filter) (* no user supplied rules here, because no user invocation *)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   469
      val _ = Output.debug ("claset, simprules and atprules total clauses = " ^ 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   470
                     Int.toString (Array.length names_arr))
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   471
      val thy = ProofContext.theory_of ctxt
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   472
      fun get_neg_subgoals n =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   473
	  if n=0 then []
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   474
	  else
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   475
	      let val st = Seq.hd (EVERY'
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   476
				       [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac] n th)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   477
		  val negs = Option.valOf (metahyps_thms n st)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   478
		  val negs_clauses = map prop_of (make_clauses negs)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   479
	      in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   480
		  negs_clauses::(get_neg_subgoals (n - 1))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   481
	      end
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   482
      val neg_subgoals = get_neg_subgoals (length goals) 
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   483
      val goals_logic = case !linkup_logic_mode of Auto => problem_logic_goals neg_subgoals
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   484
						 | Fol => FOL
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   485
						 | Hol => HOL
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   486
      val keep_types = if is_fol_logic goals_logic then !ResClause.keep_types else is_typed_hol ()
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   487
      val classrel_clauses = if keep_types then ResClause.classrel_clauses_thy thy else []
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   488
      val _ = Output.debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   489
      val arity_clauses = if keep_types then ResClause.arity_clause_thy thy else []
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   490
      val _ = Output.debug ("arity clauses = " ^ Int.toString (length arity_clauses))
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   491
      val writer = (*if !prover ~= "spass" then *)tptp_writer 
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   492
      fun write_all [] _ = []
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   493
	| write_all (subgoal::subgoals) k =
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   494
	  (writer goals_logic subgoal (pf k) (axclauses_as_terms,classrel_clauses,arity_clauses); pf k):: (write_all subgoals (k - 1))
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   495
  in
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   496
      (write_all neg_subgoals (length goals), names_arr)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   497
  end;
15644
f2ef8c258fa4 *** empty log message ***
quigley
parents: 15608
diff changeset
   498
17775
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   499
val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream * 
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   500
                                    Posix.Process.pid * string list) option);
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   501
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   502
fun kill_last_watcher () =
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   503
    (case !last_watcher_pid of 
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   504
         NONE => ()
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   505
       | SOME (_, childout, pid, files) => 
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   506
	  (Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid);
17775
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   507
	   Watcher.killWatcher pid;  
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   508
	   ignore (map (try OS.FileSys.remove) files)))
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   509
     handle OS.SysErr _ => Output.debug "Attempt to kill watcher failed";
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   510
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   511
(*writes out the current clasimpset to a tptp file;
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17502
diff changeset
   512
  turns off xsymbol at start of function, restoring it at end    *)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents: 17435
diff changeset
   513
val isar_atp = setmp print_mode [] 
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   514
 (fn (ctxt, th) =>
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   515
  if Thm.no_prems th then ()
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   516
  else
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   517
    let
17775
2679ba74411f minor code tidyig
paulson
parents: 17773
diff changeset
   518
      val _ = kill_last_watcher()
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   519
      val (files,names_arr) = write_problem_files prob_pathname (ctxt,th)
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   520
      val (childin, childout, pid) = Watcher.createWatcher (th, names_arr)
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   521
    in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17764
diff changeset
   522
      last_watcher_pid := SOME (childin, childout, pid, files);
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   523
      Output.debug ("problem files: " ^ space_implode ", " files); 
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   524
      Output.debug ("pid: " ^ string_of_pid pid);
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   525
      watcher_call_provers (sign_of_thm th) (Thm.prems_of th) (childin, childout, pid)
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   526
    end);
15608
f161fa6f8fd5 bug fixes involving typechecking clauses
paulson
parents: 15603
diff changeset
   527
17422
3b237822985d massive tidy-up and simplification
paulson
parents: 17404
diff changeset
   528
val isar_atp_writeonly = setmp print_mode [] 
17717
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   529
      (fn (ctxt,th) =>
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   530
       if Thm.no_prems th then ()
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   531
       else 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   532
         let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix 
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   533
         	      else prob_pathname
7c6a96cbc966 improvements for problem generation
paulson
parents: 17690
diff changeset
   534
         in ignore (write_problem_files pf (ctxt,th)) end);
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
   535
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   536
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   537
(** the Isar toplevel hook **)
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   538
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   539
fun invoke_atp_ml (ctxt, goal) =
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   540
  let val thy = ProofContext.theory_of ctxt;
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
   541
  in
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   542
    Output.debug ("subgoals in isar_atp:\n" ^ 
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   543
		  Pretty.string_of (ProofContext.pretty_term ctxt
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   544
		    (Logic.mk_conjunction_list (Thm.prems_of goal))));
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   545
    Output.debug ("current theory: " ^ Context.theory_name thy);
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 17091
diff changeset
   546
    hook_count := !hook_count +1;
18680
677e2bdd75f0 Output.debug;
wenzelm
parents: 18675
diff changeset
   547
    Output.debug ("in hook for time: " ^ Int.toString (!hook_count));
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16904
diff changeset
   548
    ResClause.init thy;
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   549
    ResHolClause.init thy;
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17525
diff changeset
   550
    if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal)
17502
8836793df947 further tidying; killing of old Watcher loops
paulson
parents: 17488
diff changeset
   551
    else isar_atp_writeonly (ctxt, goal)
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   552
  end;
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   553
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   554
val invoke_atp = Toplevel.no_timing o Toplevel.unknown_proof o Toplevel.keep
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   555
 (fn state =>
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   556
  let val (ctxt, (_, goal)) = Proof.get_goal (Toplevel.proof_of state)
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   557
  in  invoke_atp_ml (ctxt, goal)  end);
16357
f1275d2a1dee All subgoals sent to the watcher at once now.
quigley
parents: 16259
diff changeset
   558
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   559
val call_atpP =
17746
af59c748371d fixed the ascii-armouring of goalstring
paulson
parents: 17717
diff changeset
   560
  OuterSyntax.command 
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   561
    "ProofGeneral.call_atp" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   562
    "call automatic theorem provers" 
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   563
    OuterKeyword.diag
19205
4ec788c69f82 Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents: 19194
diff changeset
   564
    (Scan.succeed invoke_atp);
17091
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   565
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   566
val _ = OuterSyntax.add_parsers [call_atpP];
13593aa6a546 new command to invoke ATPs
paulson
parents: 16955
diff changeset
   567
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   568
end;