src/HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
author blanchet
Tue, 11 Sep 2012 13:06:13 +0200
changeset 50289 ddd606ec45b9
parent 50279 9059e0dbdbc1
child 50291 59fa53ed7507
permissions -rw-r--r--
first step towards splitting corecursor function arguments into (p, g, h) triples
blanchet@50138
     1
(*  Title:      HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
blanchet@50138
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@50138
     3
    Copyright   2012
blanchet@50138
     4
blanchet@50138
     5
Tactics for the LFP/GFP sugar.
blanchet@50138
     6
*)
blanchet@50138
     7
blanchet@50138
     8
signature BNF_FP_SUGAR_TACTICS =
blanchet@50138
     9
sig
blanchet@50145
    10
  val mk_case_tac: Proof.context -> int -> int -> int -> thm -> thm -> thm -> tactic
blanchet@50241
    11
  val mk_coiter_like_tac: thm list -> thm list -> thm -> thm -> thm -> Proof.context -> tactic
blanchet@50176
    12
  val mk_exhaust_tac: Proof.context -> int -> thm list -> thm -> thm -> tactic
blanchet@50138
    13
  val mk_fld_iff_unf_tac: Proof.context -> ctyp option list -> cterm -> cterm -> thm -> thm
blanchet@50138
    14
    -> tactic
blanchet@50142
    15
  val mk_half_distinct_tac: Proof.context -> thm -> thm list -> tactic
blanchet@50141
    16
  val mk_inject_tac: Proof.context -> thm -> thm -> tactic
blanchet@50241
    17
  val mk_iter_like_tac: thm list -> thm list -> thm list -> thm -> thm -> Proof.context -> tactic
blanchet@50138
    18
end;
blanchet@50138
    19
blanchet@50138
    20
structure BNF_FP_Sugar_Tactics : BNF_FP_SUGAR_TACTICS =
blanchet@50138
    21
struct
blanchet@50138
    22
blanchet@50140
    23
open BNF_Tactics
blanchet@50138
    24
open BNF_Util
blanchet@50279
    25
open BNF_FP_Util
blanchet@50138
    26
blanchet@50145
    27
fun mk_case_tac ctxt n k m case_def ctr_def unf_fld =
blanchet@50145
    28
  Local_Defs.unfold_tac ctxt [case_def, ctr_def, unf_fld] THEN
blanchet@50279
    29
  (rtac (mk_sum_casesN_balanced n k RS ssubst) THEN'
blanchet@50145
    30
   REPEAT_DETERM_N (Int.max (0, m - 1)) o rtac (@{thm split} RS ssubst) THEN'
blanchet@50145
    31
   rtac refl) 1;
blanchet@50145
    32
blanchet@50176
    33
fun mk_exhaust_tac ctxt n ctr_defs fld_iff_unf sumEN' =
blanchet@50278
    34
  Local_Defs.unfold_tac ctxt (fld_iff_unf :: ctr_defs) THEN rtac sumEN' 1 THEN
blanchet@50140
    35
  Local_Defs.unfold_tac ctxt @{thms all_prod_eq} THEN
blanchet@50176
    36
  EVERY' (maps (fn k => [select_prem_tac n (rotate_tac 1) k, REPEAT_DETERM o dtac @{thm meta_spec},
blanchet@50176
    37
    etac @{thm meta_mp}, atac]) (1 upto n)) 1;
blanchet@50140
    38
blanchet@50138
    39
fun mk_fld_iff_unf_tac ctxt cTs cfld cunf fld_unf unf_fld =
blanchet@50138
    40
  (rtac iffI THEN'
blanchet@50138
    41
   EVERY' (map3 (fn cTs => fn cx => fn th =>
blanchet@50138
    42
     dtac (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN'
blanchet@50138
    43
     SELECT_GOAL (Local_Defs.unfold_tac ctxt [th]) THEN'
blanchet@50138
    44
     atac) [rev cTs, cTs] [cunf, cfld] [unf_fld, fld_unf])) 1;
blanchet@50138
    45
blanchet@50142
    46
fun mk_half_distinct_tac ctxt fld_inject ctr_defs =
blanchet@50142
    47
  Local_Defs.unfold_tac ctxt (fld_inject :: @{thms sum.inject} @ ctr_defs) THEN
blanchet@50142
    48
  rtac @{thm sum.distinct(1)} 1;
blanchet@50142
    49
blanchet@50141
    50
fun mk_inject_tac ctxt ctr_def fld_inject =
blanchet@50150
    51
  Local_Defs.unfold_tac ctxt [ctr_def] THEN rtac (fld_inject RS ssubst) 1 THEN
blanchet@50150
    52
  Local_Defs.unfold_tac ctxt @{thms sum.inject Pair_eq conj_assoc} THEN rtac refl 1;
blanchet@50141
    53
blanchet@50226
    54
val iter_like_thms =
blanchet@50248
    55
  @{thms case_unit comp_def convol_def id_apply map_pair_def sum.simps(5,6) sum_map.simps
blanchet@50248
    56
      split_conv};
blanchet@50220
    57
blanchet@50244
    58
fun mk_iter_like_tac pre_map_defs map_ids iter_like_defs fld_iter_like ctr_def ctxt =
blanchet@50244
    59
  Local_Defs.unfold_tac ctxt (ctr_def :: fld_iter_like :: iter_like_defs @ pre_map_defs @ map_ids @
blanchet@50247
    60
    iter_like_thms) THEN Local_Defs.unfold_tac ctxt @{thms id_def} THEN rtac refl 1;
blanchet@50220
    61
blanchet@50228
    62
val coiter_like_ss = ss_only @{thms if_True if_False};
blanchet@50289
    63
val coiter_like_thms =
blanchet@50289
    64
  @{thms id_apply map_pair_def sum_case_if sum_map.simps sum_map_if prod.cases};
blanchet@50228
    65
blanchet@50244
    66
fun mk_coiter_like_tac coiter_like_defs map_ids fld_unf_coiter_like pre_map_def ctr_def ctxt =
blanchet@50228
    67
  Local_Defs.unfold_tac ctxt (ctr_def :: coiter_like_defs) THEN
blanchet@50241
    68
  subst_tac ctxt [fld_unf_coiter_like] 1 THEN asm_simp_tac coiter_like_ss 1 THEN
blanchet@50247
    69
  Local_Defs.unfold_tac ctxt (pre_map_def :: coiter_like_thms @ map_ids) THEN
blanchet@50250
    70
  Local_Defs.unfold_tac ctxt @{thms id_def} THEN
blanchet@50250
    71
  (rtac refl ORELSE' subst_tac ctxt @{thms unit_eq} THEN' rtac refl) 1;
blanchet@50228
    72
blanchet@50138
    73
end;