author blanchet
Wed, 05 Sep 2012 11:08:18 +0200
changeset 49149 166f19b4677b
parent 49147 0da8120bd2aa
child 49160 056d6010b6d2
permissions -rw-r--r--
tell "select_prem_tac" not to thin any further premisses -- the "rotate_tac" otherwise confuses it

(*  Title:      HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
    Author:     Jasmin Blanchette, TU Muenchen
    Copyright   2012

Tactics for the LFP/GFP sugar.

  val mk_case_tac: Proof.context -> int -> int -> int -> thm -> thm -> thm -> tactic
  val mk_exhaust_tac: Proof.context -> int -> int list -> thm list -> thm -> thm -> tactic
  val mk_fld_iff_unf_tac: Proof.context -> ctyp option list -> cterm -> cterm -> thm -> thm
    -> tactic
  val mk_half_distinct_tac: Proof.context -> thm -> thm list -> tactic
  val mk_inject_tac: Proof.context -> thm -> thm -> tactic

structure BNF_FP_Sugar_Tactics : BNF_FP_SUGAR_TACTICS =

open BNF_Tactics
open BNF_Util

fun mk_case_tac ctxt n k m case_def ctr_def unf_fld =
  Local_Defs.unfold_tac ctxt [case_def, ctr_def, unf_fld] THEN
  (rtac (BNF_FP_Util.mk_sum_casesN n k RS ssubst) THEN'
   REPEAT_DETERM_N (Int.max (0, m - 1)) o rtac (@{thm split} RS ssubst) THEN'
   rtac refl) 1;

fun mk_exhaust_tac ctxt n ms ctr_defs fld_iff_unf sumEN' =
  Local_Defs.unfold_tac ctxt (fld_iff_unf :: ctr_defs) THEN rtac sumEN' 1 THEN
  Local_Defs.unfold_tac ctxt @{thms all_prod_eq} THEN
  EVERY' (map2 (fn k => fn m =>
    select_prem_tac k (REPEAT_DETERM_N m o dtac @{thm meta_spec} THEN' rotate_tac ~1 THEN'
      etac @{thm meta_mp}) k THEN' atac) (1 upto n) ms) 1;

fun mk_fld_iff_unf_tac ctxt cTs cfld cunf fld_unf unf_fld =
  (rtac iffI THEN'
   EVERY' (map3 (fn cTs => fn cx => fn th =>
     dtac (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN'
     SELECT_GOAL (Local_Defs.unfold_tac ctxt [th]) THEN'
     atac) [rev cTs, cTs] [cunf, cfld] [unf_fld, fld_unf])) 1;

fun mk_half_distinct_tac ctxt fld_inject ctr_defs =
  Local_Defs.unfold_tac ctxt (fld_inject :: @{thms sum.inject} @ ctr_defs) THEN
  rtac @{thm sum.distinct(1)} 1;

fun mk_inject_tac ctxt ctr_def fld_inject =
  Local_Defs.unfold_tac ctxt [ctr_def] THEN rtac (fld_inject RS ssubst) 1 THEN
  Local_Defs.unfold_tac ctxt @{thms sum.inject Pair_eq conj_assoc} THEN rtac refl 1;