src/Pure/simplifier.ML
changeset 18708 4b3dadb4fe33
parent 18688 abf0f018b5ec
child 18728 6790126ab5f6
equal deleted inserted replaced
18707:9d6154f76476 18708:4b3dadb4fe33
    71   val cong_del: Context.generic attribute
    71   val cong_del: Context.generic attribute
    72   val cong_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
    72   val cong_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
    73   val simp_modifiers': (Args.T list -> (Method.modifier * Args.T list)) list
    73   val simp_modifiers': (Args.T list -> (Method.modifier * Args.T list)) list
    74   val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
    74   val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
    75   val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list
    75   val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list
    76     -> (theory -> theory) list
    76     -> theory -> theory
    77   val easy_setup: thm -> thm list -> (theory -> theory) list
    77   val easy_setup: thm -> thm list -> theory -> theory
    78 end;
    78 end;
    79 
    79 
    80 structure Simplifier: SIMPLIFIER =
    80 structure Simplifier: SIMPLIFIER =
    81 struct
    81 struct
    82 
    82 
    94   fun extend (ref ss) = ref (MetaSimplifier.inherit_context empty_ss ss);
    94   fun extend (ref ss) = ref (MetaSimplifier.inherit_context empty_ss ss);
    95   fun merge _ (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2));
    95   fun merge _ (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2));
    96   fun print _ (ref ss) = print_ss ss;
    96   fun print _ (ref ss) = print_ss ss;
    97 end);
    97 end);
    98 
    98 
    99 val _ = Context.add_setup [GlobalSimpset.init];
    99 val _ = Context.add_setup GlobalSimpset.init;
   100 val print_simpset = GlobalSimpset.print;
   100 val print_simpset = GlobalSimpset.print;
   101 val get_simpset = ! o GlobalSimpset.get;
   101 val get_simpset = ! o GlobalSimpset.get;
   102 
   102 
   103 val change_simpset_of = change o GlobalSimpset.get;
   103 val change_simpset_of = change o GlobalSimpset.get;
   104 fun change_simpset f = change_simpset_of (Context.the_context ()) f;
   104 fun change_simpset f = change_simpset_of (Context.the_context ()) f;
   126   type T = simpset;
   126   type T = simpset;
   127   val init = get_simpset;
   127   val init = get_simpset;
   128   fun print _ ss = print_ss ss;
   128   fun print _ ss = print_ss ss;
   129 end);
   129 end);
   130 
   130 
   131 val _ = Context.add_setup [LocalSimpset.init];
   131 val _ = Context.add_setup LocalSimpset.init;
   132 val print_local_simpset = LocalSimpset.print;
   132 val print_local_simpset = LocalSimpset.print;
   133 val get_local_simpset = LocalSimpset.get;
   133 val get_local_simpset = LocalSimpset.get;
   134 val put_local_simpset = LocalSimpset.put;
   134 val put_local_simpset = LocalSimpset.put;
   135 
   135 
   136 fun local_simpset_of ctxt = MetaSimplifier.context ctxt (get_local_simpset ctxt);
   136 fun local_simpset_of ctxt = MetaSimplifier.context ctxt (get_local_simpset ctxt);
   258 
   258 
   259 
   259 
   260 (* setup attributes *)
   260 (* setup attributes *)
   261 
   261 
   262 val _ = Context.add_setup
   262 val _ = Context.add_setup
   263  [Attrib.add_attributes
   263  (Attrib.add_attributes
   264    [(simpN, Attrib.common (Attrib.add_del_args simp_add simp_del),
   264    [(simpN, Attrib.common (Attrib.add_del_args simp_add simp_del),
   265       "declaration of Simplifier rule"),
   265       "declaration of Simplifier rule"),
   266     (congN, Attrib.common (Attrib.add_del_args cong_add cong_del),
   266     (congN, Attrib.common (Attrib.add_del_args cong_add cong_del),
   267       "declaration of Simplifier congruence rule"),
   267       "declaration of Simplifier congruence rule"),
   268     ("simplified", Attrib.common simplified, "simplified rule")]];
   268     ("simplified", Attrib.common simplified, "simplified rule")]);
   269 
   269 
   270 
   270 
   271 
   271 
   272 (** proof methods **)
   272 (** proof methods **)
   273 
   273 
   316 fun simp_method' ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts =>
   316 fun simp_method' ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts =>
   317   HEADGOAL (Method.insert_tac (prems @ facts) THEN'
   317   HEADGOAL (Method.insert_tac (prems @ facts) THEN'
   318       ((FLAGS o CHANGED_PROP) oo tac) (local_simpset_of ctxt)));
   318       ((FLAGS o CHANGED_PROP) oo tac) (local_simpset_of ctxt)));
   319 
   319 
   320 
   320 
   321 (* setup methods *)
   321 
   322 
   322 (** setup **)
   323 fun setup_methods more_mods = Method.add_methods
   323 
       
   324 fun method_setup more_mods = Method.add_methods
   324  [(simpN, simp_args more_mods simp_method', "simplification"),
   325  [(simpN, simp_args more_mods simp_method', "simplification"),
   325   ("simp_all", simp_args more_mods simp_method, "simplification (all goals)")];
   326   ("simp_all", simp_args more_mods simp_method, "simplification (all goals)")];
   326 
   327 
   327 fun method_setup mods = [setup_methods mods];
   328 fun easy_setup reflect trivs = method_setup [] #> (fn thy =>
   328 
       
   329 
       
   330 (** easy_setup **)
       
   331 
       
   332 fun easy_setup reflect trivs =
       
   333   let
   329   let
   334     val trivialities = Drule.reflexive_thm :: trivs;
   330     val trivialities = Drule.reflexive_thm :: trivs;
   335 
   331 
   336     fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac];
   332     fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac];
   337     val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
   333     val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
   343     fun mk_eq thm =
   339     fun mk_eq thm =
   344       if Logic.is_equals (Thm.concl_of thm) then [thm]
   340       if Logic.is_equals (Thm.concl_of thm) then [thm]
   345       else [thm RS reflect] handle THM _ => [];
   341       else [thm RS reflect] handle THM _ => [];
   346 
   342 
   347     fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm);
   343     fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm);
   348 
   344   in
   349     fun init_ss thy =
   345     GlobalSimpset.get thy :=
   350       (GlobalSimpset.get thy :=
   346       empty_ss setsubgoaler asm_simp_tac
   351         empty_ss setsubgoaler asm_simp_tac
   347       setSSolver safe_solver
   352         setSSolver safe_solver
   348       setSolver unsafe_solver
   353         setSolver unsafe_solver
   349       setmksimps mksimps;
   354         setmksimps mksimps; thy);
   350     thy
   355   in method_setup [] @ [init_ss] end;
   351   end);
   356 
   352 
   357 
   353 
   358 open MetaSimplifier;
   354 open MetaSimplifier;
   359 
   355 
   360 end;
   356 end;