src/HOL/Tools/res_atp.ML
changeset 21588 cd0dc678a205
parent 21563 b4718f2c15f0
child 21690 552d20ff9a95
     1.1 --- a/src/HOL/Tools/res_atp.ML	Wed Nov 29 15:44:46 2006 +0100
     1.2 +++ b/src/HOL/Tools/res_atp.ML	Wed Nov 29 15:44:51 2006 +0100
     1.3 @@ -15,7 +15,7 @@
     1.4    val problem_name: string ref
     1.5    val time_limit: int ref
     1.6    val set_prover: string -> unit
     1.7 -   
     1.8 +
     1.9    datatype mode = Auto | Fol | Hol
    1.10    val linkup_logic_mode : mode ref
    1.11    val write_subgoal_file: bool -> mode -> Proof.context -> thm list -> thm list -> int -> string
    1.12 @@ -65,22 +65,22 @@
    1.13  (********************************************************************)
    1.14  
    1.15  (*** background linkup ***)
    1.16 -val call_atp = ref false; 
    1.17 +val call_atp = ref false;
    1.18  val hook_count = ref 0;
    1.19  val time_limit = ref 60;
    1.20 -val prover = ref "";   
    1.21 +val prover = ref "";
    1.22  
    1.23 -fun set_prover atp = 
    1.24 +fun set_prover atp =
    1.25    case String.map Char.toLower atp of
    1.26 -      "e" => 
    1.27 +      "e" =>
    1.28            (ReduceAxiomsN.max_new := 100;
    1.29             ReduceAxiomsN.theory_const := false;
    1.30             prover := "E")
    1.31 -    | "spass" => 
    1.32 +    | "spass" =>
    1.33            (ReduceAxiomsN.max_new := 40;
    1.34             ReduceAxiomsN.theory_const := true;
    1.35             prover := "spass")
    1.36 -    | "vampire" => 
    1.37 +    | "vampire" =>
    1.38            (ReduceAxiomsN.max_new := 60;
    1.39             ReduceAxiomsN.theory_const := false;
    1.40             prover := "vampire")
    1.41 @@ -94,17 +94,17 @@
    1.42  val problem_name = ref "prob";
    1.43  
    1.44  (*Return the path to a "helper" like SPASS or tptp2X, first checking that
    1.45 -  it exists.  FIXME: modify to use Path primitives and move to some central place.*)  
    1.46 +  it exists.  FIXME: modify to use Path primitives and move to some central place.*)
    1.47  fun helper_path evar base =
    1.48    case getenv evar of
    1.49        "" => error  ("Isabelle environment variable " ^ evar ^ " not defined")
    1.50 -    | home => 
    1.51 +    | home =>
    1.52          let val path = home ^ "/" ^ base
    1.53 -        in  if File.exists (File.unpack_platform_path path) then path 
    1.54 -	    else error ("Could not find the file " ^ path)
    1.55 -	end;  
    1.56 +        in  if File.exists (File.unpack_platform_path path) then path
    1.57 +            else error ("Could not find the file " ^ path)
    1.58 +        end;
    1.59  
    1.60 -fun probfile_nosuffix _ = 
    1.61 +fun probfile_nosuffix _ =
    1.62    if !destdir = "" then File.platform_path (File.tmp_path (Path.basic (!problem_name)))
    1.63    else if File.exists (File.unpack_platform_path (!destdir))
    1.64    then !destdir ^ "/" ^ !problem_name
    1.65 @@ -118,15 +118,15 @@
    1.66  val eprover_time = ref 60;
    1.67  val spass_time = ref 60;
    1.68  
    1.69 -fun run_vampire time =  
    1.70 +fun run_vampire time =
    1.71      if (time >0) then vampire_time:= time
    1.72      else vampire_time:=60;
    1.73  
    1.74 -fun run_eprover time = 
    1.75 +fun run_eprover time =
    1.76      if (time > 0) then eprover_time:= time
    1.77      else eprover_time:=60;
    1.78  
    1.79 -fun run_spass time = 
    1.80 +fun run_spass time =
    1.81      if (time > 0) then spass_time:=time
    1.82      else spass_time:=60;
    1.83  
    1.84 @@ -141,24 +141,24 @@
    1.85  val hol_const_types_only = ResHolClause.const_types_only;
    1.86  val hol_no_types = ResHolClause.no_types;
    1.87  fun hol_typ_level () = ResHolClause.find_typ_level ();
    1.88 -fun is_typed_hol () = 
    1.89 +fun is_typed_hol () =
    1.90      let val tp_level = hol_typ_level()
    1.91      in
    1.92 -	not (tp_level = ResHolClause.T_NONE)
    1.93 +        not (tp_level = ResHolClause.T_NONE)
    1.94      end;
    1.95  
    1.96  fun atp_input_file () =
    1.97 -    let val file = !problem_name 
    1.98 +    let val file = !problem_name
    1.99      in
   1.100 -	if !destdir = "" then File.platform_path (File.tmp_path (Path.basic file))
   1.101 -	else if File.exists (File.unpack_platform_path (!destdir))
   1.102 -	then !destdir ^ "/" ^ file
   1.103 -	else error ("No such directory: " ^ !destdir)
   1.104 +        if !destdir = "" then File.platform_path (File.tmp_path (Path.basic file))
   1.105 +        else if File.exists (File.unpack_platform_path (!destdir))
   1.106 +        then !destdir ^ "/" ^ file
   1.107 +        else error ("No such directory: " ^ !destdir)
   1.108      end;
   1.109  
   1.110  val include_all = ref true;
   1.111  val include_simpset = ref false;
   1.112 -val include_claset = ref false; 
   1.113 +val include_claset = ref false;
   1.114  val include_atpset = ref true;
   1.115  
   1.116  (*Tests show that follow_defs gives VERY poor results with "include_all"*)
   1.117 @@ -200,7 +200,7 @@
   1.118  fun upgrade_lg HOLC _ = HOLC
   1.119    | upgrade_lg HOL HOLC = HOLC
   1.120    | upgrade_lg HOL _ = HOL
   1.121 -  | upgrade_lg FOL lg = lg; 
   1.122 +  | upgrade_lg FOL lg = lg;
   1.123  
   1.124  (* check types *)
   1.125  fun has_bool_hfn (Type("bool",_)) = true
   1.126 @@ -211,34 +211,34 @@
   1.127  fun is_hol_fn tp =
   1.128      let val (targs,tr) = strip_type tp
   1.129      in
   1.130 -	exists (has_bool_hfn) (tr::targs)
   1.131 +        exists (has_bool_hfn) (tr::targs)
   1.132      end;
   1.133  
   1.134  fun is_hol_pred tp =
   1.135      let val (targs,tr) = strip_type tp
   1.136      in
   1.137 -	exists (has_bool_hfn) targs
   1.138 +        exists (has_bool_hfn) targs
   1.139      end;
   1.140  
   1.141  exception FN_LG of term;
   1.142  
   1.143 -fun fn_lg (t as Const(f,tp)) (lg,seen) = 
   1.144 -    if is_hol_fn tp then (upgrade_lg HOL lg, insert (op =) t seen) else (lg, insert (op =) t seen) 
   1.145 -  | fn_lg (t as Free(f,tp)) (lg,seen) = 
   1.146 -    if is_hol_fn tp then (upgrade_lg HOL lg, insert (op =) t seen) else (lg, insert (op =) t seen) 
   1.147 +fun fn_lg (t as Const(f,tp)) (lg,seen) =
   1.148 +    if is_hol_fn tp then (upgrade_lg HOL lg, insert (op =) t seen) else (lg, insert (op =) t seen)
   1.149 +  | fn_lg (t as Free(f,tp)) (lg,seen) =
   1.150 +    if is_hol_fn tp then (upgrade_lg HOL lg, insert (op =) t seen) else (lg, insert (op =) t seen)
   1.151    | fn_lg (t as Var(f,tp)) (lg,seen) =
   1.152      if is_hol_fn tp then (upgrade_lg HOL lg,insert (op =) t seen) else (lg,insert (op =) t seen)
   1.153    | fn_lg (t as Abs(_,_,_)) (lg,seen) = (upgrade_lg HOLC lg,insert (op =) t seen)
   1.154 -  | fn_lg f _ = raise FN_LG(f); 
   1.155 +  | fn_lg f _ = raise FN_LG(f);
   1.156  
   1.157  
   1.158  fun term_lg [] (lg,seen) = (lg,seen)
   1.159    | term_lg (tm::tms) (FOL,seen) =
   1.160        let val (f,args) = strip_comb tm
   1.161 -	  val (lg',seen') = if f mem seen then (FOL,seen) 
   1.162 -			    else fn_lg f (FOL,seen)
   1.163 +          val (lg',seen') = if f mem seen then (FOL,seen)
   1.164 +                            else fn_lg f (FOL,seen)
   1.165        in
   1.166 -	if is_fol_logic lg' then ()
   1.167 +        if is_fol_logic lg' then ()
   1.168          else Output.debug ("Found a HOL term: " ^ Display.raw_string_of_term f);
   1.169          term_lg (args@tms) (lg',seen')
   1.170        end
   1.171 @@ -246,11 +246,11 @@
   1.172  
   1.173  exception PRED_LG of term;
   1.174  
   1.175 -fun pred_lg (t as Const(P,tp)) (lg,seen)= 
   1.176 -      if is_hol_pred tp then (upgrade_lg HOL lg, insert (op =) t seen) 
   1.177 -      else (lg,insert (op =) t seen) 
   1.178 +fun pred_lg (t as Const(P,tp)) (lg,seen)=
   1.179 +      if is_hol_pred tp then (upgrade_lg HOL lg, insert (op =) t seen)
   1.180 +      else (lg,insert (op =) t seen)
   1.181    | pred_lg (t as Free(P,tp)) (lg,seen) =
   1.182 -      if is_hol_pred tp then (upgrade_lg HOL lg, insert (op =) t seen) 
   1.183 +      if is_hol_pred tp then (upgrade_lg HOL lg, insert (op =) t seen)
   1.184        else (lg,insert (op =) t seen)
   1.185    | pred_lg (t as Var(_,_)) (lg,seen) = (upgrade_lg HOL lg, insert (op =) t seen)
   1.186    | pred_lg P _ = raise PRED_LG(P);
   1.187 @@ -259,21 +259,21 @@
   1.188  fun lit_lg (Const("Not",_) $ P) (lg,seen) = lit_lg P (lg,seen)
   1.189    | lit_lg P (lg,seen) =
   1.190        let val (pred,args) = strip_comb P
   1.191 -	  val (lg',seen') = if pred mem seen then (lg,seen) 
   1.192 -			    else pred_lg pred (lg,seen)
   1.193 +          val (lg',seen') = if pred mem seen then (lg,seen)
   1.194 +                            else pred_lg pred (lg,seen)
   1.195        in
   1.196 -	if is_fol_logic lg' then ()
   1.197 -	else Output.debug ("Found a HOL predicate: " ^ Display.raw_string_of_term pred);
   1.198 -	term_lg args (lg',seen')
   1.199 +        if is_fol_logic lg' then ()
   1.200 +        else Output.debug ("Found a HOL predicate: " ^ Display.raw_string_of_term pred);
   1.201 +        term_lg args (lg',seen')
   1.202        end;
   1.203  
   1.204  fun lits_lg [] (lg,seen) = (lg,seen)
   1.205    | lits_lg (lit::lits) (FOL,seen) =
   1.206        let val (lg,seen') = lit_lg lit (FOL,seen)
   1.207        in
   1.208 -	if is_fol_logic lg then ()
   1.209 -	else Output.debug ("Found a HOL literal: " ^ Display.raw_string_of_term lit);
   1.210 -	lits_lg lits (lg,seen')
   1.211 +        if is_fol_logic lg then ()
   1.212 +        else Output.debug ("Found a HOL literal: " ^ Display.raw_string_of_term lit);
   1.213 +        lits_lg lits (lg,seen')
   1.214        end
   1.215    | lits_lg lits (lg,seen) = (lg,seen);
   1.216  
   1.217 @@ -288,18 +288,18 @@
   1.218  fun logic_of_clauses [] (lg,seen) = (lg,seen)
   1.219    | logic_of_clauses (cls::clss) (FOL,seen) =
   1.220      let val (lg,seen') = logic_of_clause cls (FOL,seen)
   1.221 -	val _ =
   1.222 +        val _ =
   1.223            if is_fol_logic lg then ()
   1.224            else Output.debug ("Found a HOL clause: " ^ Display.raw_string_of_term cls)
   1.225      in
   1.226 -	logic_of_clauses clss (lg,seen')
   1.227 +        logic_of_clauses clss (lg,seen')
   1.228      end
   1.229    | logic_of_clauses (cls::clss) (lg,seen) = (lg,seen);
   1.230  
   1.231  fun problem_logic_goals_aux [] (lg,seen) = lg
   1.232 -  | problem_logic_goals_aux (subgoal::subgoals) (lg,seen) = 
   1.233 +  | problem_logic_goals_aux (subgoal::subgoals) (lg,seen) =
   1.234      problem_logic_goals_aux subgoals (logic_of_clauses subgoal (lg,seen));
   1.235 -    
   1.236 +
   1.237  fun problem_logic_goals subgoals = problem_logic_goals_aux subgoals (FOL,[]);
   1.238  
   1.239  fun is_fol_thms ths = ((fst(logic_of_clauses (map prop_of ths) (FOL,[]))) = FOL);
   1.240 @@ -311,9 +311,9 @@
   1.241  (*** white list and black list of lemmas ***)
   1.242  
   1.243  (*The rule subsetI is frequently omitted by the relevance filter.*)
   1.244 -val whitelist = ref [subsetI]; 
   1.245 -  
   1.246 -(*Names of theorems (not theorem lists! See multi_blacklist below) to be banned. 
   1.247 +val whitelist = ref [subsetI];
   1.248 +
   1.249 +(*Names of theorems (not theorem lists! See multi_blacklist below) to be banned.
   1.250  
   1.251    These theorems typically produce clauses that are prolific (match too many equality or
   1.252    membership literals) and relate to seldom-used facts. Some duplicate other rules.
   1.253 @@ -447,7 +447,7 @@
   1.254  
   1.255  
   1.256  (*These might be prolific but are probably OK, and min and max are basic.
   1.257 -   "Orderings.max_less_iff_conj", 
   1.258 +   "Orderings.max_less_iff_conj",
   1.259     "Orderings.min_less_iff_conj",
   1.260     "Orderings.min_max.below_inf.below_inf_conv",
   1.261     "Orderings.min_max.below_sup.above_sup_conv",
   1.262 @@ -463,25 +463,25 @@
   1.263  exception HASH_CLAUSE and HASH_STRING;
   1.264  
   1.265  (*Catches (for deletion) theorems automatically generated from other theorems*)
   1.266 -fun insert_suffixed_names ht x = 
   1.267 -     (Polyhash.insert ht (x^"_iff1", ()); 
   1.268 -      Polyhash.insert ht (x^"_iff2", ()); 
   1.269 -      Polyhash.insert ht (x^"_dest", ())); 
   1.270 +fun insert_suffixed_names ht x =
   1.271 +     (Polyhash.insert ht (x^"_iff1", ());
   1.272 +      Polyhash.insert ht (x^"_iff2", ());
   1.273 +      Polyhash.insert ht (x^"_dest", ()));
   1.274  
   1.275  (*Reject theorems with names like "List.filter.filter_list_def" or
   1.276    "Accessible_Part.acc.defs", as these are definitions arising from packages.
   1.277    FIXME: this will also block definitions within locales*)
   1.278  fun is_package_def a =
   1.279 -   length (NameSpace.unpack a) > 2 andalso 
   1.280 +   length (NameSpace.unpack a) > 2 andalso
   1.281     String.isSuffix "_def" a  orelse  String.isSuffix "_defs" a;
   1.282  
   1.283 -fun make_banned_test xs = 
   1.284 +fun make_banned_test xs =
   1.285    let val ht = Polyhash.mkTable (Polyhash.hash_string, op =)
   1.286                                  (6000, HASH_STRING)
   1.287 -      fun banned s = 
   1.288 +      fun banned s =
   1.289              isSome (Polyhash.peek ht s) orelse is_package_def s
   1.290    in  app (fn x => Polyhash.insert ht (x,())) (!blacklist);
   1.291 -      app (insert_suffixed_names ht) (!blacklist @ xs); 
   1.292 +      app (insert_suffixed_names ht) (!blacklist @ xs);
   1.293        banned
   1.294    end;
   1.295  
   1.296 @@ -509,40 +509,40 @@
   1.297  
   1.298  (*Use a hash table to eliminate duplicates from xs. Argument is a list of
   1.299    (thm * (string * int)) tuples. The theorems are hashed into the table. *)
   1.300 -fun make_unique xs = 
   1.301 +fun make_unique xs =
   1.302    let val ht = mk_clause_table 7000
   1.303    in
   1.304        Output.debug("make_unique gets " ^ Int.toString (length xs) ^ " clauses");
   1.305 -      app (ignore o Polyhash.peekInsert ht) xs;  
   1.306 +      app (ignore o Polyhash.peekInsert ht) xs;
   1.307        Polyhash.listItems ht
   1.308    end;
   1.309  
   1.310  (*Remove existing axiom clauses from the conjecture clauses, as this can dramatically
   1.311    boost an ATP's performance (for some reason)*)
   1.312 -fun subtract_cls c_clauses ax_clauses = 
   1.313 +fun subtract_cls c_clauses ax_clauses =
   1.314    let val ht = mk_clause_table 2200
   1.315        fun known x = isSome (Polyhash.peek ht x)
   1.316    in
   1.317 -      app (ignore o Polyhash.peekInsert ht) ax_clauses;  
   1.318 -      filter (not o known) c_clauses 
   1.319 +      app (ignore o Polyhash.peekInsert ht) ax_clauses;
   1.320 +      filter (not o known) c_clauses
   1.321    end;
   1.322  
   1.323 -(*Filter axiom clauses, but keep supplied clauses and clauses in whitelist. 
   1.324 +(*Filter axiom clauses, but keep supplied clauses and clauses in whitelist.
   1.325    Duplicates are removed later.*)
   1.326  fun get_relevant_clauses thy cls_thms white_cls goals =
   1.327    white_cls @ (ReduceAxiomsN.relevance_filter thy cls_thms goals);
   1.328  
   1.329  fun display_thms [] = ()
   1.330 -  | display_thms ((name,thm)::nthms) = 
   1.331 +  | display_thms ((name,thm)::nthms) =
   1.332        let val nthm = name ^ ": " ^ (string_of_thm thm)
   1.333        in Output.debug nthm; display_thms nthms  end;
   1.334 - 
   1.335 +
   1.336  fun all_valid_thms ctxt =
   1.337    PureThy.thms_containing (ProofContext.theory_of ctxt) ([], []) @
   1.338    filter (ProofContext.valid_thms ctxt)
   1.339      (FactIndex.find (ProofContext.fact_index_of ctxt) ([], []));
   1.340  
   1.341 -fun multi_name a (th, (n,pairs)) = 
   1.342 +fun multi_name a (th, (n,pairs)) =
   1.343    (n+1, (a ^ "(" ^ Int.toString n ^ ")", th) :: pairs)
   1.344  
   1.345  fun add_multi_names_aux ((a, []), pairs) = pairs
   1.346 @@ -557,7 +557,7 @@
   1.347    ["defs","select_defs","update_defs","induct","inducts","split","splits","split_asm"];
   1.348  
   1.349  (*Ignore blacklisted theorem lists*)
   1.350 -fun add_multi_names ((a, ths), pairs) = 
   1.351 +fun add_multi_names ((a, ths), pairs) =
   1.352    if a mem_string multi_blacklist orelse (Sign.base_name a) mem_string multi_base_blacklist
   1.353    then pairs
   1.354    else add_multi_names_aux ((a, ths), pairs);
   1.355 @@ -565,7 +565,7 @@
   1.356  fun is_multi (a, ths) = length ths > 1 orelse String.isSuffix ".axioms" a;
   1.357  
   1.358  (*The single theorems go BEFORE the multiple ones*)
   1.359 -fun name_thm_pairs ctxt = 
   1.360 +fun name_thm_pairs ctxt =
   1.361    let val (mults,singles) = List.partition is_multi (all_valid_thms ctxt)
   1.362    in  foldl add_multi_names (foldl add_multi_names [] mults) singles  end;
   1.363  
   1.364 @@ -573,40 +573,40 @@
   1.365    | check_named (_,th) = true;
   1.366  
   1.367  (* get lemmas from claset, simpset, atpset and extra supplied rules *)
   1.368 -fun get_clasimp_atp_lemmas ctxt user_thms = 
   1.369 +fun get_clasimp_atp_lemmas ctxt user_thms =
   1.370    let val included_thms =
   1.371 -	if !include_all 
   1.372 -	then (tap (fn ths => Output.debug
   1.373 -	             ("Including all " ^ Int.toString (length ths) ^ " theorems")) 
   1.374 -	          (name_thm_pairs ctxt))
   1.375 -	else 
   1.376 -	let val claset_thms =
   1.377 -		if !include_claset then ResAxioms.claset_rules_of ctxt
   1.378 -		else []
   1.379 -	    val simpset_thms = 
   1.380 -		if !include_simpset then ResAxioms.simpset_rules_of ctxt
   1.381 -		else []
   1.382 -	    val atpset_thms =
   1.383 -		if !include_atpset then ResAxioms.atpset_rules_of ctxt
   1.384 -		else []
   1.385 -	    val _ = if !Output.show_debug_msgs 
   1.386 -		    then (Output.debug "ATP theorems: "; display_thms atpset_thms) 
   1.387 -		    else ()		 
   1.388 -	in  claset_thms @ simpset_thms @ atpset_thms  end
   1.389 -      val user_rules = filter check_named 
   1.390 +        if !include_all
   1.391 +        then (tap (fn ths => Output.debug
   1.392 +                     ("Including all " ^ Int.toString (length ths) ^ " theorems"))
   1.393 +                  (name_thm_pairs ctxt))
   1.394 +        else
   1.395 +        let val claset_thms =
   1.396 +                if !include_claset then ResAxioms.claset_rules_of ctxt
   1.397 +                else []
   1.398 +            val simpset_thms =
   1.399 +                if !include_simpset then ResAxioms.simpset_rules_of ctxt
   1.400 +                else []
   1.401 +            val atpset_thms =
   1.402 +                if !include_atpset then ResAxioms.atpset_rules_of ctxt
   1.403 +                else []
   1.404 +            val _ = if !Output.show_debug_msgs
   1.405 +                    then (Output.debug "ATP theorems: "; display_thms atpset_thms)
   1.406 +                    else ()
   1.407 +        in  claset_thms @ simpset_thms @ atpset_thms  end
   1.408 +      val user_rules = filter check_named
   1.409                           (map (ResAxioms.pairname)
   1.410 -			   (if null user_thms then !whitelist else user_thms))
   1.411 +                           (if null user_thms then !whitelist else user_thms))
   1.412    in
   1.413        (filter check_named included_thms, user_rules)
   1.414    end;
   1.415  
   1.416  (*Remove lemmas that are banned from the backlist. Also remove duplicates. *)
   1.417 -fun blacklist_filter ths = 
   1.418 -  if !run_blacklist_filter then 
   1.419 +fun blacklist_filter ths =
   1.420 +  if !run_blacklist_filter then
   1.421        let val _ = Output.debug("blacklist filter gets " ^ Int.toString (length ths) ^ " theorems")
   1.422            val banned = make_banned_test (map #1 ths)
   1.423 -	  fun ok (a,_) = not (banned a)
   1.424 -	  val okthms = filter ok ths
   1.425 +          fun ok (a,_) = not (banned a)
   1.426 +          val okthms = filter ok ths
   1.427            val _ = Output.debug("...and returns " ^ Int.toString (length okthms))
   1.428        in  okthms end
   1.429    else ths;
   1.430 @@ -653,7 +653,7 @@
   1.431  (* ATP invocation methods setup                                *)
   1.432  (***************************************************************)
   1.433  
   1.434 -fun cnf_hyps_thms ctxt = 
   1.435 +fun cnf_hyps_thms ctxt =
   1.436      let val ths = Assumption.prems_of ctxt
   1.437      in fold (fold (insert Thm.eq_thm) o ResAxioms.skolem_thm) ths [] end;
   1.438  
   1.439 @@ -664,15 +664,15 @@
   1.440  
   1.441  (*Ensures that no higher-order theorems "leak out"*)
   1.442  fun restrict_to_logic logic cls =
   1.443 -  if is_fol_logic logic then filter (Meson.is_fol_term o prop_of o fst) cls 
   1.444 -	                else cls;
   1.445 +  if is_fol_logic logic then filter (Meson.is_fol_term o prop_of o fst) cls
   1.446 +                        else cls;
   1.447  
   1.448  (**** Predicates to detect unwanted clauses (prolific or likely to cause unsoundness) ****)
   1.449  
   1.450  (** Too general means, positive equality literal with a variable X as one operand,
   1.451    when X does not occur properly in the other operand. This rules out clearly
   1.452    inconsistent clauses such as V=a|V=b, though it by no means guarantees soundness. **)
   1.453 - 
   1.454 +
   1.455  fun occurs ix =
   1.456      let fun occ(Var (jx,_)) = (ix=jx)
   1.457            | occ(t1$t2)      = occ t1 orelse occ t2
   1.458 @@ -685,7 +685,7 @@
   1.459  (*Unwanted equalities include
   1.460    (1) those between a variable that does not properly occur in the second operand,
   1.461    (2) those between a variable and a record, since these seem to be prolific "cases" thms
   1.462 -*)  
   1.463 +*)
   1.464  fun too_general_eqterms (Var (ix,T), t) = not (occurs ix t) orelse is_recordtype T
   1.465    | too_general_eqterms _ = false;
   1.466  
   1.467 @@ -698,7 +698,7 @@
   1.468    | is_taut _ = false;
   1.469  
   1.470  (*True if the term contains a variable whose (atomic) type is in the given list.*)
   1.471 -fun has_typed_var tycons = 
   1.472 +fun has_typed_var tycons =
   1.473    let fun var_tycon (Var (_, Type(a,_))) = a mem_string tycons
   1.474          | var_tycon _ = false
   1.475    in  exists var_tycon o term_vars  end;
   1.476 @@ -713,72 +713,67 @@
   1.477    filter (not o unwanted o prop_of o fst) cls;
   1.478  
   1.479  fun tptp_writer logic goals filename (axioms,classrels,arities) user_lemmas =
   1.480 -    if is_fol_logic logic 
   1.481 +    if is_fol_logic logic
   1.482      then ResClause.tptp_write_file goals filename (axioms, classrels, arities)
   1.483      else ResHolClause.tptp_write_file goals filename (axioms, classrels, arities) user_lemmas;
   1.484  
   1.485  fun dfg_writer logic goals filename (axioms,classrels,arities) user_lemmas =
   1.486 -    if is_fol_logic logic 
   1.487 +    if is_fol_logic logic
   1.488      then ResClause.dfg_write_file goals filename (axioms, classrels, arities)
   1.489      else ResHolClause.dfg_write_file goals filename (axioms, classrels, arities) user_lemmas;
   1.490  
   1.491  (*Called by the oracle-based methods declared in res_atp_methods.ML*)
   1.492  fun write_subgoal_file dfg mode ctxt conjectures user_thms n =
   1.493 -    let val conj_cls = make_clauses conjectures 
   1.494 +    let val conj_cls = make_clauses conjectures
   1.495                           |> ResAxioms.assume_abstract_list |> Meson.finish_cnf
   1.496 -	val hyp_cls = cnf_hyps_thms ctxt
   1.497 -	val goal_cls = conj_cls@hyp_cls
   1.498 -	val goal_tms = map prop_of goal_cls
   1.499 -	val logic = case mode of 
   1.500 +        val hyp_cls = cnf_hyps_thms ctxt
   1.501 +        val goal_cls = conj_cls@hyp_cls
   1.502 +        val goal_tms = map prop_of goal_cls
   1.503 +        val logic = case mode of
   1.504                              Auto => problem_logic_goals [goal_tms]
   1.505 -			  | Fol => FOL
   1.506 -			  | Hol => HOL
   1.507 -	val (included_thms,user_rules) = get_clasimp_atp_lemmas ctxt user_thms
   1.508 -	val cla_simp_atp_clauses = included_thms |> blacklist_filter
   1.509 -	                             |> ResAxioms.cnf_rules_pairs |> make_unique 
   1.510 -                                     |> restrict_to_logic logic 
   1.511 +                          | Fol => FOL
   1.512 +                          | Hol => HOL
   1.513 +        val (included_thms,user_rules) = get_clasimp_atp_lemmas ctxt user_thms
   1.514 +        val cla_simp_atp_clauses = included_thms |> blacklist_filter
   1.515 +                                     |> ResAxioms.cnf_rules_pairs |> make_unique
   1.516 +                                     |> restrict_to_logic logic
   1.517                                       |> remove_unwanted_clauses
   1.518 -	val user_cls = ResAxioms.cnf_rules_pairs user_rules
   1.519 -	val thy = ProofContext.theory_of ctxt
   1.520 -	val axclauses = make_unique (get_relevant_clauses thy cla_simp_atp_clauses user_cls goal_tms)
   1.521 -	val keep_types = if is_fol_logic logic then !fol_keep_types else is_typed_hol ()
   1.522 +        val user_cls = ResAxioms.cnf_rules_pairs user_rules
   1.523 +        val thy = ProofContext.theory_of ctxt
   1.524 +        val axclauses = make_unique (get_relevant_clauses thy cla_simp_atp_clauses user_cls goal_tms)
   1.525 +        val keep_types = if is_fol_logic logic then !fol_keep_types else is_typed_hol ()
   1.526          val subs = tfree_classes_of_terms goal_tms
   1.527          and axtms = map (prop_of o #1) axclauses
   1.528          val supers = tvar_classes_of_terms axtms
   1.529          and tycons = type_consts_of_terms thy (goal_tms@axtms)
   1.530          (*TFrees in conjecture clauses; TVars in axiom clauses*)
   1.531 -        val classrel_clauses = 
   1.532 +        val classrel_clauses =
   1.533                if keep_types then ResClause.make_classrel_clauses thy subs supers
   1.534                else []
   1.535 -	val arity_clauses = if keep_types then ResClause.arity_clause_thy thy tycons supers else []
   1.536 -        val writer = if dfg then dfg_writer else tptp_writer 
   1.537 -	and file = atp_input_file()
   1.538 -	and user_lemmas_names = map #1 user_rules
   1.539 +        val arity_clauses = if keep_types then ResClause.arity_clause_thy thy tycons supers else []
   1.540 +        val writer = if dfg then dfg_writer else tptp_writer
   1.541 +        and file = atp_input_file()
   1.542 +        and user_lemmas_names = map #1 user_rules
   1.543      in
   1.544 -	writer logic goal_cls file (axclauses,classrel_clauses,arity_clauses) user_lemmas_names;
   1.545 -	Output.debug ("Writing to " ^ file);
   1.546 -	file
   1.547 +        writer logic goal_cls file (axclauses,classrel_clauses,arity_clauses) user_lemmas_names;
   1.548 +        Output.debug ("Writing to " ^ file);
   1.549 +        file
   1.550      end;
   1.551  
   1.552  
   1.553  (**** remove tmp files ****)
   1.554 -fun cond_rm_tmp file = 
   1.555 -    if !Output.show_debug_msgs orelse !destdir <> "" then Output.debug "ATP input kept..." 
   1.556 +fun cond_rm_tmp file =
   1.557 +    if !Output.show_debug_msgs orelse !destdir <> "" then Output.debug "ATP input kept..."
   1.558      else OS.FileSys.remove file;
   1.559  
   1.560  
   1.561  (****** setup ATPs as Isabelle methods ******)
   1.562 -fun atp_meth' tac ths ctxt = 
   1.563 -    Method.SIMPLE_METHOD' HEADGOAL
   1.564 -    (tac ctxt ths);
   1.565  
   1.566 -fun atp_meth tac ths ctxt = 
   1.567 +fun atp_meth tac ths ctxt =
   1.568      let val thy = ProofContext.theory_of ctxt
   1.569 -	val _ = ResClause.init thy
   1.570 -	val _ = ResHolClause.init thy
   1.571 -    in
   1.572 -	atp_meth' tac ths ctxt
   1.573 -    end;
   1.574 +        val _ = ResClause.init thy
   1.575 +        val _ = ResHolClause.init thy
   1.576 +    in Method.SIMPLE_METHOD' (tac ctxt ths) end;
   1.577  
   1.578  fun atp_method tac = Method.thms_ctxt_args (atp_meth tac);
   1.579  
   1.580 @@ -802,25 +797,25 @@
   1.581                let val spass = helper_path "SPASS_HOME" "SPASS"
   1.582                    val sopts =
   1.583     "-Auto%-SOS=1%-PGiven=0%-PProblem=0%-Splits=0%-FullRed=0%-DocProof%-TimeLimit=" ^ time
   1.584 -              in 
   1.585 +              in
   1.586                    ("spass", spass, sopts, probfile) :: make_atp_list xs (n+1)
   1.587                end
   1.588              else if !prover = "vampire"
   1.589 -	    then 
   1.590 +            then
   1.591                let val vampire = helper_path "VAMPIRE_HOME" "vampire"
   1.592                    val vopts = "--mode casc%-t " ^ time  (*what about -m 100000?*)
   1.593                in
   1.594                    ("vampire", vampire, vopts, probfile) :: make_atp_list xs (n+1)
   1.595                end
   1.596 -      	     else if !prover = "E"
   1.597 -      	     then
   1.598 -	       let val Eprover = helper_path "E_HOME" "eproof"
   1.599 -	       in
   1.600 -		  ("E", Eprover, 
   1.601 -		     "--tstp-in%-l5%-xAutoDev%-tAutoDev%--silent%--cpu-limit=" ^ time, probfile) ::
   1.602 -		   make_atp_list xs (n+1)
   1.603 -	       end
   1.604 -	     else error ("Invalid prover name: " ^ !prover)
   1.605 +             else if !prover = "E"
   1.606 +             then
   1.607 +               let val Eprover = helper_path "E_HOME" "eproof"
   1.608 +               in
   1.609 +                  ("E", Eprover,
   1.610 +                     "--tstp-in%-l5%-xAutoDev%-tAutoDev%--silent%--cpu-limit=" ^ time, probfile) ::
   1.611 +                   make_atp_list xs (n+1)
   1.612 +               end
   1.613 +             else error ("Invalid prover name: " ^ !prover)
   1.614            end
   1.615  
   1.616      val atp_list = make_atp_list sg_terms 1
   1.617 @@ -828,7 +823,7 @@
   1.618      Watcher.callResProvers(childout,atp_list);
   1.619      Output.debug "Sent commands to watcher!"
   1.620    end
   1.621 -  
   1.622 +
   1.623  fun trace_array fname =
   1.624    let val path = File.unpack_platform_path fname
   1.625    in  Array.app (File.append path o (fn s => s ^ "\n"))  end;
   1.626 @@ -839,7 +834,7 @@
   1.627        val st = Seq.hd (EVERY' tacs n th)
   1.628        val negs = Option.valOf (metahyps_thms n st)
   1.629    in make_clauses negs |> ResAxioms.assume_abstract_list |> Meson.finish_cnf end;
   1.630 -		                       
   1.631 +
   1.632  (*We write out problem files for each subgoal. Argument probfile generates filenames,
   1.633    and allows the suppression of the suffix "_1" in problem-generation mode.
   1.634    FIXME: does not cope with &&, and it isn't easy because one could have multiple
   1.635 @@ -852,12 +847,12 @@
   1.636          | get_neg_subgoals (gl::gls) n = neg_clauses th n :: get_neg_subgoals gls (n+1)
   1.637        val goal_cls = get_neg_subgoals goals 1
   1.638        val logic = case !linkup_logic_mode of
   1.639 -		Auto => problem_logic_goals (map ((map prop_of)) goal_cls)
   1.640 -	      | Fol => FOL
   1.641 -	      | Hol => HOL
   1.642 +                Auto => problem_logic_goals (map ((map prop_of)) goal_cls)
   1.643 +              | Fol => FOL
   1.644 +              | Hol => HOL
   1.645        val (included_thms,white_thms) = get_clasimp_atp_lemmas ctxt []
   1.646        val included_cls = included_thms |> blacklist_filter
   1.647 -                                       |> ResAxioms.cnf_rules_pairs |> make_unique 
   1.648 +                                       |> ResAxioms.cnf_rules_pairs |> make_unique
   1.649                                         |> restrict_to_logic logic
   1.650                                         |> remove_unwanted_clauses
   1.651        val _ = Output.debug ("clauses = " ^ Int.toString(length included_cls))
   1.652 @@ -866,11 +861,11 @@
   1.653        val axcls_list = map (fn ngcls => get_relevant_clauses thy included_cls white_cls (map prop_of ngcls)) goal_cls
   1.654        val _ = app (fn axcls => Output.debug ("filtered clauses = " ^ Int.toString(length axcls)))
   1.655                    axcls_list
   1.656 -      val keep_types = if is_fol_logic logic then !ResClause.keep_types 
   1.657 +      val keep_types = if is_fol_logic logic then !ResClause.keep_types
   1.658                         else is_typed_hol ()
   1.659 -      val writer = if !prover = "spass" then dfg_writer else tptp_writer 
   1.660 +      val writer = if !prover = "spass" then dfg_writer else tptp_writer
   1.661        fun write_all [] [] _ = []
   1.662 -	| write_all (ccls::ccls_list) (axcls::axcls_list) k =
   1.663 +        | write_all (ccls::ccls_list) (axcls::axcls_list) k =
   1.664              let val fname = probfile k
   1.665                  val axcls = make_unique axcls
   1.666                  val ccls = subtract_cls ccls axcls
   1.667 @@ -880,7 +875,7 @@
   1.668                  and supers = tvar_classes_of_terms axtms
   1.669                  and tycons = type_consts_of_terms thy (ccltms@axtms)
   1.670                  (*TFrees in conjecture clauses; TVars in axiom clauses*)
   1.671 -                val classrel_clauses = 
   1.672 +                val classrel_clauses =
   1.673                        if keep_types then ResClause.make_classrel_clauses thy subs supers
   1.674                        else []
   1.675                  val _ = Output.debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
   1.676 @@ -889,7 +884,7 @@
   1.677                  val _ = Output.debug ("arity clauses = " ^ Int.toString (length arity_clauses))
   1.678                  val clnames = writer logic ccls fname (axcls,classrel_clauses,arity_clauses) []
   1.679                  val thm_names = Array.fromList clnames
   1.680 -                val _ = if !Output.show_debug_msgs 
   1.681 +                val _ = if !Output.show_debug_msgs
   1.682                          then trace_array (fname ^ "_thm_names") thm_names else ()
   1.683              in  (thm_names,fname) :: write_all ccls_list axcls_list (k+1)  end
   1.684        val (thm_names_list, filenames) = ListPair.unzip (write_all goal_cls axcls_list 1)
   1.685 @@ -897,16 +892,16 @@
   1.686        (filenames, thm_names_list)
   1.687    end;
   1.688  
   1.689 -val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream * 
   1.690 +val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream *
   1.691                                      Posix.Process.pid * string list) option);
   1.692  
   1.693  fun kill_last_watcher () =
   1.694 -    (case !last_watcher_pid of 
   1.695 +    (case !last_watcher_pid of
   1.696           NONE => ()
   1.697 -       | SOME (_, _, pid, files) => 
   1.698 -	  (Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid);
   1.699 -	   Watcher.killWatcher pid;  
   1.700 -	   ignore (map (try cond_rm_tmp) files)))
   1.701 +       | SOME (_, _, pid, files) =>
   1.702 +          (Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid);
   1.703 +           Watcher.killWatcher pid;
   1.704 +           ignore (map (try cond_rm_tmp) files)))
   1.705       handle OS.SysErr _ => Output.debug "Attempt to kill watcher failed";
   1.706  
   1.707  (*writes out the current clasimpset to a tptp file;
   1.708 @@ -920,7 +915,7 @@
   1.709        val (childin, childout, pid) = Watcher.createWatcher (th, thm_names_list)
   1.710      in
   1.711        last_watcher_pid := SOME (childin, childout, pid, files);
   1.712 -      Output.debug ("problem files: " ^ space_implode ", " files); 
   1.713 +      Output.debug ("problem files: " ^ space_implode ", " files);
   1.714        Output.debug ("pid: " ^ string_of_pid pid);
   1.715        watcher_call_provers (sign_of_thm th) (Thm.prems_of th) (childin, childout, pid)
   1.716      end;
   1.717 @@ -928,17 +923,17 @@
   1.718  val isar_atp = setmp print_mode [] isar_atp_body;
   1.719  
   1.720  (*For ML scripts, and primarily, for debugging*)
   1.721 -fun callatp () = 
   1.722 +fun callatp () =
   1.723    let val th = topthm()
   1.724        val ctxt = ProofContext.init (theory_of_thm th)
   1.725    in  isar_atp_body (ctxt, th)  end;
   1.726  
   1.727 -val isar_atp_writeonly = setmp print_mode [] 
   1.728 +val isar_atp_writeonly = setmp print_mode []
   1.729        (fn (ctxt,th) =>
   1.730         if Thm.no_prems th then ()
   1.731 -       else 
   1.732 -         let val probfile = if Thm.nprems_of th = 1 then probfile_nosuffix 
   1.733 -          	            else prob_pathname
   1.734 +       else
   1.735 +         let val probfile = if Thm.nprems_of th = 1 then probfile_nosuffix
   1.736 +                            else prob_pathname
   1.737           in ignore (write_problem_files probfile (ctxt,th)) end);
   1.738  
   1.739  
   1.740 @@ -947,9 +942,9 @@
   1.741  fun invoke_atp_ml (ctxt, goal) =
   1.742    let val thy = ProofContext.theory_of ctxt;
   1.743    in
   1.744 -    Output.debug ("subgoals in isar_atp:\n" ^ 
   1.745 -		  Pretty.string_of (ProofContext.pretty_term ctxt
   1.746 -		    (Logic.mk_conjunction_list (Thm.prems_of goal))));
   1.747 +    Output.debug ("subgoals in isar_atp:\n" ^
   1.748 +                  Pretty.string_of (ProofContext.pretty_term ctxt
   1.749 +                    (Logic.mk_conjunction_list (Thm.prems_of goal))));
   1.750      Output.debug ("current theory: " ^ Context.theory_name thy);
   1.751      inc hook_count;
   1.752      Output.debug ("in hook for time: " ^ Int.toString (!hook_count));
   1.753 @@ -965,9 +960,9 @@
   1.754    in  invoke_atp_ml (ctxt, goal)  end);
   1.755  
   1.756  val call_atpP =
   1.757 -  OuterSyntax.command 
   1.758 -    "ProofGeneral.call_atp" 
   1.759 -    "call automatic theorem provers" 
   1.760 +  OuterSyntax.command
   1.761 +    "ProofGeneral.call_atp"
   1.762 +    "call automatic theorem provers"
   1.763      OuterKeyword.diag
   1.764      (Scan.succeed invoke_atp);
   1.765