src/HOL/Codatatype/Tools/bnf_comp_tactics.ML
author blanchet
Tue Sep 11 18:39:47 2012 +0200 (2012-09-11)
changeset 49286 dde4967c9233
parent 49284 5f39b7940b49
child 49304 6964373dd6ac
permissions -rw-r--r--
added "defaults" option
blanchet@48975
     1
(*  Title:      HOL/Codatatype/Tools/bnf_comp_tactics.ML
blanchet@48975
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@48975
     3
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@48975
     4
    Copyright   2012
blanchet@48975
     5
blanchet@48975
     6
Tactics for composition of bounded natural functors.
blanchet@48975
     7
*)
blanchet@48975
     8
blanchet@48975
     9
signature BNF_COMP_TACTICS =
blanchet@48975
    10
sig
blanchet@48975
    11
  val mk_comp_bd_card_order_tac: thm list -> thm -> tactic
blanchet@48975
    12
  val mk_comp_bd_cinfinite_tac: thm -> thm -> tactic
blanchet@48975
    13
  val mk_comp_in_alt_tac: Proof.context -> thm list -> tactic
blanchet@48975
    14
  val mk_comp_in_bd_tac: thm -> thm list -> thm -> thm list -> thm -> tactic
blanchet@48975
    15
  val mk_comp_map_comp_tac: thm -> thm -> thm list -> tactic
blanchet@48975
    16
  val mk_comp_map_cong_tac: thm list -> thm -> thm list -> tactic
blanchet@48975
    17
  val mk_comp_set_alt_tac: Proof.context -> thm -> tactic
blanchet@48975
    18
  val mk_comp_set_bd_tac: Proof.context -> thm -> thm list -> tactic
blanchet@48975
    19
  val mk_comp_set_natural_tac: thm -> thm -> thm -> thm list -> tactic
blanchet@48975
    20
  val mk_comp_wit_tac: Proof.context -> thm list -> thm -> thm list -> tactic
blanchet@48975
    21
blanchet@48975
    22
  val mk_killN_bd_card_order_tac: int -> thm -> tactic
blanchet@48975
    23
  val mk_killN_bd_cinfinite_tac: thm -> tactic
blanchet@48975
    24
  val killN_in_alt_tac: tactic
blanchet@48975
    25
  val mk_killN_in_bd_tac: int -> bool -> thm -> thm -> thm -> thm -> thm -> tactic
blanchet@48975
    26
  val mk_killN_map_cong_tac: Proof.context -> int -> int -> thm -> tactic
blanchet@48975
    27
  val mk_killN_set_bd_tac: thm -> thm -> tactic
blanchet@48975
    28
blanchet@48975
    29
  val empty_natural_tac: tactic
blanchet@48975
    30
  val liftN_in_alt_tac: tactic
blanchet@48975
    31
  val mk_liftN_in_bd_tac: int -> thm -> thm -> thm -> tactic
blanchet@48975
    32
  val mk_liftN_set_bd_tac: thm -> tactic
blanchet@48975
    33
blanchet@48975
    34
  val mk_permute_in_alt_tac: ''a list -> ''a list -> tactic
blanchet@48975
    35
  val mk_permute_in_bd_tac: ''a list -> ''a list -> thm -> thm -> thm -> tactic
blanchet@49284
    36
blanchet@49284
    37
  val mk_map_wpull_tac: thm -> thm list -> thm -> tactic
blanchet@49284
    38
  val mk_simple_wit_tac: thm list -> tactic
blanchet@48975
    39
end;
blanchet@48975
    40
blanchet@48975
    41
structure BNF_Comp_Tactics : BNF_COMP_TACTICS =
blanchet@48975
    42
struct
blanchet@48975
    43
blanchet@48975
    44
open BNF_Util
blanchet@48975
    45
open BNF_Tactics
blanchet@48975
    46
blanchet@48975
    47
val arg_cong_Union = @{thm arg_cong[of _ _ Union]};
blanchet@48975
    48
val o_eq_dest_lhs = @{thm o_eq_dest_lhs};
blanchet@48975
    49
val set_mp = @{thm set_mp};
blanchet@48975
    50
val trans_image_cong_o_apply = @{thm trans[OF image_cong[OF o_apply refl]]};
blanchet@48975
    51
val trans_o_apply = @{thm trans[OF o_apply]};
blanchet@48975
    52
blanchet@48975
    53
blanchet@48975
    54
blanchet@48975
    55
(* Composition *)
blanchet@48975
    56
blanchet@48975
    57
fun mk_comp_set_alt_tac ctxt collect_set_natural =
blanchet@48975
    58
  Local_Defs.unfold_tac ctxt @{thms sym[OF o_assoc]} THEN
blanchet@48975
    59
  Local_Defs.unfold_tac ctxt [collect_set_natural RS sym] THEN
blanchet@48975
    60
  rtac refl 1;
blanchet@48975
    61
blanchet@48975
    62
fun mk_comp_map_comp_tac Gmap_comp Gmap_cong map_comps =
blanchet@48975
    63
  EVERY' ([rtac ext, rtac sym, rtac trans_o_apply,
blanchet@48975
    64
    rtac (Gmap_comp RS sym RS o_eq_dest_lhs RS trans), rtac Gmap_cong] @
blanchet@48975
    65
    map (fn thm => rtac (thm RS sym RS fun_cong)) map_comps) 1;
blanchet@48975
    66
blanchet@48975
    67
fun mk_comp_set_natural_tac Gmap_comp Gmap_cong Gset_natural set_naturals =
blanchet@48975
    68
  EVERY' ([rtac ext] @
blanchet@48975
    69
    replicate 3 (rtac trans_o_apply) @
blanchet@48975
    70
    [rtac (arg_cong_Union RS trans),
blanchet@48975
    71
     rtac (@{thm arg_cong2[of _ _ _ _ collect, OF refl]} RS trans),
blanchet@48975
    72
     rtac (Gmap_comp RS sym RS o_eq_dest_lhs RS trans),
blanchet@48975
    73
     rtac Gmap_cong] @
blanchet@48975
    74
     map (fn thm => rtac (thm RS fun_cong)) set_naturals @
blanchet@48975
    75
     [rtac (Gset_natural RS o_eq_dest_lhs), rtac sym, rtac trans_o_apply,
blanchet@48975
    76
     rtac trans_image_cong_o_apply, rtac trans_image_cong_o_apply,
blanchet@48975
    77
     rtac (@{thm image_cong} OF [Gset_natural RS o_eq_dest_lhs RS arg_cong_Union, refl] RS trans),
blanchet@48975
    78
     rtac @{thm trans[OF pointfreeE[OF Union_natural[symmetric]]]}, rtac arg_cong_Union,
blanchet@48975
    79
     rtac @{thm trans[OF o_eq_dest_lhs[OF image_o_collect[symmetric]]]},
blanchet@48975
    80
     rtac @{thm fun_cong[OF arg_cong[of _ _ collect]]}] @
blanchet@48975
    81
     [REPEAT_DETERM_N (length set_naturals) o EVERY' [rtac @{thm trans[OF image_insert]},
blanchet@48975
    82
        rtac @{thm arg_cong2[of _ _ _ _ insert]}, rtac ext, rtac trans_o_apply,
blanchet@48975
    83
        rtac @{thm trans[OF image_cong[OF o_apply refl]]}, rtac @{thm trans[OF image_image]},
blanchet@48975
    84
        rtac @{thm sym[OF trans[OF o_apply]]}, rtac @{thm image_cong[OF refl o_apply]}],
blanchet@48975
    85
     rtac @{thm image_empty}]) 1;
blanchet@48975
    86
blanchet@48975
    87
fun mk_comp_map_cong_tac comp_set_alts map_cong map_congs =
blanchet@48975
    88
  let
blanchet@48975
    89
     val n = length comp_set_alts;
blanchet@48975
    90
  in
blanchet@48975
    91
    (if n = 0 then rtac refl 1
blanchet@48975
    92
    else rtac map_cong 1 THEN
blanchet@48975
    93
      EVERY' (map_index (fn (i, map_cong) =>
blanchet@48975
    94
        rtac map_cong THEN' EVERY' (map_index (fn (k, set_alt) =>
blanchet@48975
    95
          EVERY' [select_prem_tac n (dtac @{thm meta_spec}) (k + 1), etac @{thm meta_mp},
blanchet@48975
    96
            rtac (equalityD2 RS set_mp), rtac (set_alt RS fun_cong RS trans),
blanchet@48975
    97
            rtac trans_o_apply, rtac (@{thm collect_def} RS arg_cong_Union),
blanchet@48975
    98
            rtac @{thm UnionI}, rtac @{thm UN_I}, REPEAT_DETERM_N i o rtac @{thm insertI2},
blanchet@48975
    99
            rtac @{thm insertI1}, rtac (o_apply RS equalityD2 RS set_mp),
blanchet@48975
   100
            etac @{thm imageI}, atac])
blanchet@48975
   101
          comp_set_alts))
blanchet@48975
   102
      map_congs) 1)
blanchet@48975
   103
  end;
blanchet@48975
   104
blanchet@48975
   105
fun mk_comp_bd_card_order_tac Fbd_card_orders Gbd_card_order =
blanchet@48975
   106
  let
blanchet@48975
   107
    val (card_orders, last_card_order) = split_last Fbd_card_orders;
blanchet@48975
   108
    fun gen_before thm = rtac @{thm card_order_csum} THEN' rtac thm;
blanchet@48975
   109
  in
blanchet@48975
   110
    (rtac @{thm card_order_cprod} THEN'
blanchet@48975
   111
    WRAP' gen_before (K (K all_tac)) card_orders (rtac last_card_order) THEN'
blanchet@48975
   112
    rtac Gbd_card_order) 1
blanchet@48975
   113
  end;
blanchet@48975
   114
blanchet@48975
   115
fun mk_comp_bd_cinfinite_tac Fbd_cinfinite Gbd_cinfinite =
blanchet@48975
   116
  (rtac @{thm cinfinite_cprod} THEN'
blanchet@48975
   117
   ((K (TRY ((rtac @{thm cinfinite_csum} THEN' rtac disjI1) 1)) THEN'
blanchet@48975
   118
     ((rtac @{thm cinfinite_csum} THEN' rtac disjI1 THEN' rtac Fbd_cinfinite) ORELSE'
blanchet@48975
   119
      rtac Fbd_cinfinite)) ORELSE'
blanchet@48975
   120
    rtac Fbd_cinfinite) THEN'
blanchet@48975
   121
   rtac Gbd_cinfinite) 1;
blanchet@48975
   122
blanchet@48975
   123
fun mk_comp_set_bd_tac ctxt comp_set_alt Gset_Fset_bds =
blanchet@48975
   124
  let
blanchet@48975
   125
    val (bds, last_bd) = split_last Gset_Fset_bds;
blanchet@48975
   126
    fun gen_before bd =
blanchet@48975
   127
      rtac ctrans THEN' rtac @{thm Un_csum} THEN'
blanchet@48975
   128
      rtac ctrans THEN' rtac @{thm csum_mono} THEN'
blanchet@48975
   129
      rtac bd;
blanchet@48975
   130
    fun gen_after _ = rtac @{thm ordIso_imp_ordLeq} THEN' rtac @{thm cprod_csum_distrib1};
blanchet@48975
   131
  in
blanchet@48975
   132
    Local_Defs.unfold_tac ctxt [comp_set_alt] THEN
blanchet@48975
   133
    rtac @{thm comp_set_bd_Union_o_collect} 1 THEN
blanchet@48975
   134
    Local_Defs.unfold_tac ctxt @{thms Union_image_insert Union_image_empty Union_Un_distrib
blanchet@48975
   135
      o_apply} THEN
blanchet@48975
   136
    (rtac ctrans THEN'
blanchet@48975
   137
     WRAP' gen_before gen_after bds (rtac last_bd) THEN'
blanchet@48975
   138
     rtac @{thm ordIso_imp_ordLeq} THEN'
blanchet@48975
   139
     rtac @{thm cprod_com}) 1
blanchet@48975
   140
  end;
blanchet@48975
   141
blanchet@48975
   142
val comp_in_alt_thms = @{thms o_apply collect_def SUP_def image_insert image_empty Union_insert
blanchet@48975
   143
  Union_empty Un_empty_right Union_Un_distrib Un_subset_iff conj_subset_def UN_image_subset
blanchet@48975
   144
  conj_assoc};
blanchet@48975
   145
blanchet@48975
   146
fun mk_comp_in_alt_tac ctxt comp_set_alts =
blanchet@48975
   147
  Local_Defs.unfold_tac ctxt (comp_set_alts @ comp_in_alt_thms) THEN
blanchet@48975
   148
  Local_Defs.unfold_tac ctxt @{thms set_eq_subset} THEN
blanchet@48975
   149
  rtac conjI 1 THEN
blanchet@48975
   150
  REPEAT_DETERM (
blanchet@48975
   151
    rtac @{thm subsetI} 1 THEN
blanchet@48975
   152
    Local_Defs.unfold_tac ctxt @{thms mem_Collect_eq Ball_def} THEN
blanchet@48975
   153
    (REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
blanchet@48975
   154
     REPEAT_DETERM (CHANGED ((
blanchet@48975
   155
       (rtac conjI THEN' (atac ORELSE' rtac @{thm subset_UNIV})) ORELSE'
blanchet@48975
   156
       atac ORELSE'
blanchet@48975
   157
       (rtac @{thm subset_UNIV})) 1)) ORELSE rtac @{thm subset_UNIV} 1));
blanchet@48975
   158
blanchet@48975
   159
fun mk_comp_in_bd_tac comp_in_alt Fin_bds Gin_bd Fbd_Cinfs Gbd_Card_order =
blanchet@48975
   160
  let
blanchet@48975
   161
    val (bds, last_bd) = split_last Fin_bds;
blanchet@48975
   162
    val (Cinfs, _) = split_last Fbd_Cinfs;
blanchet@48975
   163
    fun gen_before (bd, _) = rtac ctrans THEN' rtac @{thm csum_mono} THEN' rtac bd;
blanchet@48975
   164
    fun gen_after (_, (bd_Cinf, next_bd_Cinf)) =
blanchet@48975
   165
      TRY o (rtac @{thm csum_cexp} THEN'
blanchet@48975
   166
        rtac bd_Cinf THEN'
blanchet@48975
   167
        (TRY o (rtac @{thm Cinfinite_csum} THEN' rtac disjI1) THEN' rtac next_bd_Cinf ORELSE'
blanchet@48975
   168
           rtac next_bd_Cinf) THEN'
blanchet@48975
   169
        ((rtac @{thm Card_order_csum} THEN' rtac @{thm ordLeq_csum2}) ORELSE'
blanchet@48975
   170
          (rtac @{thm Card_order_ctwo} THEN' rtac @{thm ordLeq_refl})) THEN'
blanchet@48975
   171
        rtac @{thm Card_order_ctwo});
blanchet@48975
   172
  in
blanchet@48975
   173
    (rtac @{thm ordIso_ordLeq_trans} THEN'
blanchet@48975
   174
     rtac @{thm card_of_ordIso_subst} THEN'
blanchet@48975
   175
     rtac comp_in_alt THEN'
blanchet@48975
   176
     rtac ctrans THEN'
blanchet@48975
   177
     rtac Gin_bd THEN'
blanchet@48975
   178
     rtac @{thm ordLeq_ordIso_trans} THEN'
blanchet@48975
   179
     rtac @{thm cexp_mono1} THEN'
blanchet@48975
   180
     rtac @{thm ordLeq_ordIso_trans} THEN'
blanchet@48975
   181
     rtac @{thm csum_mono1} THEN'
blanchet@48975
   182
     WRAP' gen_before gen_after (bds ~~ (Cinfs ~~ tl Fbd_Cinfs)) (rtac last_bd) THEN'
blanchet@48975
   183
     rtac @{thm csum_absorb1} THEN'
blanchet@48975
   184
     rtac @{thm Cinfinite_cexp} THEN'
blanchet@48975
   185
     (rtac @{thm ordLeq_csum2} ORELSE' rtac @{thm ordLeq_refl}) THEN'
blanchet@48975
   186
     rtac @{thm Card_order_ctwo} THEN'
blanchet@48975
   187
     (TRY o (rtac @{thm Cinfinite_csum} THEN' rtac disjI1) THEN' rtac (hd Fbd_Cinfs) ORELSE'
blanchet@48975
   188
       rtac (hd Fbd_Cinfs)) THEN'
blanchet@48975
   189
     rtac @{thm ctwo_ordLeq_Cinfinite} THEN'
blanchet@48975
   190
     rtac @{thm Cinfinite_cexp} THEN'
blanchet@48975
   191
     (rtac @{thm ordLeq_csum2} ORELSE' rtac @{thm ordLeq_refl}) THEN'
blanchet@48975
   192
     rtac @{thm Card_order_ctwo} THEN'
blanchet@48975
   193
     (TRY o (rtac @{thm Cinfinite_csum} THEN' rtac disjI1) THEN' rtac (hd Fbd_Cinfs) ORELSE'
blanchet@48975
   194
       rtac (hd Fbd_Cinfs)) THEN'
blanchet@48975
   195
     rtac disjI1 THEN'
blanchet@48975
   196
     TRY o rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   197
     rtac @{thm ctwo_Cnotzero} THEN'
blanchet@48975
   198
     rtac Gbd_Card_order THEN'
blanchet@48975
   199
     rtac @{thm cexp_cprod} THEN'
blanchet@48975
   200
     TRY o rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   201
     rtac @{thm ctwo_Cnotzero}) 1
blanchet@48975
   202
  end;
blanchet@48975
   203
blanchet@48975
   204
val comp_wit_thms = @{thms Union_empty_conv o_apply collect_def SUP_def
blanchet@48975
   205
  Union_image_insert Union_image_empty};
blanchet@48975
   206
blanchet@48975
   207
fun mk_comp_wit_tac ctxt Gwit_thms collect_set_natural Fwit_thms =
blanchet@48975
   208
  ALLGOALS (dtac @{thm in_Union_o_assoc}) THEN
blanchet@48975
   209
  Local_Defs.unfold_tac ctxt (collect_set_natural :: comp_wit_thms) THEN
blanchet@48975
   210
  REPEAT_DETERM (
blanchet@48975
   211
    atac 1 ORELSE
blanchet@48975
   212
    REPEAT_DETERM (eresolve_tac @{thms UnionE UnE imageE} 1) THEN
blanchet@48975
   213
    (TRY o dresolve_tac Gwit_thms THEN'
blanchet@48975
   214
    (etac FalseE ORELSE'
blanchet@48975
   215
    hyp_subst_tac THEN'
blanchet@48975
   216
    dresolve_tac Fwit_thms THEN'
blanchet@48975
   217
    (etac FalseE ORELSE' atac))) 1);
blanchet@48975
   218
blanchet@48975
   219
blanchet@48975
   220
blanchet@48975
   221
(* Kill operation *)
blanchet@48975
   222
blanchet@48975
   223
fun mk_killN_map_cong_tac ctxt n m map_cong =
blanchet@48975
   224
  (rtac map_cong THEN' EVERY' (replicate n (rtac refl)) THEN'
blanchet@48975
   225
    EVERY' (replicate m (Goal.assume_rule_tac ctxt))) 1;
blanchet@48975
   226
blanchet@48975
   227
fun mk_killN_bd_card_order_tac n bd_card_order =
blanchet@48975
   228
  (rtac @{thm card_order_cprod} THEN'
blanchet@48975
   229
  K (REPEAT_DETERM_N (n - 1)
blanchet@48975
   230
    ((rtac @{thm card_order_csum} THEN'
blanchet@48975
   231
    rtac @{thm card_of_card_order_on}) 1)) THEN'
blanchet@48975
   232
  rtac @{thm card_of_card_order_on} THEN'
blanchet@48975
   233
  rtac bd_card_order) 1;
blanchet@48975
   234
blanchet@48975
   235
fun mk_killN_bd_cinfinite_tac bd_Cinfinite =
blanchet@48975
   236
  (rtac @{thm cinfinite_cprod2} THEN'
blanchet@48975
   237
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   238
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   239
  rtac bd_Cinfinite) 1;
blanchet@48975
   240
blanchet@48975
   241
fun mk_killN_set_bd_tac bd_Card_order set_bd =
blanchet@48975
   242
  (rtac ctrans THEN'
blanchet@48975
   243
  rtac set_bd THEN'
blanchet@48975
   244
  rtac @{thm ordLeq_cprod2} THEN'
blanchet@48975
   245
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   246
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   247
  rtac bd_Card_order) 1
blanchet@48975
   248
blanchet@48975
   249
val killN_in_alt_tac =
blanchet@48975
   250
  ((rtac @{thm Collect_cong} THEN' rtac @{thm iffI}) 1 THEN
blanchet@48975
   251
  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
blanchet@48975
   252
  REPEAT_DETERM (CHANGED ((etac conjI ORELSE'
blanchet@48975
   253
    rtac conjI THEN' rtac @{thm subset_UNIV}) 1)) THEN
blanchet@48975
   254
  (rtac @{thm subset_UNIV} ORELSE' atac) 1 THEN
blanchet@48975
   255
  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
blanchet@48975
   256
  REPEAT_DETERM (CHANGED ((etac conjI ORELSE' atac) 1))) ORELSE
blanchet@48975
   257
  ((rtac @{thm UNIV_eq_I} THEN' rtac CollectI) 1 THEN
blanchet@48975
   258
    REPEAT_DETERM (TRY (rtac conjI 1) THEN rtac @{thm subset_UNIV} 1));
blanchet@48975
   259
blanchet@48975
   260
fun mk_killN_in_bd_tac n nontrivial_killN_in in_alt in_bd bd_Card_order bd_Cinfinite bd_Cnotzero =
blanchet@48975
   261
  (rtac @{thm ordIso_ordLeq_trans} THEN'
blanchet@48975
   262
  rtac @{thm card_of_ordIso_subst} THEN'
blanchet@48975
   263
  rtac in_alt THEN'
blanchet@48975
   264
  rtac ctrans THEN'
blanchet@48975
   265
  rtac in_bd THEN'
blanchet@48975
   266
  rtac @{thm ordIso_ordLeq_trans} THEN'
blanchet@48975
   267
  rtac @{thm cexp_cong1}) 1 THEN
blanchet@48975
   268
  (if nontrivial_killN_in then
blanchet@48975
   269
    rtac @{thm ordIso_transitive} 1 THEN
blanchet@48975
   270
    REPEAT_DETERM_N (n - 1)
blanchet@48975
   271
      ((rtac @{thm csum_cong1} THEN'
blanchet@48975
   272
      rtac @{thm ordIso_symmetric} THEN'
blanchet@48975
   273
      rtac @{thm csum_assoc} THEN'
blanchet@48975
   274
      rtac @{thm ordIso_transitive}) 1) THEN
blanchet@48975
   275
    (rtac @{thm ordIso_refl} THEN'
blanchet@48975
   276
    rtac @{thm Card_order_csum} THEN'
blanchet@48975
   277
    rtac @{thm ordIso_transitive} THEN'
blanchet@48975
   278
    rtac @{thm csum_assoc} THEN'
blanchet@48975
   279
    rtac @{thm ordIso_transitive} THEN'
blanchet@48975
   280
    rtac @{thm csum_cong1} THEN'
blanchet@48975
   281
    K (mk_flatten_assoc_tac
blanchet@48975
   282
      (rtac @{thm ordIso_refl} THEN'
blanchet@48975
   283
        FIRST' [rtac @{thm card_of_Card_order}, rtac @{thm Card_order_csum}])
blanchet@48975
   284
      @{thm ordIso_transitive} @{thm csum_assoc} @{thm csum_cong}) THEN'
blanchet@48975
   285
    rtac @{thm ordIso_refl} THEN'
blanchet@48975
   286
    (rtac @{thm card_of_Card_order} ORELSE' rtac @{thm Card_order_csum})) 1
blanchet@48975
   287
  else all_tac) THEN
blanchet@48975
   288
  (rtac @{thm csum_com} THEN'
blanchet@48975
   289
  rtac bd_Card_order THEN'
blanchet@48975
   290
  rtac disjI1 THEN'
blanchet@48975
   291
  rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   292
  rtac @{thm ctwo_Cnotzero} THEN'
blanchet@48975
   293
  rtac disjI1 THEN'
blanchet@48975
   294
  rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   295
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   296
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   297
  rtac @{thm ordLeq_ordIso_trans} THEN'
blanchet@48975
   298
  rtac @{thm cexp_mono1} THEN'
blanchet@48975
   299
  rtac ctrans THEN'
blanchet@48975
   300
  rtac @{thm csum_mono2} THEN'
blanchet@48975
   301
  rtac @{thm ordLeq_cprod1} THEN'
blanchet@48975
   302
  (rtac @{thm card_of_Card_order} ORELSE' rtac @{thm Card_order_csum}) THEN'
blanchet@48975
   303
  rtac bd_Cnotzero THEN'
blanchet@48975
   304
  rtac @{thm csum_cexp'} THEN'
blanchet@48975
   305
  rtac @{thm Cinfinite_cprod2} THEN'
blanchet@48975
   306
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   307
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   308
  rtac bd_Cinfinite THEN'
blanchet@48975
   309
  ((rtac @{thm Card_order_ctwo} THEN' rtac @{thm ordLeq_refl}) ORELSE'
blanchet@48975
   310
    (rtac @{thm Card_order_csum} THEN' rtac @{thm ordLeq_csum2})) THEN'
blanchet@48975
   311
  rtac @{thm Card_order_ctwo} THEN'
blanchet@48975
   312
  rtac disjI1 THEN'
blanchet@48975
   313
  rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   314
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   315
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   316
  rtac bd_Card_order THEN'
blanchet@48975
   317
  rtac @{thm cexp_cprod_ordLeq} THEN'
blanchet@48975
   318
  TRY o rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   319
  rtac @{thm ctwo_Cnotzero} THEN'
blanchet@48975
   320
  rtac @{thm Cinfinite_cprod2} THEN'
blanchet@48975
   321
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   322
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   323
  rtac bd_Cinfinite THEN'
blanchet@48975
   324
  rtac bd_Cnotzero THEN'
blanchet@48975
   325
  rtac @{thm ordLeq_cprod2} THEN'
blanchet@48975
   326
  TRY o rtac @{thm csum_Cnotzero1} THEN'
blanchet@48975
   327
  rtac @{thm Cnotzero_UNIV} THEN'
blanchet@48975
   328
  rtac bd_Card_order) 1;
blanchet@48975
   329
blanchet@48975
   330
blanchet@48975
   331
blanchet@48975
   332
(* Lift operation *)
blanchet@48975
   333
blanchet@48975
   334
val empty_natural_tac = rtac @{thm empty_natural} 1;
blanchet@48975
   335
blanchet@48975
   336
fun mk_liftN_set_bd_tac bd_Card_order = (rtac @{thm Card_order_empty} THEN' rtac bd_Card_order) 1;
blanchet@48975
   337
blanchet@48975
   338
val liftN_in_alt_tac =
blanchet@48975
   339
  ((rtac @{thm Collect_cong} THEN' rtac @{thm iffI}) 1 THEN
blanchet@48975
   340
  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
blanchet@48975
   341
  REPEAT_DETERM (CHANGED ((etac conjI ORELSE' atac) 1)) THEN
blanchet@48975
   342
  REPEAT_DETERM (CHANGED (etac conjE 1)) THEN
blanchet@48975
   343
  REPEAT_DETERM (CHANGED ((etac conjI ORELSE'
blanchet@48975
   344
    rtac conjI THEN' rtac @{thm empty_subsetI}) 1)) THEN
blanchet@48975
   345
  (rtac @{thm empty_subsetI} ORELSE' atac) 1) ORELSE
blanchet@48975
   346
  ((rtac sym THEN' rtac @{thm UNIV_eq_I} THEN' rtac CollectI) 1 THEN
blanchet@48975
   347
    REPEAT_DETERM (TRY (rtac conjI 1) THEN rtac @{thm empty_subsetI} 1));
blanchet@48975
   348
blanchet@48975
   349
fun mk_liftN_in_bd_tac n in_alt in_bd bd_Card_order =
blanchet@48975
   350
  (rtac @{thm ordIso_ordLeq_trans} THEN'
blanchet@48975
   351
  rtac @{thm card_of_ordIso_subst} THEN'
blanchet@48975
   352
  rtac in_alt THEN'
blanchet@48975
   353
  rtac ctrans THEN'
blanchet@48975
   354
  rtac in_bd THEN'
blanchet@48975
   355
  rtac @{thm cexp_mono1}) 1 THEN
blanchet@48975
   356
  ((rtac @{thm csum_mono1} 1 THEN
blanchet@48975
   357
  REPEAT_DETERM_N (n - 1)
blanchet@48975
   358
    ((rtac ctrans THEN'
blanchet@48975
   359
    rtac @{thm ordLeq_csum2} THEN'
blanchet@48975
   360
    (rtac @{thm Card_order_csum} ORELSE' rtac @{thm card_of_Card_order})) 1) THEN
blanchet@48975
   361
  (rtac @{thm ordLeq_csum2} THEN'
blanchet@48975
   362
  (rtac @{thm Card_order_csum} ORELSE' rtac @{thm card_of_Card_order})) 1) ORELSE
blanchet@48975
   363
  (rtac @{thm ordLeq_csum2} THEN' rtac @{thm Card_order_ctwo}) 1) THEN
blanchet@48975
   364
  (rtac disjI1 THEN' TRY o rtac @{thm csum_Cnotzero2} THEN' rtac @{thm ctwo_Cnotzero}
blanchet@48975
   365
   THEN' rtac bd_Card_order) 1;
blanchet@48975
   366
blanchet@48975
   367
blanchet@48975
   368
blanchet@48975
   369
(* Permute operation *)
blanchet@48975
   370
blanchet@48975
   371
fun mk_permute_in_alt_tac src dest =
blanchet@48975
   372
  (rtac @{thm Collect_cong} THEN'
blanchet@48975
   373
  mk_rotate_eq_tac (rtac refl) trans @{thm conj_assoc} @{thm conj_commute} @{thm conj_cong}
blanchet@48975
   374
    dest src) 1;
blanchet@48975
   375
blanchet@48975
   376
fun mk_permute_in_bd_tac src dest in_alt in_bd bd_Card_order =
blanchet@48975
   377
  (rtac @{thm ordIso_ordLeq_trans} THEN'
blanchet@48975
   378
  rtac @{thm card_of_ordIso_subst} THEN'
blanchet@48975
   379
  rtac in_alt THEN'
blanchet@48975
   380
  rtac @{thm ordLeq_ordIso_trans} THEN'
blanchet@48975
   381
  rtac in_bd THEN'
blanchet@48975
   382
  rtac @{thm cexp_cong1} THEN'
blanchet@48975
   383
  rtac @{thm csum_cong1} THEN'
blanchet@48975
   384
  mk_rotate_eq_tac
blanchet@48975
   385
    (rtac @{thm ordIso_refl} THEN'
blanchet@48975
   386
      FIRST' [rtac @{thm card_of_Card_order}, rtac @{thm Card_order_csum}])
blanchet@48975
   387
    @{thm ordIso_transitive} @{thm csum_assoc} @{thm csum_com} @{thm csum_cong}
blanchet@48975
   388
    src dest THEN'
blanchet@48975
   389
  rtac bd_Card_order THEN'
blanchet@48975
   390
  rtac disjI1 THEN'
blanchet@48975
   391
  TRY o rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   392
  rtac @{thm ctwo_Cnotzero} THEN'
blanchet@48975
   393
  rtac disjI1 THEN'
blanchet@48975
   394
  TRY o rtac @{thm csum_Cnotzero2} THEN'
blanchet@48975
   395
  rtac @{thm ctwo_Cnotzero}) 1;
blanchet@48975
   396
blanchet@49284
   397
fun mk_map_wpull_tac comp_in_alt inner_map_wpulls outer_map_wpull =
blanchet@49284
   398
  (rtac (@{thm wpull_cong} OF (replicate 3 comp_in_alt)) THEN' rtac outer_map_wpull) 1 THEN
blanchet@49284
   399
  WRAP (fn thm => rtac thm 1 THEN REPEAT_DETERM (atac 1)) (K all_tac) inner_map_wpulls all_tac THEN
blanchet@49284
   400
  TRY (REPEAT_DETERM (atac 1 ORELSE rtac @{thm wpull_id} 1));
blanchet@49284
   401
blanchet@49284
   402
fun mk_simple_wit_tac wit_thms = ALLGOALS (atac ORELSE' eresolve_tac (@{thm emptyE} :: wit_thms));
blanchet@49284
   403
blanchet@48975
   404
end;