src/HOL/Tools/BNF/bnf_gfp_tactics.ML
author wenzelm
Wed, 08 Oct 2014 17:09:07 +0200
changeset 58634 9f10d82e8188
parent 58446 e89f57d1e46c
child 59498 50b60f501b05
permissions -rw-r--r--
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55061
a0adf838e2d1 adjusted comments
blanchet
parents: 55060
diff changeset
     1
(*  Title:      HOL/Tools/BNF/bnf_gfp_tactics.ML
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     3
    Author:     Andrei Popescu, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     4
    Author:     Jasmin Blanchette, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     5
    Copyright   2012
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     7
Tactics for the codatatype construction.
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    10
signature BNF_GFP_TACTICS =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    11
sig
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    12
  val mk_bis_Gr_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> thm list -> tactic
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    13
  val mk_bis_O_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    14
  val mk_bis_Union_tac: Proof.context -> thm -> thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
  val mk_bis_converse_tac: int -> thm -> thm list -> thm list -> tactic
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
    16
  val mk_bis_rel_tac: int -> thm -> thm list -> thm list -> thm list ->
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    17
    thm list list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    18
  val mk_coalgT_tac: Proof.context -> int -> thm list -> thm list -> thm list list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    19
  val mk_coalg_final_tac: int -> thm -> thm list -> thm list -> thm list list -> thm list list ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    20
    tactic
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    21
  val mk_coalg_set_tac: thm -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    22
  val mk_coind_wit_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    23
  val mk_col_bd_tac: int -> int -> cterm option list -> thm list -> thm list -> thm -> thm ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    24
    thm list list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    25
  val mk_col_natural_tac: Proof.context -> cterm option list -> thm list -> thm list -> thm list ->
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    26
    thm list list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    27
  val mk_congruent_str_final_tac: int -> thm -> thm -> thm -> thm list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    28
  val mk_corec_tac: Proof.context -> int -> thm list -> thm -> thm -> thm list -> tactic
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    29
  val mk_corec_unique_mor_tac: Proof.context -> thm list -> thm list -> thm -> tactic
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
    30
  val mk_dtor_coinduct_tac: int -> thm -> thm -> thm list -> tactic
58445
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
    31
  val mk_dtor_corec_transfer_tac: Proof.context -> int -> int -> thm list -> thm list -> thm list ->
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
    32
    thm list -> tactic
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
    33
  val mk_dtor_rel_tac: Proof.context -> thm list -> int -> thm -> thm -> thm -> thm -> thm list ->
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    34
    thm -> thm -> thm list -> thm list -> thm list list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    35
  val mk_dtor_o_ctor_tac: Proof.context -> thm -> thm -> thm -> thm -> thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    36
  val mk_equiv_lsbis_tac: thm -> thm -> thm -> thm -> thm -> thm -> tactic
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
    37
  val mk_Jset_minimal_tac: Proof.context -> int -> thm -> tactic
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
    38
  val mk_col_minimal_tac: Proof.context -> int -> cterm option list -> thm list -> thm list ->
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    39
    tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    40
  val mk_incl_lsbis_tac: int -> int -> thm -> tactic
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    41
  val mk_length_Lev'_tac: thm -> tactic
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    42
  val mk_length_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list -> tactic
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
    43
  val mk_map_comp0_tac: thm list -> thm list -> thm -> tactic
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    44
  val mk_mcong_tac: Proof.context -> int -> (int -> tactic) -> thm list -> thm list -> thm list ->
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
    45
    thm list list -> thm list list -> thm list list list -> thm list -> tactic
53270
c8628119d18e renamed BNF axiom
blanchet
parents: 53105
diff changeset
    46
  val mk_map_id0_tac: thm list -> thm -> thm -> tactic
55602
257bd115fcca made tactics more robust
traytel
parents: 55581
diff changeset
    47
  val mk_map_tac: int -> int -> thm -> thm -> thm -> thm -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    48
  val mk_dtor_map_unique_tac: Proof.context -> thm -> thm list -> tactic
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    49
  val mk_mor_Abs_tac: Proof.context -> thm list -> thm list -> tactic
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
    50
  val mk_mor_Rep_tac: Proof.context -> thm list -> thm list -> thm list -> thm list list ->
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    51
    thm list -> thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    52
  val mk_mor_T_final_tac: thm -> thm list -> thm list -> tactic
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    53
  val mk_mor_UNIV_tac: thm list -> thm -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    54
  val mk_mor_beh_tac: Proof.context -> int -> thm -> thm -> thm list -> thm list -> thm list ->
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    55
    thm list -> thm list list -> thm list list -> thm list -> thm list -> thm list -> thm list ->
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
    56
    thm list -> thm list -> thm list list -> thm list list list -> thm list list list ->
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
    57
    thm list list -> thm list -> thm list -> tactic
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
    58
  val mk_mor_case_sum_tac: 'a list -> thm -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    59
  val mk_mor_comp_tac: thm -> thm list -> thm list -> thm list -> tactic
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    60
  val mk_mor_elim_tac: thm -> tactic
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
    61
  val mk_mor_col_tac: int -> int -> cterm option list -> int -> thm list -> thm list ->
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    62
    thm list -> thm list list -> thm list list -> tactic
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    63
  val mk_mor_incl_tac: thm -> thm list -> tactic
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    64
  val mk_mor_str_tac: 'a list -> thm -> tactic
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
    65
  val mk_mor_unfold_tac: int -> thm -> thm list -> thm list -> thm list -> thm list -> thm list ->
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
    66
    thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    67
  val mk_raw_coind_tac: thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm list ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    68
    thm list -> thm list -> thm -> thm list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    69
  val mk_rel_coinduct_tac: Proof.context -> thm list -> thm list -> thm list -> thm list list ->
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    70
    thm list -> thm list -> tactic
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
    71
  val mk_rel_coinduct_coind_tac: Proof.context -> bool -> int -> thm -> int list -> thm list ->
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
    72
    thm list -> thm list -> thm list list -> thm list -> thm list -> thm list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    73
  val mk_rel_coinduct_ind_tac: Proof.context -> int -> int list -> thm list -> thm list list ->
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    74
    int -> thm -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    75
  val mk_rv_last_tac: ctyp option list -> cterm option list -> thm list -> thm list -> tactic
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    76
  val mk_sbis_lsbis_tac: Proof.context -> thm list -> thm -> thm -> tactic
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    77
  val mk_set_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list -> thm list ->
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    78
    thm list -> thm list list -> tactic
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
    79
  val mk_set_bd_tac: thm -> thm -> tactic
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
    80
  val mk_set_Jset_incl_Jset_tac: int -> thm -> int -> tactic
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    81
  val mk_set_image_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list ->
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
    82
    thm list -> thm list -> thm list list -> thm list list -> tactic
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
    83
  val mk_set_incl_Jset_tac: thm -> tactic
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
    84
  val mk_set_ge_tac: int  -> thm -> thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    85
  val mk_set_le_tac: int -> thm -> thm list -> thm list list -> tactic
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
    86
  val mk_set_map0_tac: thm -> tactic
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
    87
  val mk_unfold_unique_mor_tac: thm list -> thm -> thm -> thm list -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    88
  val mk_unfold_transfer_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
    89
  val mk_wit_tac: Proof.context -> int -> thm list -> thm list -> thm list -> thm list -> tactic
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
    90
  val mk_le_rel_OO_tac: thm -> thm list -> thm list -> tactic
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    91
end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    92
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    93
structure BNF_GFP_Tactics : BNF_GFP_TACTICS =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    94
struct
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    95
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    96
open BNF_Tactics
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    97
open BNF_Util
51850
106afdf5806c renamed a few FP-related files, to make it clear that these are not the sum of LFP + GFP but rather shared basic libraries
blanchet
parents: 51798
diff changeset
    98
open BNF_FP_Util
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    99
open BNF_GFP_Util
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   100
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   101
val fst_convol_fun_cong_sym = @{thm fst_convol[unfolded convol_def]} RS fun_cong RS sym;
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   102
val list_inject_iffD1 = @{thm list.inject[THEN iffD1]};
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   103
val nat_induct = @{thm nat_induct};
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   104
val o_apply_trans_sym = o_apply RS trans RS sym;
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   105
val ord_eq_le_trans = @{thm ord_eq_le_trans};
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   106
val ordIso_ordLeq_trans = @{thm ordIso_ordLeq_trans};
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   107
val snd_convol_fun_cong_sym = @{thm snd_convol[unfolded convol_def]} RS fun_cong RS sym;
57983
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57806
diff changeset
   108
val sum_case_cong_weak = @{thm sum.case_cong_weak};
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   109
val trans_fun_cong_image_id_id_apply = @{thm trans[OF fun_cong[OF image_id] id_apply]};
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   110
val Collect_splitD_set_mp = @{thm Collect_splitD[OF set_mp]};
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   111
val rev_bspec = Drule.rotate_prems 1 bspec;
52749
ed416f4ac34e more converse(p) theorems; tuned proofs;
traytel
parents: 52731
diff changeset
   112
val Un_cong = @{thm arg_cong2[of _ _ _ _ "op \<union>"]};
ed416f4ac34e more converse(p) theorems; tuned proofs;
traytel
parents: 52731
diff changeset
   113
val converse_shift = @{thm converse_subset_swap} RS iffD1;
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   114
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   115
fun mk_coalg_set_tac coalg_def =
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   116
  dtac (coalg_def RS iffD1) 1 THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   117
  REPEAT_DETERM (etac conjE 1) THEN
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   118
  EVERY' [dtac rev_bspec, atac] 1 THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   119
  REPEAT_DETERM (eresolve_tac [CollectE, conjE] 1) THEN atac 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   120
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   121
fun mk_mor_elim_tac mor_def =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   122
  (dtac (mor_def RS iffD1) THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   123
  REPEAT o etac conjE THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   124
  TRY o rtac @{thm image_subsetI} THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   125
  etac bspec THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   126
  atac) 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   127
53285
f09645642984 renamed BNF fact
blanchet
parents: 53270
diff changeset
   128
fun mk_mor_incl_tac mor_def map_ids =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   129
  (rtac (mor_def RS iffD2) THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   130
  rtac conjI THEN'
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   131
  CONJ_WRAP' (K (EVERY' [rtac ballI, etac set_mp, etac (id_apply RS @{thm ssubst_mem})]))
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   132
    map_ids THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   133
  CONJ_WRAP' (fn thm =>
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   134
    (EVERY' [rtac ballI, rtac (thm RS trans), rtac sym, rtac (id_apply RS arg_cong)])) map_ids) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   135
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   136
fun mk_mor_comp_tac mor_def mor_images morEs map_comp_ids =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   137
  let
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   138
    fun fbetw_tac image = EVERY' [rtac ballI, rtac (o_apply RS @{thm ssubst_mem}), etac image,
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   139
      etac image, atac];
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   140
    fun mor_tac ((mor_image, morE), map_comp_id) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   141
      EVERY' [rtac ballI, stac o_apply, rtac trans, rtac (map_comp_id RS sym), rtac trans,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   142
        etac (morE RS arg_cong), atac, etac morE, etac mor_image, atac];
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   143
  in
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   144
    (rtac (mor_def RS iffD2) THEN' rtac conjI THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   145
    CONJ_WRAP' fbetw_tac mor_images THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   146
    CONJ_WRAP' mor_tac ((mor_images ~~ morEs) ~~ map_comp_ids)) 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   147
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   148
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   149
fun mk_mor_UNIV_tac morEs mor_def =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   150
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   151
    val n = length morEs;
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   152
    fun mor_tac morE = EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply, rtac trans, etac morE,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   153
      rtac UNIV_I, rtac sym, rtac o_apply];
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   154
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   155
    EVERY' [rtac iffI, CONJ_WRAP' mor_tac morEs,
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   156
    rtac (mor_def RS iffD2), rtac conjI, CONJ_WRAP' (K (rtac ballI THEN' rtac UNIV_I)) morEs,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   157
    CONJ_WRAP' (fn i =>
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   158
      EVERY' [dtac (mk_conjunctN n i), rtac ballI, etac @{thm comp_eq_dest}]) (1 upto n)] 1
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   159
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   160
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   161
fun mk_mor_str_tac ks mor_UNIV =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   162
  (rtac (mor_UNIV RS iffD2) THEN' CONJ_WRAP' (K (rtac refl)) ks) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   163
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   164
fun mk_mor_case_sum_tac ks mor_UNIV =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   165
  (rtac (mor_UNIV RS iffD2) THEN' CONJ_WRAP' (K (rtac @{thm case_sum_o_inj(1)[symmetric]})) ks) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   166
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   167
fun mk_set_incl_Jset_tac rec_Suc =
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   168
  EVERY' (map rtac [@{thm SUP_upper2}, UNIV_I, @{thm ord_le_eq_trans}, @{thm Un_upper1}, sym,
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   169
    rec_Suc]) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   170
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   171
fun mk_set_Jset_incl_Jset_tac n rec_Suc i =
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   172
  EVERY' (map rtac [@{thm UN_least}, subsetI, @{thm UN_I}, UNIV_I, set_mp, equalityD2, rec_Suc,
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   173
      UnI2, mk_UnIN n i] @ [etac @{thm UN_I}, atac]) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   174
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   175
fun mk_col_minimal_tac ctxt m cts rec_0s rec_Sucs =
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   176
  EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   177
    REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   178
    CONJ_WRAP' (fn thm => EVERY'
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   179
      [rtac ord_eq_le_trans, rtac thm, rtac @{thm empty_subsetI}]) rec_0s,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   180
    REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   181
    CONJ_WRAP' (fn rec_Suc => EVERY'
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   182
      [rtac ord_eq_le_trans, rtac rec_Suc,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   183
        if m = 0 then K all_tac
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   184
        else (rtac @{thm Un_least} THEN' Goal.assume_rule_tac ctxt),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   185
        CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_least}))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   186
          (K (EVERY' [rtac @{thm UN_least}, REPEAT_DETERM o eresolve_tac [allE, conjE],
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   187
            rtac subset_trans, atac, Goal.assume_rule_tac ctxt])) rec_0s])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   188
      rec_Sucs] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   189
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   190
fun mk_Jset_minimal_tac ctxt n col_minimal =
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   191
  (CONJ_WRAP' (K (EVERY' [rtac @{thm UN_least}, rtac rev_mp, rtac col_minimal,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   192
    EVERY' (replicate ((n + 1) * n) (Goal.assume_rule_tac ctxt)), rtac impI,
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   193
    REPEAT_DETERM o eresolve_tac [allE, conjE], atac])) (1 upto n)) 1
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   194
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   195
fun mk_mor_col_tac m n cts j rec_0s rec_Sucs morEs set_map0ss coalg_setss =
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   196
  EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   197
    REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   198
    CONJ_WRAP' (fn thm => EVERY' (map rtac [impI, thm RS trans, thm RS sym])) rec_0s,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   199
    REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   200
    CONJ_WRAP'
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   201
      (fn (rec_Suc, (morE, ((passive_set_map0s, active_set_map0s), coalg_sets))) =>
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   202
        EVERY' [rtac impI, rtac (rec_Suc RS trans), rtac (rec_Suc RS trans RS sym),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   203
          if m = 0 then K all_tac
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   204
          else EVERY' [rtac Un_cong, rtac @{thm box_equals},
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   205
            rtac (nth passive_set_map0s (j - 1) RS sym),
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   206
            rtac trans_fun_cong_image_id_id_apply, etac (morE RS arg_cong), atac],
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   207
          CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 Un_cong))
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   208
            (fn (i, (set_map0, coalg_set)) =>
56248
67dc9549fa15 generalized and strengthened cong rules on compound operators, similar to 1ed737a98198
haftmann
parents: 56179
diff changeset
   209
              EVERY' [rtac sym, rtac trans, rtac (refl RSN (2, @{thm SUP_cong})),
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   210
                etac (morE RS sym RS arg_cong RS trans), atac, rtac set_map0,
56248
67dc9549fa15 generalized and strengthened cong rules on compound operators, similar to 1ed737a98198
haftmann
parents: 56179
diff changeset
   211
                rtac (@{thm UN_simps(10)} RS trans), rtac (refl RS @{thm SUP_cong}),
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   212
                ftac coalg_set, atac, dtac set_mp, atac, rtac mp, rtac (mk_conjunctN n i),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   213
                REPEAT_DETERM o etac allE, atac, atac])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   214
            (rev ((1 upto n) ~~ (active_set_map0s ~~ coalg_sets)))])
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   215
      (rec_Sucs ~~ (morEs ~~ (map (chop m) set_map0ss ~~ map (drop m) coalg_setss)))] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   216
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   217
fun mk_bis_rel_tac m bis_def in_rels map_comp0s map_cong0s set_map0ss =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   218
  let
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   219
    val n = length in_rels;
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   220
    val thms = ((1 upto n) ~~ map_comp0s ~~ map_cong0s ~~ set_map0ss ~~ in_rels);
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   221
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   222
    fun mk_if_tac ((((i, map_comp0), map_cong0), set_map0s), in_rel) =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   223
      EVERY' [rtac allI, rtac allI, rtac impI, dtac (mk_conjunctN n i),
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   224
        etac allE, etac allE, etac impE, atac, etac bexE,
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   225
        REPEAT_DETERM o eresolve_tac [CollectE, conjE],
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   226
        rtac (in_rel RS iffD2), rtac exI, rtac (Drule.rotate_prems 1 conjI),
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   227
        CONJ_WRAP' (fn thm => EVERY' [rtac trans, rtac trans, rtac map_comp0, rtac map_cong0,
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   228
          REPEAT_DETERM_N m o rtac thm, REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   229
          atac])
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   230
        @{thms fst_diag_id snd_diag_id},
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   231
        rtac CollectI,
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   232
        CONJ_WRAP' (fn (i, thm) =>
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   233
          if i <= m
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   234
          then EVERY' [rtac ord_eq_le_trans, rtac thm, rtac subset_trans,
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   235
            etac @{thm image_mono}, rtac @{thm image_subsetI}, rtac CollectI,
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   236
            rtac @{thm case_prodI}, rtac refl]
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   237
          else EVERY' [rtac ord_eq_le_trans, rtac trans, rtac thm,
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   238
            rtac trans_fun_cong_image_id_id_apply, etac @{thm Collect_split_in_rel_leI}])
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   239
        (1 upto (m + n) ~~ set_map0s)];
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   240
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   241
    fun mk_only_if_tac ((((i, map_comp0), map_cong0), set_map0s), in_rel) =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   242
      EVERY' [dtac (mk_conjunctN n i), rtac allI, rtac allI, rtac impI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   243
        etac allE, etac allE, etac impE, atac,
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   244
        dtac (in_rel RS @{thm iffD1}),
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   245
        REPEAT_DETERM o eresolve_tac ([CollectE, conjE, exE] @
56017
8d3df792d47e tuned tactic
traytel
parents: 55990
diff changeset
   246
          @{thms CollectE Collect_split_in_rel_leE}),
53287
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
   247
        rtac bexI, rtac conjI, rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   248
        REPEAT_DETERM_N m o rtac (@{thm id_comp} RS fun_cong),
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   249
        REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
53287
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
   250
        atac, rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   251
        REPEAT_DETERM_N m o rtac (@{thm id_comp} RS fun_cong),
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   252
        REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   253
        rtac trans, rtac map_cong0,
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   254
        REPEAT_DETERM_N m o EVERY' [rtac @{thm Collect_splitD}, etac set_mp, atac],
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   255
        REPEAT_DETERM_N n o rtac refl,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   256
        atac, rtac CollectI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   257
        CONJ_WRAP' (fn (i, thm) =>
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   258
          if i <= m then rtac subset_UNIV
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   259
          else EVERY' [rtac ord_eq_le_trans, rtac trans, rtac thm,
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   260
            rtac trans_fun_cong_image_id_id_apply, atac])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   261
        (1 upto (m + n) ~~ set_map0s)];
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   262
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   263
    EVERY' [rtac (bis_def RS trans),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   264
      rtac iffI, etac conjE, etac conjI, CONJ_WRAP' mk_if_tac thms,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   265
      etac conjE, etac conjI, CONJ_WRAP' mk_only_if_tac thms] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   266
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   267
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   268
fun mk_bis_converse_tac m bis_rel rel_congs rel_converseps =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   269
  EVERY' [rtac (bis_rel RS iffD2), dtac (bis_rel RS iffD1),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   270
    REPEAT_DETERM o etac conjE, rtac conjI,
52749
ed416f4ac34e more converse(p) theorems; tuned proofs;
traytel
parents: 52731
diff changeset
   271
    CONJ_WRAP' (K (EVERY' [rtac converse_shift, etac subset_trans,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   272
      rtac equalityD2, rtac @{thm converse_Times}])) rel_congs,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   273
    CONJ_WRAP' (fn (rel_cong, rel_conversep) =>
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   274
      EVERY' [rtac allI, rtac allI, rtac impI,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   275
        rtac (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   276
        REPEAT_DETERM_N m o rtac @{thm conversep_eq},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   277
        REPEAT_DETERM_N (length rel_congs) o rtac @{thm conversep_in_rel},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   278
        rtac (rel_conversep RS sym RS @{thm eq_refl} RS @{thm predicate2D}),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   279
        REPEAT_DETERM o etac allE,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   280
        rtac @{thm conversepI}, etac mp, etac @{thm converseD}]) (rel_congs ~~ rel_converseps)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   281
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   282
fun mk_bis_O_tac ctxt m bis_rel rel_congs le_rel_OOs =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   283
  EVERY' [rtac (bis_rel RS iffD2), REPEAT_DETERM o dtac (bis_rel RS iffD1),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   284
    REPEAT_DETERM o etac conjE, rtac conjI,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   285
    CONJ_WRAP' (K (EVERY' [etac @{thm relcomp_subset_Sigma}, atac])) rel_congs,
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   286
    CONJ_WRAP' (fn (rel_cong, le_rel_OO) =>
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   287
      EVERY' [rtac allI, rtac allI, rtac impI,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   288
        rtac (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   289
        REPEAT_DETERM_N m o rtac @{thm eq_OO},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   290
        REPEAT_DETERM_N (length rel_congs) o rtac @{thm relcompp_in_rel},
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   291
        rtac (le_rel_OO RS @{thm predicate2D}),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   292
        etac @{thm relcompE},
56765
644f0d4820a1 cleaner 'rel_inject' theorems
blanchet
parents: 56248
diff changeset
   293
        REPEAT_DETERM o dtac prod_injectD,
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   294
        etac conjE, hyp_subst_tac ctxt,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   295
        REPEAT_DETERM o etac allE, rtac @{thm relcomppI},
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   296
        etac mp, atac, etac mp, atac]) (rel_congs ~~ le_rel_OOs)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   297
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   298
fun mk_bis_Gr_tac ctxt bis_rel rel_Grps mor_images morEs coalg_ins =
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   299
  unfold_thms_tac ctxt (bis_rel :: @{thm eq_alt} :: @{thm in_rel_Gr} :: rel_Grps) THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   300
  EVERY' [rtac conjI,
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   301
    CONJ_WRAP' (fn thm => rtac (@{thm Gr_incl} RS iffD2) THEN' etac thm) mor_images,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   302
    CONJ_WRAP' (fn (coalg_in, morE) =>
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   303
      EVERY' [rtac allI, rtac allI, rtac impI, rtac @{thm GrpI}, etac (morE RS trans),
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   304
        etac @{thm GrD1}, etac (@{thm GrD2} RS arg_cong), etac coalg_in, etac @{thm GrD1}])
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   305
    (coalg_ins ~~ morEs)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   306
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   307
fun mk_bis_Union_tac ctxt bis_def in_monos =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   308
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   309
    val n = length in_monos;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   310
    val ks = 1 upto n;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   311
  in
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   312
    unfold_thms_tac ctxt [bis_def] THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   313
    EVERY' [rtac conjI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   314
      CONJ_WRAP' (fn i =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   315
        EVERY' [rtac @{thm UN_least}, dtac bspec, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   316
          dtac conjunct1, etac (mk_conjunctN n i)]) ks,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   317
      CONJ_WRAP' (fn (i, in_mono) =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   318
        EVERY' [rtac allI, rtac allI, rtac impI, etac @{thm UN_E}, dtac bspec, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   319
          dtac conjunct2, dtac (mk_conjunctN n i), etac allE, etac allE, dtac mp,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   320
          atac, etac bexE, rtac bexI, atac, rtac in_mono,
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   321
          REPEAT_DETERM_N n o etac @{thm SUP_upper2[OF _ subset_refl]},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   322
          atac]) (ks ~~ in_monos)] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   323
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   324
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   325
fun mk_sbis_lsbis_tac ctxt lsbis_defs bis_Union bis_cong =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   326
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   327
    val n = length lsbis_defs;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   328
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   329
    EVERY' [rtac (Thm.permute_prems 0 1 bis_cong), EVERY' (map rtac lsbis_defs),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   330
      rtac bis_Union, rtac ballI, REPEAT_DETERM o eresolve_tac [CollectE, conjE, exE],
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   331
      hyp_subst_tac ctxt, etac bis_cong, EVERY' (map (rtac o mk_nth_conv n) (1 upto n))] 1
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   332
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   333
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   334
fun mk_incl_lsbis_tac n i lsbis_def =
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   335
  EVERY' [rtac @{thm xt1(3)}, rtac lsbis_def, rtac @{thm SUP_upper2}, rtac CollectI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   336
    REPEAT_DETERM_N n o rtac exI, rtac conjI, rtac refl, atac, rtac equalityD2,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   337
    rtac (mk_nth_conv n i)] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   338
51447
a19e973fa2cf eliminate duplicated constant (diag vs. Id_on)
traytel
parents: 51070
diff changeset
   339
fun mk_equiv_lsbis_tac sbis_lsbis lsbis_incl incl_lsbis bis_Id_on bis_converse bis_O =
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   340
  EVERY' [rtac (@{thm equiv_def} RS iffD2),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   341
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   342
    rtac conjI, rtac (@{thm refl_on_def} RS iffD2),
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   343
    rtac conjI, rtac lsbis_incl, rtac ballI, rtac set_mp,
51447
a19e973fa2cf eliminate duplicated constant (diag vs. Id_on)
traytel
parents: 51070
diff changeset
   344
    rtac incl_lsbis, rtac bis_Id_on, atac, etac @{thm Id_onI},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   345
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   346
    rtac conjI, rtac (@{thm sym_def} RS iffD2),
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   347
    rtac allI, rtac allI, rtac impI, rtac set_mp,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   348
    rtac incl_lsbis, rtac bis_converse, rtac sbis_lsbis, etac @{thm converseI},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   349
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   350
    rtac (@{thm trans_def} RS iffD2),
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   351
    rtac allI, rtac allI, rtac allI, rtac impI, rtac impI, rtac set_mp,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   352
    rtac incl_lsbis, rtac bis_O, rtac sbis_lsbis, rtac sbis_lsbis,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   353
    etac @{thm relcompI}, atac] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   354
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   355
fun mk_coalgT_tac ctxt m defs strT_defs set_map0ss =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   356
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   357
    val n = length strT_defs;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   358
    val ks = 1 upto n;
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   359
    fun coalg_tac (i, (active_sets, def)) =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   360
      EVERY' [rtac ballI, REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE],
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   361
        hyp_subst_tac ctxt, rtac (def RS trans RS @{thm ssubst_mem}), etac (arg_cong RS trans),
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   362
        rtac (mk_sum_caseN n i), rtac CollectI,
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   363
        REPEAT_DETERM_N m o EVERY' [rtac conjI, rtac subset_UNIV],
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   364
        CONJ_WRAP' (fn (i, thm) => EVERY' [rtac (thm RS ord_eq_le_trans),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   365
          rtac @{thm image_subsetI}, rtac CollectI, rtac exI, rtac exI, rtac conjI, rtac refl,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   366
          rtac conjI,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   367
          rtac conjI, etac @{thm empty_Shift}, dtac set_rev_mp,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   368
            etac equalityD1, etac CollectD,
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   369
          rtac ballI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   370
            CONJ_WRAP' (fn i => EVERY' [rtac ballI, etac CollectE, dtac @{thm ShiftD},
55581
d1c228753d76 another simplification of internal codatatype construction
traytel
parents: 55577
diff changeset
   371
              dtac bspec, etac thin_rl, atac, dtac (mk_conjunctN n i),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   372
              dtac bspec, rtac CollectI, etac @{thm set_mp[OF equalityD1[OF Succ_Shift]]},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   373
              REPEAT_DETERM o eresolve_tac [exE, conjE], rtac exI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   374
              rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   375
              rtac (@{thm append_Cons} RS sym RS arg_cong RS trans), atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   376
              CONJ_WRAP' (K (EVERY' [etac trans, rtac @{thm Collect_cong},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   377
                rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   378
                rtac (@{thm append_Cons} RS sym RS arg_cong)])) ks]) ks,
55581
d1c228753d76 another simplification of internal codatatype construction
traytel
parents: 55577
diff changeset
   379
          dtac bspec, atac, dtac (mk_conjunctN n i), dtac bspec,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   380
          etac @{thm set_mp[OF equalityD1]}, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   381
          REPEAT_DETERM o eresolve_tac [exE, conjE], rtac exI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   382
          rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   383
          etac (@{thm append_Nil} RS sym RS arg_cong RS trans),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   384
          REPEAT_DETERM_N m o (rtac conjI THEN' atac),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   385
          CONJ_WRAP' (K (EVERY' [etac trans, rtac @{thm Collect_cong},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   386
            rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   387
            rtac (@{thm append_Nil} RS sym RS arg_cong)])) ks]) (ks ~~ active_sets)];
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   388
  in
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   389
    unfold_thms_tac ctxt defs THEN
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   390
    CONJ_WRAP' coalg_tac (ks ~~ (map (drop m) set_map0ss ~~ strT_defs)) 1
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   391
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   392
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   393
fun mk_length_Lev_tac ctxt cts Lev_0s Lev_Sucs =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   394
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   395
    val n = length Lev_0s;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   396
    val ks = n downto 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   397
  in
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   398
    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   399
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   400
      CONJ_WRAP' (fn Lev_0 =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   401
        EVERY' [rtac impI, dtac (Lev_0 RS equalityD1 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   402
          etac @{thm singletonE}, etac ssubst, rtac @{thm list.size(3)}]) Lev_0s,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   403
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   404
      CONJ_WRAP' (fn Lev_Suc =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   405
        EVERY' [rtac impI, dtac (Lev_Suc RS equalityD1 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   406
          CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   407
            (fn i =>
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   408
              EVERY' [REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE], hyp_subst_tac ctxt,
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   409
                rtac trans, rtac @{thm length_Cons}, rtac @{thm arg_cong[of _ _ Suc]},
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   410
                REPEAT_DETERM o etac allE, dtac (mk_conjunctN n i), etac mp, atac]) ks])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   411
      Lev_Sucs] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   412
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   413
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   414
fun mk_length_Lev'_tac length_Lev =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   415
  EVERY' [ftac length_Lev, etac ssubst, atac] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   416
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   417
fun mk_rv_last_tac cTs cts rv_Nils rv_Conss =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   418
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   419
    val n = length rv_Nils;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   420
    val ks = 1 upto n;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   421
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   422
    EVERY' [rtac (Drule.instantiate' cTs cts @{thm list.induct}),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   423
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   424
      CONJ_WRAP' (fn rv_Cons =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   425
        CONJ_WRAP' (fn (i, rv_Nil) => (EVERY' [rtac exI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   426
          rtac (@{thm append_Nil} RS arg_cong RS trans),
55606
75a639ddc05f tuned tactic
traytel
parents: 55602
diff changeset
   427
          rtac (rv_Cons RS trans), rtac (mk_sum_caseN n i RS trans), rtac rv_Nil]))
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   428
        (ks ~~ rv_Nils))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   429
      rv_Conss,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   430
      REPEAT_DETERM o rtac allI, rtac (mk_sumEN n),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   431
      EVERY' (map (fn i =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   432
        CONJ_WRAP' (fn rv_Cons => EVERY' [REPEAT_DETERM o etac allE, dtac (mk_conjunctN n i),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   433
          CONJ_WRAP' (fn i' => EVERY' [dtac (mk_conjunctN n i'), etac exE, rtac exI,
55606
75a639ddc05f tuned tactic
traytel
parents: 55602
diff changeset
   434
            rtac (@{thm append_Cons} RS arg_cong RS trans), rtac (rv_Cons RS trans),
57983
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57806
diff changeset
   435
            if n = 1 then K all_tac else etac (sum_case_cong_weak RS trans),
55606
75a639ddc05f tuned tactic
traytel
parents: 55602
diff changeset
   436
            rtac (mk_sum_caseN n i RS trans), atac])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   437
          ks])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   438
        rv_Conss)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   439
      ks)] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   440
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   441
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   442
fun mk_set_Lev_tac ctxt cts Lev_0s Lev_Sucs rv_Nils rv_Conss from_to_sbdss =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   443
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   444
    val n = length Lev_0s;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   445
    val ks = 1 upto n;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   446
  in
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   447
    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   448
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   449
      CONJ_WRAP' (fn ((i, (Lev_0, Lev_Suc)), rv_Nil) =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   450
        EVERY' [rtac impI, dtac (Lev_0 RS equalityD1 RS set_mp),
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   451
          etac @{thm singletonE}, hyp_subst_tac ctxt,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   452
          CONJ_WRAP' (fn i' => rtac impI THEN' dtac (sym RS trans) THEN' rtac rv_Nil THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   453
            (if i = i'
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   454
            then EVERY' [dtac (mk_InN_inject n i), hyp_subst_tac ctxt,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   455
              CONJ_WRAP' (fn (i'', Lev_0'') =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   456
                EVERY' [rtac impI, rtac @{thm ssubst_mem[OF append_Nil]},
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49328
diff changeset
   457
                  rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i''),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   458
                  rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   459
                  etac conjI, rtac (Lev_0'' RS equalityD2 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   460
                  rtac @{thm singletonI}])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   461
              (ks ~~ Lev_0s)]
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   462
            else etac (mk_InN_not_InM i' i RS notE)))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   463
          ks])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   464
      ((ks ~~ (Lev_0s ~~ Lev_Sucs)) ~~ rv_Nils),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   465
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   466
      CONJ_WRAP' (fn ((Lev_Suc, rv_Cons), from_to_sbds) =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   467
        EVERY' [rtac impI, dtac (Lev_Suc RS equalityD1 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   468
          CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   469
            (fn (i, from_to_sbd) =>
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   470
              EVERY' [REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE], hyp_subst_tac ctxt,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   471
                CONJ_WRAP' (fn i' => rtac impI THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   472
                  CONJ_WRAP' (fn i'' =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   473
                    EVERY' [rtac impI, rtac (Lev_Suc RS equalityD2 RS set_mp),
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49328
diff changeset
   474
                      rtac @{thm ssubst_mem[OF append_Cons]}, rtac (mk_UnIN n i),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   475
                      rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   476
                      rtac conjI, atac, dtac (sym RS trans RS sym),
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   477
                      rtac (rv_Cons RS trans), rtac (mk_sum_caseN n i RS trans),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   478
                      etac (from_to_sbd RS arg_cong), REPEAT_DETERM o etac allE,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   479
                      dtac (mk_conjunctN n i), dtac mp, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   480
                      dtac (mk_conjunctN n i'), dtac mp, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   481
                      dtac (mk_conjunctN n i''), etac mp, atac])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   482
                  ks)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   483
                ks])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   484
          (rev (ks ~~ from_to_sbds))])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   485
      ((Lev_Sucs ~~ rv_Conss) ~~ from_to_sbdss)] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   486
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   487
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   488
fun mk_set_image_Lev_tac ctxt cts Lev_0s Lev_Sucs rv_Nils rv_Conss from_to_sbdss to_sbd_injss =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   489
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   490
    val n = length Lev_0s;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   491
    val ks = 1 upto n;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   492
  in
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   493
    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   494
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   495
      CONJ_WRAP' (fn ((i, (Lev_0, Lev_Suc)), rv_Nil) =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   496
        EVERY' [rtac impI, dtac (Lev_0 RS equalityD1 RS set_mp),
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   497
          etac @{thm singletonE}, hyp_subst_tac ctxt,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   498
          CONJ_WRAP' (fn i' => rtac impI THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   499
            CONJ_WRAP' (fn i'' => rtac impI  THEN' dtac (sym RS trans) THEN' rtac rv_Nil THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   500
              (if i = i''
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   501
              then EVERY' [dtac @{thm ssubst_mem[OF sym[OF append_Nil]]},
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   502
                dtac (Lev_Suc RS equalityD1 RS set_mp), dtac (mk_InN_inject n i),
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   503
                hyp_subst_tac ctxt,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   504
                CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   505
                  (fn k => REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE] THEN'
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   506
                    dtac list_inject_iffD1 THEN' etac conjE THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   507
                    (if k = i'
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   508
                    then EVERY' [dtac (mk_InN_inject n k), hyp_subst_tac ctxt, etac imageI]
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   509
                    else etac (mk_InN_not_InM i' k RS notE)))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   510
                (rev ks)]
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   511
              else etac (mk_InN_not_InM i'' i RS notE)))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   512
            ks)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   513
          ks])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   514
      ((ks ~~ (Lev_0s ~~ Lev_Sucs)) ~~ rv_Nils),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   515
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   516
      CONJ_WRAP' (fn ((Lev_Suc, rv_Cons), (from_to_sbds, to_sbd_injs)) =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   517
        EVERY' [rtac impI, dtac (Lev_Suc RS equalityD1 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   518
          CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   519
            (fn (i, (from_to_sbd, to_sbd_inj)) =>
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   520
              REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE] THEN' hyp_subst_tac ctxt THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   521
              CONJ_WRAP' (fn i' => rtac impI THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   522
                dtac @{thm ssubst_mem[OF sym[OF append_Cons]]} THEN'
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   523
                dtac (Lev_Suc RS equalityD1 RS set_mp) THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   524
                CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE)) (fn k =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   525
                  REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE] THEN'
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   526
                  dtac list_inject_iffD1 THEN' etac conjE THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   527
                  (if k = i
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   528
                  then EVERY' [dtac (mk_InN_inject n i),
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   529
                    dtac (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   530
                    atac, atac, hyp_subst_tac ctxt] THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   531
                    CONJ_WRAP' (fn i'' =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   532
                      EVERY' [rtac impI, dtac (sym RS trans),
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   533
                        rtac (rv_Cons RS trans), rtac (mk_sum_caseN n i RS arg_cong RS trans),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   534
                        etac (from_to_sbd RS arg_cong),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   535
                        REPEAT_DETERM o etac allE,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   536
                        dtac (mk_conjunctN n i), dtac mp, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   537
                        dtac (mk_conjunctN n i'), dtac mp, atac,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   538
                        dtac (mk_conjunctN n i''), etac mp, etac sym])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   539
                    ks
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   540
                  else etac (mk_InN_not_InM i k RS notE)))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   541
                (rev ks))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   542
              ks)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   543
          (rev (ks ~~ (from_to_sbds ~~ to_sbd_injs)))])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   544
      ((Lev_Sucs ~~ rv_Conss) ~~ (from_to_sbdss ~~ to_sbd_injss))] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   545
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   546
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   547
fun mk_mor_beh_tac ctxt m mor_def mor_cong beh_defs carT_defs strT_defs isNode_defs to_sbd_injss
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   548
  from_to_sbdss Lev_0s Lev_Sucs rv_Nils rv_Conss length_Levs length_Lev's rv_lastss set_Levsss
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   549
  set_image_Levsss set_map0ss map_comp_ids map_cong0s =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   550
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   551
    val n = length beh_defs;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   552
    val ks = 1 upto n;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   553
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   554
    fun fbetw_tac (i, (carT_def, (isNode_def, (Lev_0, (rv_Nil, ((length_Lev, length_Lev'),
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   555
      (rv_lasts, (set_map0s, (set_Levss, set_image_Levss))))))))) =
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   556
      EVERY' [rtac ballI, rtac (carT_def RS equalityD2 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   557
        rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, rtac conjI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   558
        rtac conjI,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   559
          rtac @{thm UN_I}, rtac UNIV_I, rtac (Lev_0 RS equalityD2 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   560
          rtac @{thm singletonI},
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   561
        (**)
55581
d1c228753d76 another simplification of internal codatatype construction
traytel
parents: 55577
diff changeset
   562
          rtac ballI, etac @{thm UN_E},
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   563
          CONJ_WRAP' (fn (i, (rv_last, (isNode_def, (set_map0s,
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   564
            (set_Levs, set_image_Levs))))) =>
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   565
            EVERY' [rtac ballI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   566
              REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   567
              rtac (rev_mp OF [rv_last, impI]), etac exE, rtac (isNode_def RS iffD2),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   568
              rtac exI, rtac conjI,
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   569
              if n = 1 then rtac refl
57983
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57806
diff changeset
   570
              else etac (sum_case_cong_weak RS trans) THEN' rtac (mk_sum_caseN n i),
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   571
              CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   572
                EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   573
                  rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, etac set_Lev,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   574
                  if n = 1 then rtac refl else atac, atac, rtac subsetI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   575
                  REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   576
                  REPEAT_DETERM_N 4 o etac thin_rl,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   577
                  rtac set_image_Lev,
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   578
                  atac, dtac length_Lev, hyp_subst_tac ctxt, dtac length_Lev',
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   579
                  etac @{thm set_mp[OF equalityD1[OF arg_cong[OF length_append_singleton]]]},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   580
                  if n = 1 then rtac refl else atac])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   581
              (drop m set_map0s ~~ (set_Levs ~~ set_image_Levs))])
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   582
          (ks ~~ (rv_lasts ~~ (isNode_defs ~~ (set_map0ss ~~
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   583
            (set_Levss ~~ set_image_Levss))))),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   584
        (*root isNode*)
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   585
          rtac (isNode_def RS iffD2), rtac exI, rtac conjI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   586
          CONVERSION (Conv.top_conv
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   587
            (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   588
          if n = 1 then rtac refl else rtac (mk_sum_caseN n i),
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   589
          CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   590
            EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   591
              rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, rtac set_Lev,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   592
              rtac (Lev_0 RS equalityD2 RS set_mp), rtac @{thm singletonI}, rtac rv_Nil,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   593
              atac, rtac subsetI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   594
              REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   595
              rtac set_image_Lev, rtac (Lev_0 RS equalityD2 RS set_mp),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   596
              rtac @{thm singletonI}, dtac length_Lev',
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   597
              etac @{thm set_mp[OF equalityD1[OF arg_cong[OF
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   598
                trans[OF length_append_singleton arg_cong[of _ _ Suc, OF list.size(3)]]]]]},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   599
              rtac rv_Nil])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   600
          (drop m set_map0s ~~ (nth set_Levss (i - 1) ~~ nth set_image_Levss (i - 1)))];
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   601
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   602
    fun mor_tac (i, (strT_def, ((Lev_Suc, (rv_Nil, rv_Cons)),
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   603
      ((map_comp_id, map_cong0), (length_Lev', (from_to_sbds, to_sbd_injs)))))) =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   604
      EVERY' [rtac ballI, rtac sym, rtac trans, rtac strT_def,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   605
        CONVERSION (Conv.top_conv
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   606
          (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   607
        if n = 1 then K all_tac
57983
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57806
diff changeset
   608
        else (rtac (sum_case_cong_weak RS trans) THEN'
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   609
          rtac (mk_sum_caseN n i) THEN' rtac (mk_sum_caseN n i RS trans)),
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   610
        rtac (map_comp_id RS trans), rtac (map_cong0 OF replicate m refl),
58634
9f10d82e8188 added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents: 58446
diff changeset
   611
        EVERY' (@{map 3} (fn i' => fn to_sbd_inj => fn from_to_sbd =>
56765
644f0d4820a1 cleaner 'rel_inject' theorems
blanchet
parents: 56248
diff changeset
   612
          DETERM o EVERY' [rtac trans, rtac o_apply, rtac prod_injectI, rtac conjI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   613
            rtac trans, rtac @{thm Shift_def},
58445
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
   614
            rtac equalityI, rtac subsetI, etac thin_rl,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   615
            REPEAT_DETERM o eresolve_tac [CollectE, @{thm UN_E}], dtac length_Lev', dtac asm_rl,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   616
            etac thin_rl, dtac @{thm set_rev_mp[OF _ equalityD1]},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   617
            rtac (@{thm length_Cons} RS arg_cong RS trans), rtac Lev_Suc,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   618
            CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE)) (fn i'' =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   619
              EVERY' [REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE],
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   620
                dtac list_inject_iffD1, etac conjE,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   621
                if i' = i'' then EVERY' [dtac (mk_InN_inject n i'),
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   622
                  dtac (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   623
                  atac, atac, hyp_subst_tac ctxt, etac @{thm UN_I[OF UNIV_I]}]
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   624
                else etac (mk_InN_not_InM i' i'' RS notE)])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   625
            (rev ks),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   626
            rtac @{thm UN_least}, rtac subsetI, rtac CollectI, rtac @{thm UN_I[OF UNIV_I]},
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49328
diff changeset
   627
            rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i'), rtac CollectI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   628
            REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, etac conjI, atac,
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   629
            rtac trans, rtac @{thm shift_def}, rtac iffD2, rtac @{thm fun_eq_iff}, rtac allI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   630
            CONVERSION (Conv.top_conv
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   631
              (K (Conv.try_conv (Conv.rewr_conv (rv_Cons RS eq_reflection)))) ctxt),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   632
            if n = 1 then K all_tac
57983
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57806
diff changeset
   633
            else rtac sum_case_cong_weak THEN' rtac (mk_sum_caseN n i' RS trans),
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   634
            SELECT_GOAL (unfold_thms_tac ctxt [from_to_sbd]), rtac refl])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   635
        ks to_sbd_injs from_to_sbds)];
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   636
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   637
    (rtac mor_cong THEN'
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   638
    EVERY' (map (fn thm => rtac (thm RS @{thm ext})) beh_defs) THEN'
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   639
    rtac (mor_def RS iffD2) THEN' rtac conjI THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   640
    CONJ_WRAP' fbetw_tac
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   641
      (ks ~~ (carT_defs ~~ (isNode_defs ~~ (Lev_0s ~~ (rv_Nils ~~ ((length_Levs ~~ length_Lev's) ~~
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   642
        (rv_lastss ~~ (set_map0ss ~~ (set_Levsss ~~ set_image_Levsss))))))))) THEN'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   643
    CONJ_WRAP' mor_tac
55577
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   644
      (ks ~~ (strT_defs ~~ ((Lev_Sucs ~~ (rv_Nils ~~ rv_Conss)) ~~
a6c2379078c8 simplifications of internal codatatype construction
traytel
parents: 55541
diff changeset
   645
        ((map_comp_ids ~~ map_cong0s) ~~
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   646
          (length_Lev's ~~ (from_to_sbdss ~~ to_sbd_injss))))))) 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   647
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   648
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   649
fun mk_congruent_str_final_tac m lsbisE map_comp_id map_cong0 equiv_LSBISs =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   650
  EVERY' [rtac @{thm congruentI}, dtac lsbisE,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   651
    REPEAT_DETERM o eresolve_tac [CollectE, conjE, bexE], rtac (o_apply RS trans),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   652
    etac (sym RS arg_cong RS trans), rtac (map_comp_id RS trans),
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   653
    rtac (map_cong0 RS trans), REPEAT_DETERM_N m o rtac refl,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   654
    EVERY' (map (fn equiv_LSBIS =>
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   655
      EVERY' [rtac @{thm equiv_proj}, rtac equiv_LSBIS, etac set_mp, atac])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   656
    equiv_LSBISs), rtac sym, rtac (o_apply RS trans),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   657
    etac (sym RS arg_cong RS trans), rtac map_comp_id] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   658
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   659
fun mk_coalg_final_tac m coalg_def congruent_str_finals equiv_LSBISs set_map0ss coalgT_setss =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   660
  EVERY' [rtac (coalg_def RS iffD2),
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   661
    CONJ_WRAP' (fn ((set_map0s, coalgT_sets), (equiv_LSBIS, congruent_str_final)) =>
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   662
      EVERY' [rtac @{thm univ_preserves}, rtac equiv_LSBIS, rtac congruent_str_final,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   663
        rtac ballI, rtac @{thm ssubst_mem}, rtac o_apply, rtac CollectI,
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   664
        REPEAT_DETERM_N m o EVERY' [rtac conjI, rtac subset_UNIV],
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   665
        CONJ_WRAP' (fn (equiv_LSBIS, (set_map0, coalgT_set)) =>
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   666
          EVERY' [rtac (set_map0 RS ord_eq_le_trans),
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   667
            rtac @{thm image_subsetI}, rtac iffD2, rtac @{thm proj_in_iff},
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   668
            rtac equiv_LSBIS, etac set_rev_mp, etac coalgT_set])
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   669
        (equiv_LSBISs ~~ (drop m set_map0s ~~ coalgT_sets))])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   670
    ((set_map0ss ~~ coalgT_setss) ~~ (equiv_LSBISs ~~ congruent_str_finals))] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   671
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   672
fun mk_mor_T_final_tac mor_def congruent_str_finals equiv_LSBISs =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   673
  EVERY' [rtac (mor_def RS iffD2), rtac conjI,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   674
    CONJ_WRAP' (fn equiv_LSBIS =>
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   675
      EVERY' [rtac ballI, rtac iffD2, rtac @{thm proj_in_iff}, rtac equiv_LSBIS, atac])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   676
    equiv_LSBISs,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   677
    CONJ_WRAP' (fn (equiv_LSBIS, congruent_str_final) =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   678
      EVERY' [rtac ballI, rtac sym, rtac trans, rtac @{thm univ_commute}, rtac equiv_LSBIS,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   679
        rtac congruent_str_final, atac, rtac o_apply])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   680
    (equiv_LSBISs ~~ congruent_str_finals)] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   681
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   682
fun mk_mor_Rep_tac ctxt defs Reps Abs_inverses coalg_final_setss map_comp_ids map_cong0Ls =
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   683
  unfold_thms_tac ctxt defs THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   684
  EVERY' [rtac conjI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   685
    CONJ_WRAP' (fn thm => rtac ballI THEN' rtac thm) Reps,
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   686
    CONJ_WRAP' (fn (Rep, ((map_comp_id, map_cong0L), coalg_final_sets)) =>
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   687
      EVERY' [rtac ballI, rtac (map_comp_id RS trans), rtac map_cong0L,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   688
        EVERY' (map2 (fn Abs_inverse => fn coalg_final_set =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   689
          EVERY' [rtac ballI, rtac (o_apply RS trans), rtac Abs_inverse,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   690
            etac set_rev_mp, rtac coalg_final_set, rtac Rep])
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   691
        Abs_inverses coalg_final_sets)])
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   692
    (Reps ~~ ((map_comp_ids ~~ map_cong0Ls) ~~ coalg_final_setss))] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   693
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   694
fun mk_mor_Abs_tac ctxt defs Abs_inverses =
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   695
  unfold_thms_tac ctxt defs THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   696
  EVERY' [rtac conjI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   697
    CONJ_WRAP' (K (rtac ballI THEN' rtac UNIV_I)) Abs_inverses,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   698
    CONJ_WRAP' (fn thm => rtac ballI THEN' etac (thm RS arg_cong RS sym)) Abs_inverses] 1;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   699
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   700
fun mk_mor_unfold_tac m mor_UNIV dtor_defs unfold_defs Abs_inverses morEs map_comp_ids map_cong0s =
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   701
  EVERY' [rtac iffD2, rtac mor_UNIV,
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   702
    CONJ_WRAP' (fn ((Abs_inverse, morE), ((dtor_def, unfold_def), (map_comp_id, map_cong0))) =>
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   703
      EVERY' [rtac @{thm ext}, rtac (o_apply RS trans RS sym), rtac (dtor_def RS trans),
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   704
        rtac (unfold_def RS arg_cong RS trans), rtac (Abs_inverse RS arg_cong RS trans),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   705
        rtac (morE RS arg_cong RS trans), rtac (map_comp_id RS trans),
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   706
        rtac (o_apply RS trans RS sym), rtac map_cong0,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   707
        REPEAT_DETERM_N m o rtac refl,
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   708
        EVERY' (map (fn thm => rtac (thm RS trans) THEN' rtac (o_apply RS sym)) unfold_defs)])
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   709
    ((Abs_inverses ~~ morEs) ~~ ((dtor_defs ~~ unfold_defs) ~~ (map_comp_ids ~~ map_cong0s)))] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   710
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   711
fun mk_raw_coind_tac bis_def bis_cong bis_O bis_converse bis_Gr tcoalg coalgT mor_T_final
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   712
  sbis_lsbis lsbis_incls incl_lsbiss equiv_LSBISs mor_Rep Rep_injects =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   713
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   714
    val n = length Rep_injects;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   715
  in
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49463
diff changeset
   716
    EVERY' [rtac rev_mp, ftac (bis_def RS iffD1),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   717
      REPEAT_DETERM o etac conjE, rtac bis_cong, rtac bis_O, rtac bis_converse,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   718
      rtac bis_Gr, rtac tcoalg, rtac mor_Rep, rtac bis_O, atac, rtac bis_Gr, rtac tcoalg,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   719
      rtac mor_Rep, REPEAT_DETERM_N n o etac @{thm relImage_Gr},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   720
      rtac impI, rtac rev_mp, rtac bis_cong, rtac bis_O, rtac bis_Gr, rtac coalgT,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   721
      rtac mor_T_final, rtac bis_O, rtac sbis_lsbis, rtac bis_converse, rtac bis_Gr, rtac coalgT,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   722
      rtac mor_T_final, EVERY' (map (fn thm => rtac (thm RS @{thm relInvImage_Gr})) lsbis_incls),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   723
      rtac impI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   724
      CONJ_WRAP' (fn (Rep_inject, (equiv_LSBIS , (incl_lsbis, lsbis_incl))) =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   725
        EVERY' [rtac subset_trans, rtac @{thm relInvImage_UNIV_relImage}, rtac subset_trans,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   726
          rtac @{thm relInvImage_mono}, rtac subset_trans, etac incl_lsbis,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   727
          rtac ord_eq_le_trans, rtac @{thm sym[OF relImage_relInvImage]},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   728
          rtac @{thm xt1(3)}, rtac @{thm Sigma_cong},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   729
          rtac @{thm proj_image}, rtac @{thm proj_image}, rtac lsbis_incl,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   730
          rtac subset_trans, rtac @{thm relImage_mono}, rtac incl_lsbis, atac,
51447
a19e973fa2cf eliminate duplicated constant (diag vs. Id_on)
traytel
parents: 51070
diff changeset
   731
          rtac @{thm relImage_proj}, rtac equiv_LSBIS, rtac @{thm relInvImage_Id_on},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   732
          rtac Rep_inject])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   733
      (Rep_injects ~~ (equiv_LSBISs ~~ (incl_lsbiss ~~ lsbis_incls)))] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   734
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   735
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   736
fun mk_unfold_unique_mor_tac raw_coinds bis mor unfold_defs =
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   737
  CONJ_WRAP' (fn (raw_coind, unfold_def) =>
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   738
    EVERY' [rtac @{thm ext}, etac (bis RS raw_coind RS set_mp RS @{thm IdD}), rtac mor,
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   739
      rtac @{thm image2_eqI}, rtac refl, rtac (unfold_def RS arg_cong RS trans),
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   740
      rtac (o_apply RS sym), rtac UNIV_I]) (raw_coinds ~~ unfold_defs) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   741
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   742
fun mk_dtor_o_ctor_tac ctxt ctor_def unfold map_comp_id map_cong0L unfold_o_dtors =
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   743
  unfold_thms_tac ctxt [ctor_def] THEN EVERY' [rtac @{thm ext}, rtac trans, rtac o_apply,
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 51739
diff changeset
   744
    rtac trans, rtac unfold, rtac trans, rtac map_comp_id, rtac trans, rtac map_cong0L,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   745
    EVERY' (map (fn thm =>
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49581
diff changeset
   746
      rtac ballI THEN' rtac (trans OF [thm RS fun_cong, id_apply])) unfold_o_dtors),
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49581
diff changeset
   747
    rtac sym, rtac id_apply] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   748
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   749
fun mk_corec_tac ctxt m corec_defs unfold map_cong0 corec_Inls =
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   750
  unfold_thms_tac ctxt corec_defs THEN EVERY' [rtac trans, rtac (o_apply RS arg_cong),
55642
63beb38e9258 adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents: 55606
diff changeset
   751
    rtac trans, rtac unfold, fo_rtac (@{thm sum.case(2)} RS arg_cong RS trans) ctxt, rtac map_cong0,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   752
    REPEAT_DETERM_N m o rtac refl,
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   753
    EVERY' (map (fn thm => rtac @{thm case_sum_expand_Inr} THEN' rtac thm) corec_Inls)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   754
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   755
fun mk_corec_unique_mor_tac ctxt corec_defs corec_Inls unfold_unique_mor =
51739
3514b90d0a8b (co)rec is (just as the (un)fold) the unique morphism;
traytel
parents: 51447
diff changeset
   756
  unfold_thms_tac ctxt
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   757
    (corec_defs @ map (fn thm => thm RS @{thm case_sum_expand_Inr'}) corec_Inls) THEN
51739
3514b90d0a8b (co)rec is (just as the (un)fold) the unique morphism;
traytel
parents: 51447
diff changeset
   758
  etac unfold_unique_mor 1;
3514b90d0a8b (co)rec is (just as the (un)fold) the unique morphism;
traytel
parents: 51447
diff changeset
   759
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   760
fun mk_dtor_coinduct_tac m raw_coind bis_rel rel_congs =
56114
bc7335979247 tuned tactics
traytel
parents: 56113
diff changeset
   761
  EVERY' [rtac rev_mp, rtac raw_coind, rtac iffD2, rtac bis_rel, rtac conjI,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   762
    CONJ_WRAP' (K (rtac @{thm ord_le_eq_trans[OF subset_UNIV UNIV_Times_UNIV[THEN sym]]}))
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   763
    rel_congs,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   764
    CONJ_WRAP' (fn rel_cong => EVERY' [rtac allI, rtac allI, rtac impI,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   765
      REPEAT_DETERM o etac allE, rtac (rel_cong RS @{thm eq_refl} RS @{thm predicate2D}),
55541
fd9ea8ae28f6 syntactic simplifications of internal (co)datatype constructions
traytel
parents: 55414
diff changeset
   766
      REPEAT_DETERM_N m o rtac refl,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   767
      REPEAT_DETERM_N (length rel_congs) o rtac @{thm in_rel_Collect_split_eq[symmetric]},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   768
      etac mp, etac CollectE, etac @{thm splitD}])
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   769
    rel_congs,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   770
    rtac impI, REPEAT_DETERM o etac conjE,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   771
    CONJ_WRAP' (K (EVERY' [rtac impI, rtac @{thm IdD}, etac set_mp,
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   772
      rtac CollectI, etac @{thm case_prodI}])) rel_congs] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   773
55602
257bd115fcca made tactics more robust
traytel
parents: 55581
diff changeset
   774
fun mk_map_tac m n map_arg_cong unfold map_comp map_cong0 =
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   775
  EVERY' [rtac @{thm ext}, rtac (o_apply RS trans RS sym), rtac (o_apply RS trans RS sym),
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   776
    rtac (unfold RS trans), rtac (Thm.permute_prems 0 1 (map_comp RS @{thm box_equals})),
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   777
    rtac map_cong0,
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   778
    REPEAT_DETERM_N m o rtac (@{thm id_comp} RS fun_cong),
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   779
    REPEAT_DETERM_N n o rtac (@{thm comp_id} RS fun_cong),
55602
257bd115fcca made tactics more robust
traytel
parents: 55581
diff changeset
   780
    rtac map_arg_cong, rtac (o_apply RS sym)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   781
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   782
fun mk_set_le_tac n Jset_minimal set_Jsets set_Jset_Jsetss =
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   783
  EVERY' [rtac Jset_minimal,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   784
    REPEAT_DETERM_N n o rtac @{thm Un_upper1},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   785
    REPEAT_DETERM_N n o
58634
9f10d82e8188 added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents: 58446
diff changeset
   786
      EVERY' (@{map 3} (fn i => fn set_Jset => fn set_Jset_Jsets =>
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49328
diff changeset
   787
        EVERY' [rtac subsetI, rtac @{thm UnI2}, rtac (mk_UnIN n i), etac @{thm UN_I},
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   788
          etac UnE, etac set_Jset, REPEAT_DETERM_N (n - 1) o etac UnE,
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   789
          EVERY' (map (fn thm => EVERY' [etac @{thm UN_E}, etac thm, atac]) set_Jset_Jsets)])
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   790
      (1 upto n) set_Jsets set_Jset_Jsetss)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   791
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   792
fun mk_set_ge_tac n set_incl_Jset set_Jset_incl_Jsets =
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   793
  EVERY' [rtac @{thm Un_least}, rtac set_incl_Jset,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   794
    REPEAT_DETERM_N (n - 1) o rtac @{thm Un_least},
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   795
    EVERY' (map (fn thm => rtac @{thm UN_least} THEN' etac thm) set_Jset_incl_Jsets)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   796
53270
c8628119d18e renamed BNF axiom
blanchet
parents: 53105
diff changeset
   797
fun mk_map_id0_tac maps unfold_unique unfold_dtor =
52912
traytel
parents: 52911
diff changeset
   798
  EVERY' [rtac (unfold_unique RS trans), EVERY' (map (rtac o mk_sym) maps),
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   799
    rtac unfold_dtor] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   800
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   801
fun mk_map_comp0_tac maps map_comp0s map_unique =
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   802
  EVERY' [rtac map_unique,
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   803
    EVERY' (map2 (fn map_thm => fn map_comp0 =>
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   804
      EVERY' (map rtac
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   805
        [@{thm comp_assoc[symmetric]} RS trans,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   806
        @{thm arg_cong2[of _ _ _ _ "op o"]} OF [map_thm, refl] RS trans,
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   807
        @{thm comp_assoc[symmetric]} RS sym RS trans, map_thm RS arg_cong RS trans,
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   808
        @{thm comp_assoc[symmetric]} RS trans,
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   809
        @{thm arg_cong2[of _ _ _ _ "op o"]} OF [map_comp0 RS sym, refl]]))
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   810
    maps map_comp0s)] 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   811
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   812
fun mk_mcong_tac ctxt m coinduct_tac map_comps dtor_maps map_cong0s set_map0ss set_Jsetss
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   813
  set_Jset_Jsetsss in_rels =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   814
  let
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
   815
    val n = length map_comps;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   816
    val ks = 1 upto n;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   817
  in
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   818
    EVERY' ([rtac rev_mp, coinduct_tac] @
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   819
      maps (fn ((((((map_comp_trans, dtor_maps_trans), map_cong0), set_map0s), set_Jsets),
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   820
        set_Jset_Jsetss), in_rel) =>
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   821
        [REPEAT_DETERM o resolve_tac [allI, impI, in_rel RS iffD2],
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   822
         REPEAT_DETERM o eresolve_tac [exE, conjE], hyp_subst_tac ctxt, rtac exI,
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   823
         rtac (Drule.rotate_prems 1 conjI),
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
   824
         rtac conjI, rtac map_comp_trans, rtac sym, rtac dtor_maps_trans, rtac map_cong0,
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   825
         REPEAT_DETERM_N m o (rtac o_apply_trans_sym THEN' rtac @{thm fst_conv}),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   826
         REPEAT_DETERM_N n o rtac fst_convol_fun_cong_sym,
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
   827
         rtac map_comp_trans, rtac sym, rtac dtor_maps_trans, rtac map_cong0,
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   828
         EVERY' (maps (fn set_Jset =>
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   829
           [rtac o_apply_trans_sym, rtac (@{thm snd_conv} RS trans), etac CollectE,
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   830
           REPEAT_DETERM o etac conjE, etac bspec, etac set_Jset]) set_Jsets),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   831
         REPEAT_DETERM_N n o rtac snd_convol_fun_cong_sym,
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   832
         rtac CollectI,
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   833
         EVERY' (map (fn set_map0 => EVERY' [rtac conjI, rtac ord_eq_le_trans, rtac set_map0,
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   834
           rtac @{thm image_subsetI}, rtac CollectI, rtac @{thm case_prodI}, rtac refl])
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   835
        (take m set_map0s)),
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   836
         CONJ_WRAP' (fn (set_map0, set_Jset_Jsets) =>
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   837
           EVERY' [rtac ord_eq_le_trans, rtac set_map0,
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   838
             rtac @{thm image_subsetI}, rtac CollectI, rtac @{thm case_prodI}, rtac exI, rtac conjI,
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   839
             rtac CollectI, etac CollectE,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   840
             REPEAT_DETERM o etac conjE,
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   841
             CONJ_WRAP' (fn set_Jset_Jset =>
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   842
               EVERY' [rtac ballI, etac bspec, etac set_Jset_Jset, atac]) set_Jset_Jsets,
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
   843
             rtac (conjI OF [refl, refl])])
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   844
           (drop m set_map0s ~~ set_Jset_Jsetss)])
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
   845
        (map (fn th => th RS trans) map_comps ~~ map (fn th => th RS trans) dtor_maps ~~
56179
6b5c46582260 tuned internal construction
traytel
parents: 56114
diff changeset
   846
          map_cong0s ~~ set_map0ss ~~ set_Jsetss ~~ set_Jset_Jsetsss ~~ in_rels) @
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   847
      [rtac impI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   848
       CONJ_WRAP' (fn k =>
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   849
         EVERY' [rtac impI, dtac (mk_conjunctN n k), etac mp, rtac exI, rtac conjI, etac CollectI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   850
           rtac conjI, rtac refl, rtac refl]) ks]) 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   851
  end
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   852
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   853
fun mk_dtor_map_unique_tac ctxt unfold_unique sym_map_comps =
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   854
  rtac unfold_unique 1 THEN
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   855
  unfold_thms_tac ctxt (sym_map_comps @ @{thms comp_assoc[symmetric] id_comp comp_id}) THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   856
  ALLGOALS (etac sym);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   857
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   858
fun mk_col_natural_tac ctxt cts rec_0s rec_Sucs dtor_maps set_map0ss =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   859
  let
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49516
diff changeset
   860
    val n = length dtor_maps;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   861
  in
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   862
    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   863
      REPEAT_DETERM o rtac allI, SELECT_GOAL (unfold_thms_tac ctxt rec_0s),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   864
      CONJ_WRAP' (K (rtac @{thm image_empty})) rec_0s,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   865
      REPEAT_DETERM o rtac allI,
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49516
diff changeset
   866
      CONJ_WRAP' (fn (rec_Suc, (dtor_map, set_nats)) => EVERY'
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   867
        [SELECT_GOAL (unfold_thms_tac ctxt
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49516
diff changeset
   868
          (rec_Suc :: dtor_map :: set_nats @ @{thms image_Un image_UN UN_simps(10)})),
52659
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   869
        rtac Un_cong, rtac refl,
58b87aa4dc3b eliminate duplicated theorems (thanks to "Auto solve_direct" in jEdit)
traytel
parents: 52635
diff changeset
   870
        CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 Un_cong))
56248
67dc9549fa15 generalized and strengthened cong rules on compound operators, similar to 1ed737a98198
haftmann
parents: 56179
diff changeset
   871
          (fn i => EVERY' [rtac @{thm SUP_cong[OF refl]},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   872
            REPEAT_DETERM o etac allE, etac (mk_conjunctN n i)]) (n downto 1)])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   873
      (rec_Sucs ~~ (dtor_maps ~~ set_map0ss))] 1
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   874
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   875
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   876
fun mk_set_map0_tac col_natural =
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   877
  EVERY' (map rtac [@{thm ext}, o_apply RS trans, sym, o_apply RS trans, @{thm image_UN} RS trans,
56248
67dc9549fa15 generalized and strengthened cong rules on compound operators, similar to 1ed737a98198
haftmann
parents: 56179
diff changeset
   878
    refl RS @{thm SUP_cong}, col_natural]) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   879
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   880
fun mk_col_bd_tac m j cts rec_0s rec_Sucs sbd_Card_order sbd_Cinfinite set_sbdss =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   881
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   882
    val n = length rec_0s;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   883
  in
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   884
    EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   885
      REPEAT_DETERM o rtac allI,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   886
      CONJ_WRAP' (fn rec_0 => EVERY' (map rtac [ordIso_ordLeq_trans,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   887
        @{thm card_of_ordIso_subst}, rec_0, @{thm Card_order_empty}, sbd_Card_order])) rec_0s,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   888
      REPEAT_DETERM o rtac allI,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   889
      CONJ_WRAP' (fn (rec_Suc, set_sbds) => EVERY'
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   890
        [rtac ordIso_ordLeq_trans, rtac @{thm card_of_ordIso_subst}, rtac rec_Suc,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   891
        rtac (sbd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})), rtac (nth set_sbds (j - 1)),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   892
        REPEAT_DETERM_N (n - 1) o rtac (sbd_Cinfinite RSN (3, @{thm Un_Cinfinite_bound})),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   893
        EVERY' (map2 (fn i => fn set_sbd => EVERY' [rtac @{thm UNION_Cinfinite_bound},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   894
          rtac set_sbd, rtac ballI, REPEAT_DETERM o etac allE,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   895
          etac (mk_conjunctN n i), rtac sbd_Cinfinite]) (1 upto n) (drop m set_sbds))])
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   896
      (rec_Sucs ~~ set_sbdss)] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   897
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   898
56113
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   899
fun mk_set_bd_tac sbd_Cinfinite col_bd =
e3b8f8319d73 simplified internal codatatype construction
traytel
parents: 56017
diff changeset
   900
  EVERY' (map rtac [@{thm UNION_Cinfinite_bound}, ordIso_ordLeq_trans, @{thm card_of_nat},
54793
c99f0fdb0886 tighter bnf bounds for (co)datatypes
traytel
parents: 53289
diff changeset
   901
    @{thm natLeq_ordLeq_cinfinite}, sbd_Cinfinite, ballI, col_bd, sbd_Cinfinite]) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   902
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   903
fun mk_le_rel_OO_tac coinduct rel_Jrels le_rel_OOs =
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   904
  EVERY' (rtac coinduct :: map2 (fn rel_Jrel => fn le_rel_OO =>
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   905
    let val Jrel_imp_rel = rel_Jrel RS iffD1;
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   906
    in
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   907
      EVERY' [rtac (le_rel_OO RS @{thm predicate2D}), etac @{thm relcomppE},
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   908
      rtac @{thm relcomppI}, etac Jrel_imp_rel, etac Jrel_imp_rel]
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54793
diff changeset
   909
    end)
57726
18b8a8f10313 simplified tactics slightly
traytel
parents: 56765
diff changeset
   910
  rel_Jrels le_rel_OOs) 1;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   911
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   912
fun mk_wit_tac ctxt n dtor_ctors dtor_set wit coind_wits =
49104
6defdacd595a generate coinductive witnesses for codatatypes
traytel
parents: 49091
diff changeset
   913
  ALLGOALS (TRY o (eresolve_tac coind_wits THEN' rtac refl)) THEN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   914
  REPEAT_DETERM (atac 1 ORELSE
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49581
diff changeset
   915
    EVERY' [dtac set_rev_mp, rtac equalityD1, resolve_tac dtor_set,
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   916
    K (unfold_thms_tac ctxt dtor_ctors),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   917
    REPEAT_DETERM_N n o etac UnE,
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   918
    REPEAT_DETERM o
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   919
      (TRY o REPEAT_DETERM o etac UnE THEN' TRY o etac @{thm UN_E} THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   920
        (eresolve_tac wit ORELSE'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   921
        (dresolve_tac wit THEN'
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   922
          (etac FalseE ORELSE'
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   923
          EVERY' [hyp_subst_tac ctxt, dtac set_rev_mp, rtac equalityD1, resolve_tac dtor_set,
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   924
            K (unfold_thms_tac ctxt dtor_ctors), REPEAT_DETERM_N n o etac UnE]))))] 1);
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   925
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
   926
fun mk_coind_wit_tac ctxt induct unfolds set_nats wits =
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   927
  rtac induct 1 THEN ALLGOALS (TRY o rtac impI THEN' TRY o hyp_subst_tac ctxt) THEN
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49501
diff changeset
   928
  unfold_thms_tac ctxt (unfolds @ set_nats @ @{thms image_id id_apply}) THEN
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51782
diff changeset
   929
  ALLGOALS (REPEAT_DETERM o etac imageE THEN' TRY o hyp_subst_tac ctxt) THEN
49104
6defdacd595a generate coinductive witnesses for codatatypes
traytel
parents: 49091
diff changeset
   930
  ALLGOALS (TRY o
58445
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
   931
    FIRST' [rtac TrueI, rtac refl, etac (refl RSN (2, mp)), dresolve_tac wits THEN' etac FalseE]);
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
   932
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
   933
fun mk_dtor_corec_transfer_tac ctxt n m dtor_corec_defs dtor_unfold_transfer pre_T_map_transfers
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
   934
    dtor_rels =
58446
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   935
  CONJ_WRAP (fn (dtor_corec_def, dtor_unfold_transfer) =>
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   936
      REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   937
      unfold_thms_tac ctxt [dtor_corec_def, o_apply] THEN
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   938
      HEADGOAL (rtac (mk_rel_funDN (n + 1) dtor_unfold_transfer) THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   939
        EVERY' (map2 (fn pre_T_map_transfer => fn dtor_rel =>
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   940
          etac (mk_rel_funDN_rotated 2 @{thm case_sum_transfer}) THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   941
          rtac (mk_rel_funDN 2 @{thm comp_transfer}) THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   942
          rtac (mk_rel_funDN (m + n) pre_T_map_transfer) THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   943
          REPEAT_DETERM_N m o rtac @{thm id_transfer} THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   944
          REPEAT_DETERM_N n o rtac @{thm Inl_transfer} THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   945
          rtac rel_funI THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   946
          etac (dtor_rel RS iffD1)) pre_T_map_transfers dtor_rels) THEN'
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   947
        etac (mk_rel_funDN 1 @{thm Inr_transfer})))
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
   948
    (dtor_corec_defs ~~ dtor_unfold_transfer);
49104
6defdacd595a generate coinductive witnesses for codatatypes
traytel
parents: 49091
diff changeset
   949
53287
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
   950
fun mk_dtor_rel_tac ctxt in_Jrels i in_rel map_comp0 map_cong0 dtor_map dtor_sets dtor_inject
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   951
    dtor_ctor set_map0s dtor_set_incls dtor_set_set_inclss =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   952
  let
49544
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   953
    val m = length dtor_set_incls;
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   954
    val n = length dtor_set_set_inclss;
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   955
    val (passive_set_map0s, active_set_map0s) = chop m set_map0s;
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   956
    val in_Jrel = nth in_Jrels (i - 1);
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   957
    val if_tac =
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   958
      EVERY' [dtac (in_Jrel RS iffD1), REPEAT_DETERM o eresolve_tac [exE, conjE, CollectE],
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   959
        rtac (in_rel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   960
        EVERY' (map2 (fn set_map0 => fn set_incl =>
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   961
          EVERY' [rtac conjI, rtac ord_eq_le_trans, rtac set_map0,
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   962
            rtac ord_eq_le_trans, rtac trans_fun_cong_image_id_id_apply,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   963
            etac (set_incl RS @{thm subset_trans})])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   964
        passive_set_map0s dtor_set_incls),
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   965
        CONJ_WRAP' (fn (in_Jrel, (set_map0, dtor_set_set_incls)) =>
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   966
          EVERY' [rtac ord_eq_le_trans, rtac set_map0, rtac @{thm image_subsetI}, rtac CollectI,
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55393
diff changeset
   967
            rtac @{thm case_prodI}, rtac (in_Jrel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
49544
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   968
            CONJ_WRAP' (fn thm => etac (thm RS @{thm subset_trans}) THEN' atac) dtor_set_set_incls,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   969
            rtac conjI, rtac refl, rtac refl])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   970
        (in_Jrels ~~ (active_set_map0s ~~ dtor_set_set_inclss)),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   971
        CONJ_WRAP' (fn conv =>
53287
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
   972
          EVERY' [rtac trans, rtac map_comp0, rtac trans, rtac map_cong0,
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
   973
          REPEAT_DETERM_N m o rtac @{thm fun_cong[OF comp_id]},
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   974
          REPEAT_DETERM_N n o EVERY' (map rtac [trans, o_apply, conv]),
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49516
diff changeset
   975
          rtac trans, rtac sym, rtac dtor_map, rtac (dtor_inject RS iffD2), atac])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   976
        @{thms fst_conv snd_conv}];
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   977
    val only_if_tac =
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   978
      EVERY' [dtac (in_rel RS iffD1), REPEAT_DETERM o eresolve_tac [exE, conjE, CollectE],
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   979
        rtac (in_Jrel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   980
        CONJ_WRAP' (fn (dtor_set, passive_set_map0) =>
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49581
diff changeset
   981
          EVERY' [rtac ord_eq_le_trans, rtac dtor_set, rtac @{thm Un_least},
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   982
            rtac ord_eq_le_trans, rtac @{thm box_equals}, rtac passive_set_map0,
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   983
            rtac (dtor_ctor RS sym RS arg_cong), rtac trans_fun_cong_image_id_id_apply, atac,
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   984
            CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_least}))
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   985
              (fn (active_set_map0, in_Jrel) => EVERY' [rtac ord_eq_le_trans,
56248
67dc9549fa15 generalized and strengthened cong rules on compound operators, similar to 1ed737a98198
haftmann
parents: 56179
diff changeset
   986
                rtac @{thm SUP_cong[OF _ refl]}, rtac @{thm box_equals[OF _ _ refl]},
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   987
                rtac active_set_map0, rtac (dtor_ctor RS sym RS arg_cong), rtac @{thm UN_least},
49305
8241f21d104b tuned antiquotations
blanchet
parents: 49104
diff changeset
   988
                dtac set_rev_mp, etac @{thm image_mono}, etac imageE,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   989
                dtac @{thm ssubst_mem[OF pair_collapse]},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   990
                REPEAT_DETERM o eresolve_tac (CollectE :: conjE ::
56765
644f0d4820a1 cleaner 'rel_inject' theorems
blanchet
parents: 56248
diff changeset
   991
                  @{thms case_prodE iffD1[OF prod.inject, elim_format]}),
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   992
                hyp_subst_tac ctxt,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   993
                dtac (in_Jrel RS iffD1),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   994
                dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
   995
                REPEAT_DETERM o eresolve_tac [CollectE, conjE], atac])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   996
            (rev (active_set_map0s ~~ in_Jrels))])
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
   997
        (dtor_sets ~~ passive_set_map0s),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   998
        rtac conjI,
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49516
diff changeset
   999
        REPEAT_DETERM_N 2 o EVERY'[rtac (dtor_inject RS iffD1), rtac trans, rtac dtor_map,
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
  1000
          rtac @{thm box_equals}, rtac map_comp0, rtac (dtor_ctor RS sym RS arg_cong), rtac trans,
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
  1001
          rtac map_cong0, REPEAT_DETERM_N m o rtac @{thm fun_cong[OF comp_id]},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
  1002
          EVERY' (map (fn in_Jrel => EVERY' [rtac trans, rtac o_apply, dtac set_rev_mp, atac,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
  1003
            dtac @{thm ssubst_mem[OF pair_collapse]},
56765
644f0d4820a1 cleaner 'rel_inject' theorems
blanchet
parents: 56248
diff changeset
  1004
            REPEAT_DETERM o eresolve_tac (CollectE :: conjE ::
644f0d4820a1 cleaner 'rel_inject' theorems
blanchet
parents: 56248
diff changeset
  1005
              @{thms case_prodE iffD1[OF prod.inject, elim_format]}),
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
  1006
            hyp_subst_tac ctxt, dtac (in_Jrel RS iffD1),
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51850
diff changeset
  1007
            dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE, atac]) in_Jrels),
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
  1008
          atac]]
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
  1009
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
  1010
    EVERY' [rtac iffI, if_tac, only_if_tac] 1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
  1011
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
  1012
58445
86b5b02ef33a generate 'dtor_corec_transfer' for codatatypes
desharna
parents: 57983
diff changeset
  1013
fun mk_rel_coinduct_coind_tac ctxt fst m coinduct ks map_comp0s map_congs map_arg_congs set_map0ss
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1014
  dtor_unfolds dtor_maps in_rels =
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1015
  let
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1016
    val n = length ks;
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1017
    val fst_diag_nth = if fst then @{thm fst_diag_fst} else @{thm fst_diag_snd};
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1018
    val snd_diag_nth = if fst then @{thm snd_diag_fst} else @{thm snd_diag_snd};
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1019
  in
55602
257bd115fcca made tactics more robust
traytel
parents: 55581
diff changeset
  1020
    EVERY' [rtac coinduct,
58634
9f10d82e8188 added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents: 58446
diff changeset
  1021
      EVERY' (@{map 8} (fn i => fn map_comp0 => fn map_cong => fn map_arg_cong => fn set_map0s =>
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1022
          fn dtor_unfold => fn dtor_map => fn in_rel =>
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1023
        EVERY' [REPEAT_DETERM o resolve_tac [allI, impI, in_rel RS iffD2],
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1024
          REPEAT_DETERM o eresolve_tac [exE, conjE],
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1025
          select_prem_tac (length ks) (dtac @{thm spec2}) i, dtac mp, atac,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1026
          REPEAT_DETERM o eresolve_tac [CollectE, conjE], hyp_subst_tac ctxt,
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1027
          rtac exI, rtac (Drule.rotate_prems 1 conjI), rtac conjI,
53287
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
  1028
          rtac (map_comp0 RS trans), rtac (dtor_map RS trans RS sym),
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
  1029
          rtac (dtor_unfold RS map_arg_cong RS trans), rtac (trans OF [map_comp0, map_cong]),
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1030
          REPEAT_DETERM_N m o rtac (fst_diag_nth RS @{thm fun_cong[OF trans[OF o_id sym]]}),
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1031
          REPEAT_DETERM_N n o (rtac @{thm sym[OF trans[OF o_apply]]} THEN' rtac @{thm fst_conv}),
53287
271b34513bfb renamed BNF axiom
blanchet
parents: 53285
diff changeset
  1032
          rtac (map_comp0 RS trans), rtac (map_cong RS trans),
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1033
          REPEAT_DETERM_N m o rtac (snd_diag_nth RS fun_cong),
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1034
          REPEAT_DETERM_N n o (rtac @{thm trans[OF o_apply]} THEN' rtac @{thm snd_conv}),
55642
63beb38e9258 adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents: 55606
diff changeset
  1035
          etac (@{thm prod.case} RS map_arg_cong RS trans),
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1036
          SELECT_GOAL (unfold_thms_tac ctxt @{thms prod.case o_def fst_conv snd_conv}),
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1037
          rtac CollectI,
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1038
          CONJ_WRAP' (fn set_map0 =>
55644
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1039
            EVERY' [rtac (set_map0 RS ord_eq_le_trans),
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1040
              rtac @{thm image_subsetI}, rtac CollectI, rtac @{thm case_prodI},
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1041
              FIRST' [rtac refl, EVERY'[rtac exI, rtac conjI, etac Collect_splitD_set_mp, atac,
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1042
                rtac (@{thm surjective_pairing} RS arg_cong)]]])
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1043
          set_map0s])
b657146dc030 only one internal coinduction rule
traytel
parents: 55642
diff changeset
  1044
      ks map_comp0s map_congs map_arg_congs set_map0ss dtor_unfolds dtor_maps in_rels)] 1
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1045
  end;
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1046
55642
63beb38e9258 adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents: 55606
diff changeset
  1047
val split_id_unfolds = @{thms prod.case image_id id_apply};
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1048
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
  1049
fun mk_rel_coinduct_ind_tac ctxt m ks unfolds set_map0ss j set_induct =
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1050
  let val n = length ks;
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1051
  in
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1052
    rtac set_induct 1 THEN
58634
9f10d82e8188 added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents: 58446
diff changeset
  1053
    EVERY' (@{map 3} (fn unfold => fn set_map0s => fn i =>
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1054
      EVERY' [REPEAT_DETERM o resolve_tac [allI, impI], etac conjE,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1055
        select_prem_tac n (dtac @{thm spec2}) i, dtac mp, atac,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1056
        REPEAT_DETERM o eresolve_tac [CollectE, conjE, Collect_splitD_set_mp, set_rev_mp],
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1057
        hyp_subst_tac ctxt,
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1058
        SELECT_GOAL (unfold_thms_tac ctxt ([unfold, nth set_map0s (j - 1)] @ split_id_unfolds)),
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1059
        rtac subset_refl])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1060
    unfolds set_map0ss ks) 1 THEN
58634
9f10d82e8188 added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents: 58446
diff changeset
  1061
    EVERY' (@{map 3} (fn unfold => fn set_map0s => fn i =>
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1062
      EVERY' (map (fn set_map0 =>
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1063
        EVERY' [REPEAT_DETERM o resolve_tac [allI, impI], etac conjE,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1064
        select_prem_tac n (dtac @{thm spec2}) i, dtac mp, atac,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1065
        REPEAT_DETERM o eresolve_tac [CollectE, conjE], hyp_subst_tac ctxt,
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1066
        SELECT_GOAL (unfold_thms_tac ctxt ([unfold, set_map0] @ split_id_unfolds)),
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1067
        etac imageE, hyp_subst_tac ctxt, REPEAT_DETERM o eresolve_tac [allE, mp],
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1068
        rtac conjI, etac Collect_splitD_set_mp, atac, rtac (@{thm surjective_pairing} RS arg_cong)])
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1069
      (drop m set_map0s)))
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
  1070
    unfolds set_map0ss ks) 1
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1071
  end;
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1072
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55067
diff changeset
  1073
fun mk_rel_coinduct_tac ctxt CIHs in_rels in_Jrels helper_indss helper_coind1s helper_coind2s =
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1074
  let val n = length in_rels;
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1075
  in
52506
eb80a16a2b72 use long goal format in rel_induct theorem
traytel
parents: 51925
diff changeset
  1076
    Method.insert_tac CIHs 1 THEN
51925
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1077
    unfold_thms_tac ctxt (@{thm choice_iff} :: @{thm ex_simps(6)[symmetric]} :: in_rels) THEN
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1078
    REPEAT_DETERM (etac exE 1) THEN
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1079
    CONJ_WRAP' (fn (in_Jrel, (helper_inds, (helper_coind1, helper_coind2))) =>
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1080
      EVERY' [rtac @{thm predicate2I}, rtac (in_Jrel RS iffD2), rtac exI, rtac conjI,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1081
        if null helper_inds then rtac UNIV_I
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1082
        else rtac CollectI THEN'
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1083
          CONJ_WRAP' (fn helper_ind =>
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1084
            EVERY' [rtac (helper_ind RS rev_mp), REPEAT_DETERM_N n o atac,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1085
              REPEAT_DETERM_N n o etac thin_rl, rtac impI,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1086
              REPEAT_DETERM o resolve_tac [subsetI, CollectI, @{thm iffD2[OF split_beta]}],
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1087
              dtac bspec, atac, REPEAT_DETERM o eresolve_tac [allE, mp, conjE],
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1088
              etac (refl RSN (2, conjI))])
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1089
          helper_inds,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1090
        rtac conjI,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1091
        rtac (helper_coind1 RS rev_mp), REPEAT_DETERM_N n o atac, REPEAT_DETERM_N n o etac thin_rl,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1092
        rtac impI, etac mp, rtac exI, etac (refl RSN (2, conjI)),
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1093
        rtac (helper_coind2 RS rev_mp), REPEAT_DETERM_N n o atac, REPEAT_DETERM_N n o etac thin_rl,
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1094
        rtac impI, etac mp, rtac exI, etac (refl RSN (2, conjI))])
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1095
    (in_Jrels ~~ (helper_indss ~~ (helper_coind1s ~~ helper_coind2s))) 1
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1096
  end;
e3b7917186f1 relator coinduction for codatatypes
traytel
parents: 51893
diff changeset
  1097
55901
8c6d49dd8ae1 renamed a pair of low-level theorems to have c/dtor in their names (like the others)
blanchet
parents: 55644
diff changeset
  1098
fun mk_unfold_transfer_tac ctxt m ctor_rel_coinduct map_transfers unfolds =
52731
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1099
  let
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1100
    val n = length map_transfers;
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1101
  in
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1102
    unfold_thms_tac ctxt
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55901
diff changeset
  1103
      @{thms rel_fun_def_butlast all_conj_distrib[symmetric] imp_conjR[symmetric]} THEN
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55901
diff changeset
  1104
    unfold_thms_tac ctxt @{thms rel_fun_iff_geq_image2p} THEN
52731
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1105
    HEADGOAL (EVERY'
55901
8c6d49dd8ae1 renamed a pair of low-level theorems to have c/dtor in their names (like the others)
blanchet
parents: 55644
diff changeset
  1106
      [REPEAT_DETERM o resolve_tac [allI, impI], rtac ctor_rel_coinduct,
52731
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1107
      EVERY' (map (fn map_transfer => EVERY'
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1108
        [REPEAT_DETERM o resolve_tac [allI, impI], etac @{thm image2pE}, hyp_subst_tac ctxt,
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1109
        SELECT_GOAL (unfold_thms_tac ctxt unfolds),
58446
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58445
diff changeset
  1110
        rtac (funpow (m + n + 1) (fn thm => thm RS rel_funD) map_transfer),
52731
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1111
        REPEAT_DETERM_N m o rtac @{thm id_transfer},
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55901
diff changeset
  1112
        REPEAT_DETERM_N n o rtac @{thm rel_fun_image2p},
52731
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1113
        etac @{thm predicate2D}, etac @{thm image2pI}])
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1114
      map_transfers)])
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1115
  end;
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52659
diff changeset
  1116
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
  1117
end;