src/Pure/raw_simplifier.ML
changeset 54997 811c35e81ac5
parent 54984 da70ab8531f4
child 55000 782b8cc9233d
equal deleted inserted replaced
54996:aee15e11ee73 54997:811c35e81ac5
    68 end;
    68 end;
    69 
    69 
    70 signature RAW_SIMPLIFIER =
    70 signature RAW_SIMPLIFIER =
    71 sig
    71 sig
    72   include BASIC_RAW_SIMPLIFIER
    72   include BASIC_RAW_SIMPLIFIER
    73   exception SIMPLIFIER of string * thm
    73   exception SIMPLIFIER of string * thm list
    74   type trace_ops
    74   type trace_ops
    75   val set_trace_ops: trace_ops -> theory -> theory
    75   val set_trace_ops: trace_ops -> theory -> theory
    76   val internal_ss: simpset ->
    76   val internal_ss: simpset ->
    77    {congs: (cong_name * thm) list * cong_name list,
    77    {congs: (cong_name * thm) list * cong_name list,
    78     procs: proc Net.net,
    78     procs: proc Net.net,
   434   in depth end;
   434   in depth end;
   435 
   435 
   436 
   436 
   437 (* diagnostics *)
   437 (* diagnostics *)
   438 
   438 
   439 exception SIMPLIFIER of string * thm;
   439 exception SIMPLIFIER of string * thm list;
   440 
   440 
   441 val simp_debug_raw = Config.declare "simp_debug" (K (Config.Bool false));
   441 val simp_debug_raw = Config.declare "simp_debug" (K (Config.Bool false));
   442 val simp_debug = Config.bool simp_debug_raw;
   442 val simp_debug = Config.bool simp_debug_raw;
   443 
   443 
   444 val simp_trace_default = Unsynchronized.ref false;
   444 val simp_trace_default = Unsynchronized.ref false;
   539   let
   539   let
   540     val prop = Thm.prop_of thm;
   540     val prop = Thm.prop_of thm;
   541     val prems = Logic.strip_imp_prems prop;
   541     val prems = Logic.strip_imp_prems prop;
   542     val concl = Drule.strip_imp_concl (Thm.cprop_of thm);
   542     val concl = Drule.strip_imp_concl (Thm.cprop_of thm);
   543     val (lhs, rhs) = Thm.dest_equals concl handle TERM _ =>
   543     val (lhs, rhs) = Thm.dest_equals concl handle TERM _ =>
   544       raise SIMPLIFIER ("Rewrite rule not a meta-equality", thm);
   544       raise SIMPLIFIER ("Rewrite rule not a meta-equality", [thm]);
   545     val elhs = Thm.dest_arg (Thm.cprop_of (Thm.eta_conversion lhs));
   545     val elhs = Thm.dest_arg (Thm.cprop_of (Thm.eta_conversion lhs));
   546     val erhs = Envir.eta_contract (term_of rhs);
   546     val erhs = Envir.eta_contract (term_of rhs);
   547     val perm =
   547     val perm =
   548       var_perm (term_of elhs, erhs) andalso
   548       var_perm (term_of elhs, erhs) andalso
   549       not (term_of elhs aconv erhs) andalso
   549       not (term_of elhs aconv erhs) andalso
   552 
   552 
   553 end;
   553 end;
   554 
   554 
   555 fun decomp_simp' thm =
   555 fun decomp_simp' thm =
   556   let val (_, lhs, _, rhs, _) = decomp_simp thm in
   556   let val (_, lhs, _, rhs, _) = decomp_simp thm in
   557     if Thm.nprems_of thm > 0 then raise SIMPLIFIER ("Bad conditional rewrite rule", thm)
   557     if Thm.nprems_of thm > 0 then raise SIMPLIFIER ("Bad conditional rewrite rule", [thm])
   558     else (lhs, rhs)
   558     else (lhs, rhs)
   559   end;
   559   end;
   560 
   560 
   561 fun mk_eq_True ctxt (thm, name) =
   561 fun mk_eq_True ctxt (thm, name) =
   562   let val Simpset (_, {mk_rews = {mk_eq_True, ...}, ...}) = simpset_of ctxt in
   562   let val Simpset (_, {mk_rews = {mk_eq_True, ...}, ...}) = simpset_of ctxt in
   664 
   664 
   665 fun add_eqcong thm ctxt = ctxt |> map_simpset2
   665 fun add_eqcong thm ctxt = ctxt |> map_simpset2
   666   (fn (congs, procs, mk_rews, termless, subgoal_tac, loop_tacs, solvers) =>
   666   (fn (congs, procs, mk_rews, termless, subgoal_tac, loop_tacs, solvers) =>
   667     let
   667     let
   668       val (lhs, _) = Logic.dest_equals (Thm.concl_of thm)
   668       val (lhs, _) = Logic.dest_equals (Thm.concl_of thm)
   669         handle TERM _ => raise SIMPLIFIER ("Congruence not a meta-equality", thm);
   669         handle TERM _ => raise SIMPLIFIER ("Congruence not a meta-equality", [thm]);
   670     (*val lhs = Envir.eta_contract lhs;*)
   670     (*val lhs = Envir.eta_contract lhs;*)
   671       val a = the (cong_name (head_of lhs)) handle Option.Option =>
   671       val a = the (cong_name (head_of lhs)) handle Option.Option =>
   672         raise SIMPLIFIER ("Congruence must start with a constant or free variable", thm);
   672         raise SIMPLIFIER ("Congruence must start with a constant or free variable", [thm]);
   673       val (xs, weak) = congs;
   673       val (xs, weak) = congs;
   674       val _ =
   674       val _ =
   675         if AList.defined (op =) xs a then
   675         if AList.defined (op =) xs a then
   676           Context_Position.if_visible ctxt
   676           Context_Position.if_visible ctxt
   677             warning ("Overwriting congruence rule for " ^ quote (#2 a))
   677             warning ("Overwriting congruence rule for " ^ quote (#2 a))
   682 
   682 
   683 fun del_eqcong thm ctxt = ctxt |> map_simpset2
   683 fun del_eqcong thm ctxt = ctxt |> map_simpset2
   684   (fn (congs, procs, mk_rews, termless, subgoal_tac, loop_tacs, solvers) =>
   684   (fn (congs, procs, mk_rews, termless, subgoal_tac, loop_tacs, solvers) =>
   685     let
   685     let
   686       val (lhs, _) = Logic.dest_equals (Thm.concl_of thm)
   686       val (lhs, _) = Logic.dest_equals (Thm.concl_of thm)
   687         handle TERM _ => raise SIMPLIFIER ("Congruence not a meta-equality", thm);
   687         handle TERM _ => raise SIMPLIFIER ("Congruence not a meta-equality", [thm]);
   688     (*val lhs = Envir.eta_contract lhs;*)
   688     (*val lhs = Envir.eta_contract lhs;*)
   689       val a = the (cong_name (head_of lhs)) handle Option.Option =>
   689       val a = the (cong_name (head_of lhs)) handle Option.Option =>
   690         raise SIMPLIFIER ("Congruence must start with a constant", thm);
   690         raise SIMPLIFIER ("Congruence must start with a constant", [thm]);
   691       val (xs, _) = congs;
   691       val (xs, _) = congs;
   692       val xs' = filter_out (fn (x : cong_name, _) => x = a) xs;
   692       val xs' = filter_out (fn (x : cong_name, _) => x = a) xs;
   693       val weak' = xs' |> map_filter (fn (a, thm) =>
   693       val weak' = xs' |> map_filter (fn (a, thm) =>
   694         if is_full_cong thm then NONE else SOME a);
   694         if is_full_cong thm then NONE else SOME a);
   695     in ((xs', weak'), procs, mk_rews, termless, subgoal_tac, loop_tacs, solvers) end);
   695     in ((xs', weak'), procs, mk_rews, termless, subgoal_tac, loop_tacs, solvers) end);