src/Pure/meta_simplifier.ML
changeset 24124 4399175e3014
parent 23938 977d14aeb4d5
child 24358 d75af3e90e82
equal deleted inserted replaced
24123:a0fc58900606 24124:4399175e3014
    12 
    12 
    13 signature BASIC_META_SIMPLIFIER =
    13 signature BASIC_META_SIMPLIFIER =
    14 sig
    14 sig
    15   val debug_simp: bool ref
    15   val debug_simp: bool ref
    16   val trace_simp: bool ref
    16   val trace_simp: bool ref
    17   val simp_depth_limit: int ref
       
    18   val trace_simp_depth_limit: int ref
    17   val trace_simp_depth_limit: int ref
    19   type rrule
    18   type rrule
    20   val eq_rrule: rrule * rrule -> bool
    19   val eq_rrule: rrule * rrule -> bool
    21   type cong
    20   type cong
    22   type simpset
    21   type simpset
    92 signature META_SIMPLIFIER =
    91 signature META_SIMPLIFIER =
    93 sig
    92 sig
    94   include BASIC_META_SIMPLIFIER
    93   include BASIC_META_SIMPLIFIER
    95   exception SIMPLIFIER of string * thm
    94   exception SIMPLIFIER of string * thm
    96   val solver: simpset -> solver -> int -> tactic
    95   val solver: simpset -> solver -> int -> tactic
       
    96   val simp_depth_limit_value: Config.value Config.T
       
    97   val simp_depth_limit: int Config.T
    97   val clear_ss: simpset -> simpset
    98   val clear_ss: simpset -> simpset
    98   val simproc_i: theory -> string -> term list
    99   val simproc_i: theory -> string -> term list
    99     -> (theory -> simpset -> term -> thm option) -> simproc
   100     -> (theory -> simpset -> term -> thm option) -> simproc
   100   val simproc: theory -> string -> string list
   101   val simproc: theory -> string -> string list
   101     -> (theory -> simpset -> term -> thm option) -> simproc
   102     -> (theory -> simpset -> term -> thm option) -> simproc
   252 fun eq_solver (Solver {id = id1, ...}, Solver {id = id2, ...}) = (id1 = id2);
   253 fun eq_solver (Solver {id = id1, ...}, Solver {id = id2, ...}) = (id1 = id2);
   253 
   254 
   254 
   255 
   255 (* simp depth *)
   256 (* simp depth *)
   256 
   257 
   257 val simp_depth_limit = ref 100;
   258 val simp_depth_limit_value = Config.declare false "simp_depth_limit" (Config.Int 100);
       
   259 val simp_depth_limit = Config.int simp_depth_limit_value;
       
   260 
   258 val trace_simp_depth_limit = ref 1;
   261 val trace_simp_depth_limit = ref 1;
   259 
   262 
   260 fun trace_depth (Simpset ({depth = (depth, exceeded), ...}, _)) msg =
   263 fun trace_depth (Simpset ({depth = (depth, exceeded), ...}, _)) msg =
   261   if depth > ! trace_simp_depth_limit then
   264   if depth > ! trace_simp_depth_limit then
   262     if ! exceeded then () else (tracing "trace_simp_depth_limit exceeded!"; exceeded := true)
   265     if ! exceeded then () else (tracing "trace_simp_depth_limit exceeded!"; exceeded := true)
   882   IMPORTANT: rewrite rules must not introduce new Vars or TVars!
   885   IMPORTANT: rewrite rules must not introduce new Vars or TVars!
   883 *)
   886 *)
   884 
   887 
   885 fun rewritec (prover, thyt, maxt) ss t =
   888 fun rewritec (prover, thyt, maxt) ss t =
   886   let
   889   let
       
   890     val ctxt = the_context ss;
   887     val Simpset ({rules, ...}, {congs, procs, termless, ...}) = ss;
   891     val Simpset ({rules, ...}, {congs, procs, termless, ...}) = ss;
   888     val eta_thm = Thm.eta_conversion t;
   892     val eta_thm = Thm.eta_conversion t;
   889     val eta_t' = Thm.rhs_of eta_thm;
   893     val eta_t' = Thm.rhs_of eta_thm;
   890     val eta_t = term_of eta_t';
   894     val eta_t = term_of eta_t';
   891     fun rew {thm, name, lhs, elhs, extra, fo, perm} =
   895     fun rew {thm, name, lhs, elhs, extra, fo, perm} =
   912               let val lr = Logic.dest_equals prop;
   916               let val lr = Logic.dest_equals prop;
   913                   val SOME thm'' = check_conv false ss eta_thm thm'
   917                   val SOME thm'' = check_conv false ss eta_thm thm'
   914               in SOME (thm'', uncond_skel (congs, lr)) end)
   918               in SOME (thm'', uncond_skel (congs, lr)) end)
   915            else
   919            else
   916              (trace_thm (fn () => "Trying to rewrite:") ss thm';
   920              (trace_thm (fn () => "Trying to rewrite:") ss thm';
   917               if simp_depth ss > ! simp_depth_limit
   921               if simp_depth ss > Config.get ctxt simp_depth_limit
   918               then let val s = "simp_depth_limit exceeded - giving up"
   922               then let val s = "simp_depth_limit exceeded - giving up"
   919                    in trace false (fn () => s) ss; warning s; NONE end
   923                    in trace false (fn () => s) ss; warning s; NONE end
   920               else
   924               else
   921               case prover ss thm' of
   925               case prover ss thm' of
   922                 NONE => (trace_thm (fn () => "FAILED") ss thm'; NONE)
   926                 NONE => (trace_thm (fn () => "FAILED") ss thm'; NONE)