Catch exceptions arising during the abstraction operation.
authorpaulson
Wed Oct 31 15:10:34 2007 +0100 (2007-10-31)
changeset 25256fe467fdf129a
parent 25255 66ee31849d13
child 25257 8faf184ba5b1
Catch exceptions arising during the abstraction operation.
Filter out theorems that are "too deep".
src/HOL/Tools/res_axioms.ML
     1.1 --- a/src/HOL/Tools/res_axioms.ML	Wed Oct 31 12:19:45 2007 +0100
     1.2 +++ b/src/HOL/Tools/res_axioms.ML	Wed Oct 31 15:10:34 2007 +0100
     1.3 @@ -22,6 +22,7 @@
     1.4    val atpset_rules_of: Proof.context -> (string * thm) list
     1.5    val meson_method_setup: theory -> theory
     1.6    val clause_cache_endtheory: theory -> theory option
     1.7 +  val suppress_endtheory: bool ref     (*for emergency use where endtheory causes problems*)
     1.8    val setup: theory -> theory
     1.9  end;
    1.10  
    1.11 @@ -170,7 +171,8 @@
    1.12  
    1.13  (*FIXME: requires more use of cterm constructors*)
    1.14  fun abstract ct =
    1.15 -  let val Abs(x,_,body) = term_of ct
    1.16 +  let val _ = Output.debug (fn()=>"  abstraction: " ^ string_of_cterm ct)
    1.17 +      val Abs(x,_,body) = term_of ct
    1.18        val thy = theory_of_cterm ct
    1.19        val Type("fun",[xT,bodyT]) = typ_of (ctyp_of_term ct)
    1.20        val cxT = ctyp_of thy xT and cbodyT = ctyp_of thy bodyT
    1.21 @@ -202,7 +204,8 @@
    1.22  	       if rand = Bound 0 then eta_conversion ct
    1.23  	       else (*B*)
    1.24  	         let val crand = cterm_of thy (Abs(x,xT,rand))
    1.25 -	             val abs_B' = cterm_instantiate [(f_B, cterm_of thy rator),(g_B,crand)] abs_B
    1.26 +	             val crator = cterm_of thy rator
    1.27 +	             val abs_B' = cterm_instantiate [(f_B,crator),(g_B,crand)] abs_B
    1.28  	             val (_,rhs) = Thm.dest_equals (cprop_of abs_B') 
    1.29  	         in
    1.30  	           Thm.transitive abs_B' (Conv.arg_conv abstract rhs)
    1.31 @@ -238,7 +241,11 @@
    1.32  	val th = Drule.eta_contraction_rule th
    1.33  	val eqth = combinators_aux (cprop_of th)
    1.34  	val _ = Output.debug (fn()=>"Conversion result: " ^ string_of_thm eqth);
    1.35 -    in  equal_elim eqth th   end;
    1.36 +    in  equal_elim eqth th   end
    1.37 +    handle THM (msg,_,_) => 
    1.38 +      (warning ("Error in the combinator translation of " ^ string_of_thm th);
    1.39 +       warning ("  Exception message: " ^ msg);
    1.40 +       TrueI);  (*A type variable of sort {} will cause make abstraction fail.*)
    1.41  
    1.42  (*cterms are used throughout for efficiency*)
    1.43  val cTrueprop = Thm.cterm_of HOL.thy HOLogic.Trueprop;
    1.44 @@ -318,8 +325,17 @@
    1.45        then exists (excessive_lambdas_fm Ts) (#2 (strip_comb t))
    1.46        else excessive_lambdas (t, max_lambda_nesting);
    1.47  
    1.48 +(*The max apply_depth of any metis call in MetisExamples (on 31-10-2007) was 11.*)
    1.49 +val max_apply_depth = 15;
    1.50 +     
    1.51 +fun apply_depth (f$t) = Int.max (apply_depth f, apply_depth t + 1)
    1.52 +  | apply_depth (Abs(_,_,t)) = apply_depth t
    1.53 +  | apply_depth _ = 0;
    1.54 +
    1.55  fun too_complex t = 
    1.56 -  Meson.too_many_clauses t orelse excessive_lambdas_fm [] t;
    1.57 +  apply_depth t > max_apply_depth orelse 
    1.58 +  Meson.too_many_clauses t orelse
    1.59 +  excessive_lambdas_fm [] t;
    1.60    
    1.61  fun is_strange_thm th =
    1.62    case head_of (concl_of th) of
    1.63 @@ -330,7 +346,8 @@
    1.64    PureThy.is_internal th orelse too_complex (prop_of th) orelse is_strange_thm th;
    1.65  
    1.66  val multi_base_blacklist =
    1.67 -  ["defs","select_defs","update_defs","induct","inducts","split","splits","split_asm"];
    1.68 +  ["defs","select_defs","update_defs","induct","inducts","split","splits","split_asm",
    1.69 +   "cases","ext_cases"];  (*FIXME: put other record thms here, or use the "Internal" marker*)
    1.70  
    1.71  (*Keep the full complexity of the original name*)
    1.72  fun flatten_name s = space_implode "_X" (NameSpace.explode s);
    1.73 @@ -347,11 +364,12 @@
    1.74    It returns a modified theory, unless skolemization fails.*)
    1.75  fun skolem thy th =
    1.76    let val ctxt0 = Variable.thm_context th
    1.77 +      val _ = Output.debug (fn () => "skolemizing " ^ name_or_string th)
    1.78    in
    1.79       Option.map
    1.80          (fn (nnfth,ctxt1) =>
    1.81 -          let val _ = Output.debug (fn () => "skolemizing " ^ name_or_string th ^ ": ")
    1.82 -              val _ = Output.debug (fn () => string_of_thm nnfth)
    1.83 +          let 
    1.84 +              val _ = Output.debug (fn () => "  initial nnf: " ^ string_of_thm nnfth)
    1.85                val s = fake_name th
    1.86                val (thy',defs) = declare_skofuns s nnfth thy
    1.87                val (cnfs,ctxt2) = Meson.make_cnf (map skolem_of_def defs) nnfth ctxt1
    1.88 @@ -471,12 +489,14 @@
    1.89  (*The cache can be kept smaller by inspecting the prop of each thm. Can ignore all that are
    1.90    lambda_free, but then the individual theory caches become much bigger.*)
    1.91  
    1.92 +val suppress_endtheory = ref false;
    1.93 +
    1.94  (*The new constant is a hack to prevent multiple execution*)
    1.95  fun clause_cache_endtheory thy =
    1.96 -  let val _ = Output.debug (fn () => "RexAxioms end theory action: " ^ Context.str_of_thy thy)
    1.97 -  in
    1.98 -    Option.map skolem_cache_node (try mark_skolemized thy)
    1.99 -  end;
   1.100 +  if !suppress_endtheory then NONE
   1.101 +  else
   1.102 +   (Output.debug (fn () => "RexAxioms end theory action: " ^ Context.str_of_thy thy);
   1.103 +    Option.map skolem_cache_node (try mark_skolemized thy) );
   1.104  
   1.105  (*** meson proof methods ***)
   1.106