src/HOLCF/Tools/fixrec.ML
changeset 37080 a2a1c8a658ef
parent 37079 0cd15d8c90a0
child 37081 3e5146b93218
equal deleted inserted replaced
37079:0cd15d8c90a0 37080:a2a1c8a658ef
    11   val add_fixrec_cmd: bool -> (binding * string option * mixfix) list
    11   val add_fixrec_cmd: bool -> (binding * string option * mixfix) list
    12     -> (Attrib.binding * string) list -> local_theory -> local_theory
    12     -> (Attrib.binding * string) list -> local_theory -> local_theory
    13   val add_fixpat: Thm.binding * term list -> theory -> theory
    13   val add_fixpat: Thm.binding * term list -> theory -> theory
    14   val add_fixpat_cmd: Attrib.binding * string list -> theory -> theory
    14   val add_fixpat_cmd: Attrib.binding * string list -> theory -> theory
    15   val add_matchers: (string * string) list -> theory -> theory
    15   val add_matchers: (string * string) list -> theory -> theory
    16   val fixrec_simp_add: attribute
       
    17   val fixrec_simp_del: attribute
       
    18   val fixrec_simp_tac: Proof.context -> int -> tactic
    16   val fixrec_simp_tac: Proof.context -> int -> tactic
    19   val setup: theory -> theory
    17   val setup: theory -> theory
    20 end;
    18 end;
    21 
    19 
    22 structure Fixrec :> FIXREC =
    20 structure Fixrec :> FIXREC =
   302 
   300 
   303 (*************************************************************************)
   301 (*************************************************************************)
   304 (********************** Proving associated theorems **********************)
   302 (********************** Proving associated theorems **********************)
   305 (*************************************************************************)
   303 (*************************************************************************)
   306 
   304 
   307 structure FixrecSimpData = Generic_Data
   305 (* tactic to perform eta-contraction on subgoal *)
   308 (
   306 fun eta_tac (ctxt : Proof.context) : int -> tactic =
   309   type T = simpset;
   307   EqSubst.eqsubst_tac ctxt [0] @{thms refl};
   310   val empty = HOL_basic_ss addsimps simp_thms;
       
   311   val extend = I;
       
   312   val merge = merge_ss;
       
   313 );
       
   314 
   308 
   315 fun fixrec_simp_tac ctxt =
   309 fun fixrec_simp_tac ctxt =
   316   let
   310   let
   317     val tab = FixrecUnfoldData.get (Context.Proof ctxt);
   311     val tab = FixrecUnfoldData.get (Context.Proof ctxt);
   318     val ss = Simplifier.context ctxt (FixrecSimpData.get (Context.Proof ctxt));
   312     val ss = Simplifier.simpset_of ctxt;
   319     fun concl t =
   313     fun concl t =
   320       if Logic.is_all t then concl (snd (Logic.dest_all t))
   314       if Logic.is_all t then concl (snd (Logic.dest_all t))
   321       else HOLogic.dest_Trueprop (Logic.strip_imp_concl t);
   315       else HOLogic.dest_Trueprop (Logic.strip_imp_concl t);
   322     fun tac (t, i) =
   316     fun tac (t, i) =
   323       let
   317       let
   324         val (c, T) =
   318         val (c, T) =
   325             (dest_Const o head_of o chead_of o fst o HOLogic.dest_eq o concl) t;
   319             (dest_Const o head_of o chead_of o fst o HOLogic.dest_eq o concl) t;
   326         val unfold_thm = the (Symtab.lookup tab c);
   320         val unfold_thm = the (Symtab.lookup tab c);
   327         val rule = unfold_thm RS @{thm ssubst_lhs};
   321         val rule = unfold_thm RS @{thm ssubst_lhs};
   328       in
   322       in
   329         CHANGED (rtac rule i THEN asm_simp_tac ss i)
   323         CHANGED (rtac rule i THEN eta_tac ctxt i THEN asm_simp_tac ss i)
   330       end
   324       end
   331   in
   325   in
   332     SUBGOAL (fn ti => the_default no_tac (try tac ti))
   326     SUBGOAL (fn ti => the_default no_tac (try tac ti))
   333   end;
   327   end;
   334 
       
   335 val fixrec_simp_add : attribute =
       
   336   Thm.declaration_attribute
       
   337     (fn th => FixrecSimpData.map (fn ss => ss addsimps [th]));
       
   338 
       
   339 val fixrec_simp_del : attribute =
       
   340   Thm.declaration_attribute
       
   341     (fn th => FixrecSimpData.map (fn ss => ss delsimps [th]));
       
   342 
   328 
   343 (* proves a block of pattern matching equations as theorems, using unfold *)
   329 (* proves a block of pattern matching equations as theorems, using unfold *)
   344 fun make_simps ctxt (unfold_thm, eqns : (Attrib.binding * term) list) =
   330 fun make_simps ctxt (unfold_thm, eqns : (Attrib.binding * term) list) =
   345   let
   331   let
   346     val ss = Simplifier.context ctxt (FixrecSimpData.get (Context.Proof ctxt));
   332     val ss = Simplifier.simpset_of ctxt;
   347     val rule = unfold_thm RS @{thm ssubst_lhs};
   333     val rule = unfold_thm RS @{thm ssubst_lhs};
   348     val tac = rtac rule 1 THEN asm_simp_tac ss 1;
   334     val tac = rtac rule 1 THEN eta_tac ctxt 1 THEN asm_simp_tac ss 1;
   349     fun prove_term t = Goal.prove ctxt [] [] t (K tac);
   335     fun prove_term t = Goal.prove ctxt [] [] t (K tac);
   350     fun prove_eqn (bind, eqn_t) = (bind, prove_term eqn_t);
   336     fun prove_eqn (bind, eqn_t) = (bind, prove_term eqn_t);
   351   in
   337   in
   352     map prove_eqn eqns
   338     map prove_eqn eqns
   353   end;
   339   end;
   457 val _ =
   443 val _ =
   458   Outer_Syntax.command "fixpat" "define rewrites for fixrec functions" Keyword.thy_decl
   444   Outer_Syntax.command "fixpat" "define rewrites for fixrec functions" Keyword.thy_decl
   459     (Parse_Spec.specs >> (Toplevel.theory o add_fixpat_cmd));
   445     (Parse_Spec.specs >> (Toplevel.theory o add_fixpat_cmd));
   460 
   446 
   461 val setup =
   447 val setup =
   462   Attrib.setup @{binding fixrec_simp}
   448   Method.setup @{binding fixrec_simp}
   463                      (Attrib.add_del fixrec_simp_add fixrec_simp_del)
   449     (Scan.succeed (SIMPLE_METHOD' o fixrec_simp_tac))
   464                      "declaration of fixrec simp rule"
   450     "pattern prover for fixrec constants";
   465   #> Method.setup @{binding fixrec_simp}
       
   466                      (Scan.succeed (SIMPLE_METHOD' o fixrec_simp_tac))
       
   467                      "pattern prover for fixrec constants";
       
   468 
   451 
   469 end;
   452 end;