src/HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
author blanchet
Tue Sep 11 18:39:47 2012 +0200 (2012-09-11)
changeset 49286 dde4967c9233
parent 49276 59fa53ed7507
child 49362 1271aca16aed
permissions -rw-r--r--
added "defaults" option
blanchet@49123
     1
(*  Title:      HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
blanchet@49123
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@49123
     3
    Copyright   2012
blanchet@49123
     4
blanchet@49123
     5
Tactics for the LFP/GFP sugar.
blanchet@49123
     6
*)
blanchet@49123
     7
blanchet@49123
     8
signature BNF_FP_SUGAR_TACTICS =
blanchet@49123
     9
sig
blanchet@49130
    10
  val mk_case_tac: Proof.context -> int -> int -> int -> thm -> thm -> thm -> tactic
blanchet@49226
    11
  val mk_coiter_like_tac: thm list -> thm list -> thm -> thm -> thm -> Proof.context -> tactic
blanchet@49161
    12
  val mk_exhaust_tac: Proof.context -> int -> thm list -> thm -> thm -> tactic
blanchet@49123
    13
  val mk_fld_iff_unf_tac: Proof.context -> ctyp option list -> cterm -> cterm -> thm -> thm
blanchet@49123
    14
    -> tactic
blanchet@49127
    15
  val mk_half_distinct_tac: Proof.context -> thm -> thm list -> tactic
blanchet@49126
    16
  val mk_inject_tac: Proof.context -> thm -> thm -> tactic
blanchet@49226
    17
  val mk_iter_like_tac: thm list -> thm list -> thm list -> thm -> thm -> Proof.context -> tactic
blanchet@49123
    18
end;
blanchet@49123
    19
blanchet@49123
    20
structure BNF_FP_Sugar_Tactics : BNF_FP_SUGAR_TACTICS =
blanchet@49123
    21
struct
blanchet@49123
    22
blanchet@49125
    23
open BNF_Tactics
blanchet@49123
    24
open BNF_Util
blanchet@49264
    25
open BNF_FP_Util
blanchet@49123
    26
blanchet@49130
    27
fun mk_case_tac ctxt n k m case_def ctr_def unf_fld =
blanchet@49130
    28
  Local_Defs.unfold_tac ctxt [case_def, ctr_def, unf_fld] THEN
blanchet@49264
    29
  (rtac (mk_sum_casesN_balanced n k RS ssubst) THEN'
blanchet@49130
    30
   REPEAT_DETERM_N (Int.max (0, m - 1)) o rtac (@{thm split} RS ssubst) THEN'
blanchet@49130
    31
   rtac refl) 1;
blanchet@49130
    32
blanchet@49161
    33
fun mk_exhaust_tac ctxt n ctr_defs fld_iff_unf sumEN' =
blanchet@49263
    34
  Local_Defs.unfold_tac ctxt (fld_iff_unf :: ctr_defs) THEN rtac sumEN' 1 THEN
blanchet@49125
    35
  Local_Defs.unfold_tac ctxt @{thms all_prod_eq} THEN
blanchet@49161
    36
  EVERY' (maps (fn k => [select_prem_tac n (rotate_tac 1) k, REPEAT_DETERM o dtac @{thm meta_spec},
blanchet@49161
    37
    etac @{thm meta_mp}, atac]) (1 upto n)) 1;
blanchet@49125
    38
blanchet@49123
    39
fun mk_fld_iff_unf_tac ctxt cTs cfld cunf fld_unf unf_fld =
blanchet@49123
    40
  (rtac iffI THEN'
blanchet@49123
    41
   EVERY' (map3 (fn cTs => fn cx => fn th =>
blanchet@49123
    42
     dtac (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN'
blanchet@49123
    43
     SELECT_GOAL (Local_Defs.unfold_tac ctxt [th]) THEN'
blanchet@49123
    44
     atac) [rev cTs, cTs] [cunf, cfld] [unf_fld, fld_unf])) 1;
blanchet@49123
    45
blanchet@49127
    46
fun mk_half_distinct_tac ctxt fld_inject ctr_defs =
blanchet@49127
    47
  Local_Defs.unfold_tac ctxt (fld_inject :: @{thms sum.inject} @ ctr_defs) THEN
blanchet@49127
    48
  rtac @{thm sum.distinct(1)} 1;
blanchet@49127
    49
blanchet@49126
    50
fun mk_inject_tac ctxt ctr_def fld_inject =
blanchet@49135
    51
  Local_Defs.unfold_tac ctxt [ctr_def] THEN rtac (fld_inject RS ssubst) 1 THEN
blanchet@49135
    52
  Local_Defs.unfold_tac ctxt @{thms sum.inject Pair_eq conj_assoc} THEN rtac refl 1;
blanchet@49126
    53
blanchet@49211
    54
val iter_like_thms =
blanchet@49233
    55
  @{thms case_unit comp_def convol_def id_apply map_pair_def sum.simps(5,6) sum_map.simps
blanchet@49233
    56
      split_conv};
blanchet@49205
    57
blanchet@49229
    58
fun mk_iter_like_tac pre_map_defs map_ids iter_like_defs fld_iter_like ctr_def ctxt =
blanchet@49229
    59
  Local_Defs.unfold_tac ctxt (ctr_def :: fld_iter_like :: iter_like_defs @ pre_map_defs @ map_ids @
blanchet@49232
    60
    iter_like_thms) THEN Local_Defs.unfold_tac ctxt @{thms id_def} THEN rtac refl 1;
blanchet@49205
    61
blanchet@49213
    62
val coiter_like_ss = ss_only @{thms if_True if_False};
blanchet@49276
    63
val coiter_like_thms = @{thms id_apply map_pair_def sum_map.simps prod.cases};
blanchet@49213
    64
blanchet@49229
    65
fun mk_coiter_like_tac coiter_like_defs map_ids fld_unf_coiter_like pre_map_def ctr_def ctxt =
blanchet@49213
    66
  Local_Defs.unfold_tac ctxt (ctr_def :: coiter_like_defs) THEN
blanchet@49226
    67
  subst_tac ctxt [fld_unf_coiter_like] 1 THEN asm_simp_tac coiter_like_ss 1 THEN
blanchet@49232
    68
  Local_Defs.unfold_tac ctxt (pre_map_def :: coiter_like_thms @ map_ids) THEN
blanchet@49235
    69
  Local_Defs.unfold_tac ctxt @{thms id_def} THEN
blanchet@49235
    70
  (rtac refl ORELSE' subst_tac ctxt @{thms unit_eq} THEN' rtac refl) 1;
blanchet@49213
    71
blanchet@49123
    72
end;