src/HOL/Tools/BNF/bnf_def_tactics.ML
author desharna
Mon, 06 Oct 2014 13:34:12 +0200
changeset 58568 727e014c6dbd
parent 58446 e89f57d1e46c
child 59498 50b60f501b05
permissions -rw-r--r--
add 'set_cases' to 'fp_sugar'
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_def_tactics.ML
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
57668
blanchet
parents: 56903
diff changeset
     4
    Author:     Martin Desharnais, TU Muenchen
blanchet
parents: 56903
diff changeset
     5
    Copyright   2012, 2013, 2014
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
     6
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
     7
Tactics for definition of bounded natural functors.
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
     8
*)
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
     9
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    10
signature BNF_DEF_TACTICS =
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    11
sig
51766
f19a4d0ab1bf renamed "set_natural" to "set_map", reflecting {Bl,Po,Tr} concensus
blanchet
parents: 51762
diff changeset
    12
  val mk_collect_set_map_tac: thm list -> tactic
56635
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    13
  val mk_in_mono_tac: int -> tactic
57970
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    14
  val mk_inj_map_strong_tac: Proof.context -> thm -> thm list -> thm -> tactic
56635
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    15
  val mk_inj_map_tac: int -> thm -> thm -> thm -> thm -> tactic
53285
f09645642984 renamed BNF fact
blanchet
parents: 53270
diff changeset
    16
  val mk_map_id: thm -> thm
56903
69b6369a98fa generate 'map_ident' theorem for BNFs
desharna
parents: 56635
diff changeset
    17
  val mk_map_ident: Proof.context -> thm -> thm
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
    18
  val mk_map_comp: thm -> thm
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51766
diff changeset
    19
  val mk_map_cong_tac: Proof.context -> thm -> tactic
53290
b6c3be868217 renamed BNF fact
blanchet
parents: 53289
diff changeset
    20
  val mk_set_map: thm -> thm
58106
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
    21
  val mk_set_transfer_tac: Proof.context -> thm -> thm list -> tactic
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    22
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    23
  val mk_rel_Grp_tac: Proof.context -> thm list -> thm -> thm -> thm -> thm -> thm list -> tactic
51894
traytel
parents: 51893
diff changeset
    24
  val mk_rel_eq_tac: int -> thm -> thm -> thm -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    25
  val mk_rel_OO_le_tac: Proof.context -> thm list -> thm -> thm -> thm -> thm list -> tactic
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
    26
  val mk_rel_conversep_tac: thm -> thm -> tactic
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    27
  val mk_rel_conversep_le_tac: Proof.context -> thm list -> thm -> thm -> thm -> thm list -> tactic
57932
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
    28
  val mk_rel_map0_tac: Proof.context -> int -> thm -> thm -> thm -> thm -> tactic
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
    29
  val mk_rel_mono_tac: thm list -> thm -> tactic
57967
e6d2e998c30f renamed 'rel_mono_strong' to 'rel_mono_strong0'
desharna
parents: 57932
diff changeset
    30
  val mk_rel_mono_strong0_tac: Proof.context -> thm -> thm list -> tactic
58104
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
    31
  val mk_rel_transfer_tac: Proof.context -> thm -> thm list -> thm -> tactic
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
    32
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    33
  val mk_map_transfer_tac: Proof.context -> thm -> thm -> thm list -> thm -> thm -> tactic
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
    34
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    35
  val mk_in_bd_tac: Proof.context -> int -> thm -> thm -> thm -> thm -> thm list -> thm list ->
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    36
    thm -> thm -> thm -> thm -> tactic
54189
c0186a0d8cb3 define a trivial nonemptiness witness if none is provided
traytel
parents: 53562
diff changeset
    37
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    38
  val mk_trivial_wit_tac: Proof.context -> thm list -> thm list -> tactic
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    39
end;
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    40
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    41
structure BNF_Def_Tactics : BNF_DEF_TACTICS =
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    42
struct
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    43
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    44
open BNF_Util
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    45
open BNF_Tactics
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    46
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
    47
val ord_eq_le_trans = @{thm ord_eq_le_trans};
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
    48
val ord_le_eq_trans = @{thm ord_le_eq_trans};
52749
ed416f4ac34e more converse(p) theorems; tuned proofs;
traytel
parents: 52731
diff changeset
    49
val conversep_shift = @{thm conversep_le_swap} RS iffD1;
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
    50
53285
f09645642984 renamed BNF fact
blanchet
parents: 53270
diff changeset
    51
fun mk_map_id id = mk_trans (fun_cong OF [id]) @{thm id_apply};
56903
69b6369a98fa generate 'map_ident' theorem for BNFs
desharna
parents: 56635
diff changeset
    52
fun mk_map_ident ctxt = unfold_thms ctxt @{thms id_def};
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
    53
fun mk_map_comp comp = @{thm comp_eq_dest_lhs} OF [mk_sym comp];
51798
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51766
diff changeset
    54
fun mk_map_cong_tac ctxt cong0 =
ad3a241def73 uniform Proof.context for hyp_subst_tac;
wenzelm
parents: 51766
diff changeset
    55
  (hyp_subst_tac ctxt THEN' rtac cong0 THEN'
51762
219a3063ed29 derive "map_cong"
blanchet
parents: 51761
diff changeset
    56
   REPEAT_DETERM o (dtac meta_spec THEN' etac meta_mp THEN' atac)) 1;
53290
b6c3be868217 renamed BNF fact
blanchet
parents: 53289
diff changeset
    57
fun mk_set_map set_map0 = set_map0 RS @{thm comp_eq_dest};
49490
394870e51d18 tuned antiquotations
traytel
parents: 49488
diff changeset
    58
fun mk_in_mono_tac n = if n = 0 then rtac subset_UNIV 1
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    59
  else (rtac subsetI THEN'
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    60
  rtac CollectI) 1 THEN
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    61
  REPEAT_DETERM (eresolve_tac [CollectE, conjE] 1) THEN
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    62
  REPEAT_DETERM_N (n - 1)
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    63
    ((rtac conjI THEN' etac subset_trans THEN' atac) 1) THEN
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    64
  (etac subset_trans THEN' atac) 1;
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    65
56635
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    66
fun mk_inj_map_tac n map_id map_comp map_cong0 map_cong =
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    67
  let
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    68
    val map_cong' = map_cong OF (asm_rl :: replicate n refl);
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    69
    val map_cong0' = map_cong0 OF (replicate n @{thm the_inv_f_o_f_id});
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    70
  in
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    71
    HEADGOAL (rtac @{thm injI} THEN' etac (map_cong' RS box_equals) THEN'
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    72
      REPEAT_DETERM_N 2 o (rtac (box_equals OF [map_cong0', map_comp RS sym, map_id]) THEN'
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    73
        REPEAT_DETERM_N n o atac))
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    74
  end;
b07c8ad23010 added 'inj_map' as auxiliary BNF theorem
blanchet
parents: 55990
diff changeset
    75
57970
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    76
fun mk_inj_map_strong_tac ctxt rel_eq rel_maps rel_mono_strong =
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    77
  let
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    78
    val rel_eq' = rel_eq RS @{thm predicate2_eqD};
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    79
    val rel_maps' = map (fn thm => thm RS iffD1) rel_maps;
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    80
  in
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    81
    HEADGOAL (dtac (rel_eq' RS iffD2) THEN' rtac (rel_eq' RS iffD1)) THEN
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    82
    EVERY (map (HEADGOAL o dtac) rel_maps') THEN
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    83
    HEADGOAL (etac rel_mono_strong) THEN
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    84
    TRYALL (Goal.assume_rule_tac ctxt)
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    85
  end;
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
    86
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
    87
fun mk_collect_set_map_tac set_map0s =
55067
a452de24a877 tuned names
blanchet
parents: 55061
diff changeset
    88
  (rtac (@{thm collect_comp} RS trans) THEN' rtac @{thm arg_cong[of _ _ collect]} THEN'
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
    89
  EVERY' (map (fn set_map0 =>
49623
1a0f25c38629 tuned tactic; got rid of substs_tac alias
traytel
parents: 49621
diff changeset
    90
    rtac (mk_trans @{thm image_insert} @{thm arg_cong2[of _ _ _ _ insert]}) THEN'
53289
5e0623448bdb renamed BNF axiom
blanchet
parents: 53288
diff changeset
    91
    rtac set_map0) set_map0s) THEN'
49623
1a0f25c38629 tuned tactic; got rid of substs_tac alias
traytel
parents: 49621
diff changeset
    92
  rtac @{thm image_empty}) 1;
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    93
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
    94
fun mk_rel_Grp_tac ctxt rel_OO_Grps map_id0 map_cong0 map_id map_comp set_maps =
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    95
  let
54792
traytel
parents: 54189
diff changeset
    96
    val n = length set_maps;
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
    97
    val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac else rtac (hd rel_OO_Grps RS trans);
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
    98
  in
54792
traytel
parents: 54189
diff changeset
    99
    if null set_maps then
53270
c8628119d18e renamed BNF axiom
blanchet
parents: 52986
diff changeset
   100
      unfold_thms_tac ctxt ((map_id0 RS @{thm Grp_UNIV_id}) :: rel_OO_Grps) THEN
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   101
      rtac @{thm Grp_UNIV_idI[OF refl]} 1
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   102
    else
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   103
      EVERY' [rel_OO_Grps_tac, rtac @{thm antisym}, rtac @{thm predicate2I},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   104
        REPEAT_DETERM o
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   105
          eresolve_tac [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
54792
traytel
parents: 54189
diff changeset
   106
        hyp_subst_tac ctxt, rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac map_cong0,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   107
        REPEAT_DETERM_N n o EVERY' [rtac @{thm Collect_split_Grp_eqD}, etac @{thm set_mp}, atac],
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   108
        rtac CollectI,
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   109
        CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS ord_eq_le_trans),
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   110
          rtac @{thm image_subsetI}, rtac @{thm Collect_split_Grp_inD}, etac @{thm set_mp}, atac])
54792
traytel
parents: 54189
diff changeset
   111
        set_maps,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   112
        rtac @{thm predicate2I}, REPEAT_DETERM o eresolve_tac [@{thm GrpE}, exE, conjE],
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   113
        hyp_subst_tac ctxt,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   114
        rtac @{thm relcomppI}, rtac @{thm conversepI},
53270
c8628119d18e renamed BNF axiom
blanchet
parents: 52986
diff changeset
   115
        EVERY' (map2 (fn convol => fn map_id0 =>
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   116
          EVERY' [rtac @{thm GrpI},
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   117
            rtac (@{thm box_equals} OF [map_cong0, map_comp RS sym, map_id0]),
49495
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49490
diff changeset
   118
            REPEAT_DETERM_N n o rtac (convol RS fun_cong),
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49490
diff changeset
   119
            REPEAT_DETERM o eresolve_tac [CollectE, conjE],
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49490
diff changeset
   120
            rtac CollectI,
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49490
diff changeset
   121
            CONJ_WRAP' (fn thm =>
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   122
              EVERY' [rtac ord_eq_le_trans, rtac thm, rtac @{thm image_subsetI},
52986
7f7bbeb16538 eliminated bogus assumption from theorem (that was instantiated with refl and resulted in flexflex pairs)
traytel
parents: 52844
diff changeset
   123
                rtac @{thm convol_mem_GrpI}, etac set_mp, atac])
54792
traytel
parents: 54189
diff changeset
   124
            set_maps])
53285
f09645642984 renamed BNF fact
blanchet
parents: 53270
diff changeset
   125
          @{thms fst_convol snd_convol} [map_id, refl])] 1
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   126
  end;
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   127
53270
c8628119d18e renamed BNF axiom
blanchet
parents: 52986
diff changeset
   128
fun mk_rel_eq_tac n rel_Grp rel_cong map_id0 =
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   129
  (EVERY' (rtac (rel_cong RS trans) :: replicate n (rtac @{thm eq_alt})) THEN'
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   130
  rtac (rel_Grp RSN (2, @{thm box_equals[OF _ sym sym[OF eq_alt]]})) THEN'
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   131
  (if n = 0 then rtac refl
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   132
  else EVERY' [rtac @{thm arg_cong2[of _ _ _ _ "Grp"]},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   133
    rtac @{thm equalityI}, rtac subset_UNIV, rtac subsetI, rtac CollectI,
53270
c8628119d18e renamed BNF axiom
blanchet
parents: 52986
diff changeset
   134
    CONJ_WRAP' (K (rtac subset_UNIV)) (1 upto n), rtac map_id0])) 1;
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   135
57932
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   136
fun mk_rel_map0_tac ctxt live rel_compp rel_conversep rel_Grp map_id =
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   137
  if live = 0 then
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   138
    HEADGOAL (Goal.conjunction_tac) THEN
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   139
    unfold_thms_tac ctxt @{thms id_apply} THEN
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   140
    ALLGOALS (rtac refl)
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   141
  else
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   142
    let
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   143
      val ks = 1 upto live;
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   144
    in
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   145
      Goal.conjunction_tac 1 THEN
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   146
      unfold_thms_tac ctxt [rel_compp, rel_conversep, rel_Grp, @{thm vimage2p_Grp}] THEN
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   147
      TRYALL (EVERY' [rtac iffI, rtac @{thm relcomppI}, rtac @{thm GrpI},
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   148
        resolve_tac [map_id, refl], rtac CollectI,
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   149
        CONJ_WRAP' (K (rtac @{thm subset_UNIV})) ks, rtac @{thm relcomppI}, atac,
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   150
        rtac @{thm conversepI}, rtac @{thm GrpI}, resolve_tac [map_id, refl], rtac CollectI,
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   151
        CONJ_WRAP' (K (rtac @{thm subset_UNIV})) ks,
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   152
        REPEAT_DETERM o eresolve_tac @{thms relcomppE conversepE GrpE},
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   153
        dtac (trans OF [sym, map_id]), hyp_subst_tac ctxt, atac])
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   154
    end;
c29659f77f8d generate 'rel_map' theorem for BNFs
desharna
parents: 57668
diff changeset
   155
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   156
fun mk_rel_mono_tac rel_OO_Grps in_mono =
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   157
  let
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   158
    val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   159
      else rtac (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   160
        rtac (hd rel_OO_Grps RS sym RSN (2, ord_le_eq_trans));
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   161
  in
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   162
    EVERY' [rel_OO_Grps_tac, rtac @{thm relcompp_mono}, rtac @{thm iffD2[OF conversep_mono]},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   163
      rtac @{thm Grp_mono}, rtac in_mono, REPEAT_DETERM o etac @{thm Collect_split_mono},
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   164
      rtac @{thm Grp_mono}, rtac in_mono, REPEAT_DETERM o etac @{thm Collect_split_mono}] 1
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   165
  end;
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   166
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
   167
fun mk_rel_conversep_le_tac ctxt rel_OO_Grps rel_eq map_cong0 map_comp set_maps =
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   168
  let
54792
traytel
parents: 54189
diff changeset
   169
    val n = length set_maps;
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   170
    val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   171
      else rtac (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   172
        rtac (hd rel_OO_Grps RS sym RS @{thm arg_cong[of _ _ conversep]} RSN (2, ord_le_eq_trans));
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   173
  in
54792
traytel
parents: 54189
diff changeset
   174
    if null set_maps then rtac (rel_eq RS @{thm leq_conversepI}) 1
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   175
    else
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   176
      EVERY' [rel_OO_Grps_tac, rtac @{thm predicate2I},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   177
        REPEAT_DETERM o
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   178
          eresolve_tac [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   179
        hyp_subst_tac ctxt, rtac @{thm conversepI}, rtac @{thm relcomppI}, rtac @{thm conversepI},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   180
        EVERY' (map (fn thm => EVERY' [rtac @{thm GrpI}, rtac sym, rtac trans,
51761
4c9f08836d87 renamed "map_cong" axiom to "map_cong0" in preparation for real "map_cong"
blanchet
parents: 49623
diff changeset
   181
          rtac map_cong0, REPEAT_DETERM_N n o rtac thm,
54792
traytel
parents: 54189
diff changeset
   182
          rtac (map_comp RS sym), rtac CollectI,
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   183
          CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS ord_eq_le_trans),
54792
traytel
parents: 54189
diff changeset
   184
            etac @{thm flip_pred}]) set_maps]) [@{thm snd_fst_flip}, @{thm fst_snd_flip}])] 1
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   185
  end;
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   186
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   187
fun mk_rel_conversep_tac le_conversep rel_mono =
52749
ed416f4ac34e more converse(p) theorems; tuned proofs;
traytel
parents: 52731
diff changeset
   188
  EVERY' [rtac @{thm antisym}, rtac le_conversep, rtac @{thm xt1(6)}, rtac conversep_shift,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   189
    rtac le_conversep, rtac @{thm iffD2[OF conversep_mono]}, rtac rel_mono,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   190
    REPEAT_DETERM o rtac @{thm eq_refl[OF sym[OF conversep_conversep]]}] 1;
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   191
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
   192
fun mk_rel_OO_le_tac ctxt rel_OO_Grps rel_eq map_cong0 map_comp set_maps =
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   193
  let
54792
traytel
parents: 54189
diff changeset
   194
    val n = length set_maps;
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   195
    fun in_tac nthO_in = rtac CollectI THEN'
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   196
        CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS ord_eq_le_trans),
54792
traytel
parents: 54189
diff changeset
   197
          rtac @{thm image_subsetI}, rtac nthO_in, etac set_mp, atac]) set_maps;
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   198
    val rel_OO_Grps_tac = if null rel_OO_Grps then K all_tac
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54792
diff changeset
   199
      else rtac (hd rel_OO_Grps RS ord_eq_le_trans) THEN'
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   200
        rtac (@{thm arg_cong2[of _ _ _ _ "op OO"]} OF (replicate 2 (hd rel_OO_Grps RS sym)) RSN
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54792
diff changeset
   201
          (2, ord_le_eq_trans));
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   202
  in
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54792
diff changeset
   203
    if null set_maps then rtac (rel_eq RS @{thm leq_OOI}) 1
52844
66fa0f602cc4 more robust tactics (don't use unfolding when RHS might contain schematics not contained on the LHS)
traytel
parents: 52813
diff changeset
   204
    else
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54792
diff changeset
   205
      EVERY' [rel_OO_Grps_tac, rtac @{thm predicate2I},
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   206
        REPEAT_DETERM o
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   207
          eresolve_tac [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   208
        hyp_subst_tac ctxt,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   209
        rtac @{thm relcomppI}, rtac @{thm relcomppI}, rtac @{thm conversepI}, rtac @{thm GrpI},
54792
traytel
parents: 54189
diff changeset
   210
        rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   211
        REPEAT_DETERM_N n o rtac @{thm fst_fstOp},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   212
        in_tac @{thm fstOp_in},
54792
traytel
parents: 54189
diff changeset
   213
        rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac map_cong0,
57970
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
   214
        REPEAT_DETERM_N n o EVERY' [rtac trans, rtac o_apply,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   215
          rtac ballE, rtac subst,
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   216
          rtac @{thm csquare_def}, rtac @{thm csquare_fstOp_sndOp}, atac, etac notE,
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   217
          etac set_mp, atac],
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   218
        in_tac @{thm fstOp_in},
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   219
        rtac @{thm relcomppI}, rtac @{thm conversepI}, rtac @{thm GrpI},
54792
traytel
parents: 54189
diff changeset
   220
        rtac trans, rtac map_comp, rtac map_cong0,
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   221
        REPEAT_DETERM_N n o rtac o_apply,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   222
        in_tac @{thm sndOp_in},
54792
traytel
parents: 54189
diff changeset
   223
        rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51798
diff changeset
   224
        REPEAT_DETERM_N n o rtac @{thm snd_sndOp},
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54792
diff changeset
   225
        in_tac @{thm sndOp_in}] 1
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   226
  end;
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   227
57967
e6d2e998c30f renamed 'rel_mono_strong' to 'rel_mono_strong0'
desharna
parents: 57932
diff changeset
   228
fun mk_rel_mono_strong0_tac ctxt in_rel set_maps =
54792
traytel
parents: 54189
diff changeset
   229
  if null set_maps then atac 1
51916
eac9e9a45bf5 stronger monotonicity property for relators
traytel
parents: 51915
diff changeset
   230
  else
54998
8601434fa334 tuned signature;
wenzelm
parents: 54841
diff changeset
   231
    unfold_tac ctxt [in_rel] THEN
51916
eac9e9a45bf5 stronger monotonicity property for relators
traytel
parents: 51915
diff changeset
   232
    REPEAT_DETERM (eresolve_tac [exE, CollectE, conjE] 1) THEN
eac9e9a45bf5 stronger monotonicity property for relators
traytel
parents: 51915
diff changeset
   233
    hyp_subst_tac ctxt 1 THEN
eac9e9a45bf5 stronger monotonicity property for relators
traytel
parents: 51915
diff changeset
   234
    EVERY' [rtac exI, rtac @{thm conjI[OF CollectI conjI[OF refl refl]]},
55163
a740f312d9e4 made tactic more robust
traytel
parents: 55067
diff changeset
   235
      CONJ_WRAP' (fn thm =>
a740f312d9e4 made tactic more robust
traytel
parents: 55067
diff changeset
   236
        (etac (@{thm Collect_split_mono_strong} OF [thm, thm]) THEN' atac))
a740f312d9e4 made tactic more robust
traytel
parents: 55067
diff changeset
   237
      set_maps] 1;
51916
eac9e9a45bf5 stronger monotonicity property for relators
traytel
parents: 51915
diff changeset
   238
58104
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   239
fun mk_rel_transfer_tac ctxt in_rel rel_map rel_mono_strong =
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   240
  let
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   241
    fun last_tac iffD =
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   242
      HEADGOAL (etac rel_mono_strong) THEN
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   243
      REPEAT_DETERM (HEADGOAL (etac (@{thm predicate2_transferD} RS iffD) THEN'
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   244
        REPEAT_DETERM o atac));
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   245
  in
58446
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58106
diff changeset
   246
    REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN
58104
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   247
    (HEADGOAL (hyp_subst_tac ctxt THEN' rtac refl) ORELSE
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   248
     REPEAT_DETERM (HEADGOAL (eresolve_tac (Tactic.make_elim (in_rel RS iffD1) ::
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   249
       @{thms exE conjE CollectE}))) THEN
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   250
     HEADGOAL (hyp_subst_tac ctxt) THEN unfold_thms_tac ctxt rel_map THEN HEADGOAL (rtac iffI) THEN
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   251
     last_tac iffD1 THEN last_tac iffD2)
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   252
  end;
c5316f843f72 generate 'rel_transfer' for BNFs
desharna
parents: 57970
diff changeset
   253
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
   254
fun mk_map_transfer_tac ctxt rel_mono in_rel set_maps map_cong0 map_comp =
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   255
  let
53290
b6c3be868217 renamed BNF fact
blanchet
parents: 53289
diff changeset
   256
    val n = length set_maps;
53562
9d8764624487 handle corner case in tactic
traytel
parents: 53561
diff changeset
   257
    val in_tac = if n = 0 then rtac UNIV_I else
9d8764624487 handle corner case in tactic
traytel
parents: 53561
diff changeset
   258
      rtac CollectI THEN' CONJ_WRAP' (fn thm =>
9d8764624487 handle corner case in tactic
traytel
parents: 53561
diff changeset
   259
        etac (thm RS
9d8764624487 handle corner case in tactic
traytel
parents: 53561
diff changeset
   260
          @{thm ord_eq_le_trans[OF _ subset_trans[OF image_mono convol_image_vimage2p]]}))
9d8764624487 handle corner case in tactic
traytel
parents: 53561
diff changeset
   261
      set_maps;
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   262
  in
58446
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58106
diff changeset
   263
    REPEAT_DETERM_N n (HEADGOAL (rtac rel_funI)) THEN
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55642
diff changeset
   264
    unfold_thms_tac ctxt @{thms rel_fun_iff_leq_vimage2p} THEN
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   265
    HEADGOAL (EVERY' [rtac @{thm order_trans}, rtac rel_mono, REPEAT_DETERM_N n o atac,
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   266
      rtac @{thm predicate2I}, dtac (in_rel RS iffD1),
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   267
      REPEAT_DETERM o eresolve_tac [exE, CollectE, conjE], hyp_subst_tac ctxt,
53562
9d8764624487 handle corner case in tactic
traytel
parents: 53561
diff changeset
   268
      rtac @{thm vimage2pI}, rtac (in_rel RS iffD2), rtac exI, rtac conjI, in_tac,
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   269
      rtac conjI,
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   270
      EVERY' (map (fn convol =>
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   271
        rtac (@{thm box_equals} OF [map_cong0, map_comp RS sym, map_comp RS sym]) THEN'
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   272
        REPEAT_DETERM_N n o rtac (convol RS fun_cong)) @{thms fst_convol snd_convol})])
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   273
  end;
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52659
diff changeset
   274
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
   275
fun mk_in_bd_tac ctxt live surj_imp_ordLeq_inst map_comp map_id map_cong0 set_maps set_bds
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
   276
  bd_card_order bd_Card_order bd_Cinfinite bd_Cnotzero =
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   277
  if live = 0 then
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   278
    rtac @{thm ordLeq_transitive[OF ordLeq_csum2[OF card_of_Card_order]
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   279
      ordLeq_cexp2[OF ordLeq_refl[OF Card_order_ctwo] Card_order_csum]]} 1
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   280
  else
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   281
    let
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   282
      val bd'_Cinfinite = bd_Cinfinite RS @{thm Cinfinite_csum1};
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   283
      val inserts =
57970
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
   284
        map (fn set_bd =>
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   285
          iffD2 OF [@{thm card_of_ordLeq}, @{thm ordLeq_ordIso_trans} OF
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   286
            [set_bd, bd_Card_order RS @{thm card_of_Field_ordIso} RS @{thm ordIso_symmetric}]])
57970
eaa986cd285a generate 'inj_map_strong' for BNFs
desharna
parents: 57967
diff changeset
   287
        set_bds;
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   288
    in
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   289
      EVERY' [rtac (Drule.rotate_prems 1 ctrans), rtac @{thm cprod_cinfinite_bound},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   290
        rtac (ctrans OF @{thms ordLeq_csum2 ordLeq_cexp2}), rtac @{thm card_of_Card_order},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   291
        rtac @{thm ordLeq_csum2}, rtac @{thm Card_order_ctwo}, rtac @{thm Card_order_csum},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   292
        rtac @{thm ordIso_ordLeq_trans}, rtac @{thm cexp_cong1},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   293
        if live = 1 then rtac @{thm ordIso_refl[OF Card_order_csum]}
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   294
        else
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   295
          REPEAT_DETERM_N (live - 2) o rtac @{thm ordIso_transitive[OF csum_cong2]} THEN'
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   296
          REPEAT_DETERM_N (live - 1) o rtac @{thm csum_csum},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   297
        rtac bd_Card_order, rtac (@{thm cexp_mono2_Cnotzero} RS ctrans), rtac @{thm ordLeq_csum1},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   298
        rtac bd_Card_order, rtac @{thm Card_order_csum}, rtac bd_Cnotzero,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   299
        rtac @{thm csum_Cfinite_cexp_Cinfinite},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   300
        rtac (if live = 1 then @{thm card_of_Card_order} else @{thm Card_order_csum}),
53290
b6c3be868217 renamed BNF fact
blanchet
parents: 53289
diff changeset
   301
        CONJ_WRAP_GEN' (rtac @{thm Cfinite_csum}) (K (rtac @{thm Cfinite_cone})) set_maps,
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   302
        rtac bd'_Cinfinite, rtac @{thm card_of_Card_order},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   303
        rtac @{thm Card_order_cexp}, rtac @{thm Cinfinite_cexp}, rtac @{thm ordLeq_csum2},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   304
        rtac @{thm Card_order_ctwo}, rtac bd'_Cinfinite,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   305
        rtac (Drule.rotate_prems 1 (@{thm cprod_mono2} RSN (2, ctrans))),
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   306
        REPEAT_DETERM_N (live - 1) o
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   307
          (rtac (bd_Cinfinite RS @{thm cprod_cexp_csum_cexp_Cinfinite} RSN (2, ctrans)) THEN'
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   308
           rtac @{thm ordLeq_ordIso_trans[OF cprod_mono2 ordIso_symmetric[OF cprod_cexp]]}),
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   309
        rtac @{thm ordLeq_refl[OF Card_order_cexp]}] 1 THEN
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   310
      unfold_thms_tac ctxt [bd_card_order RS @{thm card_order_csum_cone_cexp_def}] THEN
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   311
      unfold_thms_tac ctxt @{thms cprod_def Field_card_of} THEN
52813
963297a24206 more robust tactic
traytel
parents: 52749
diff changeset
   312
      EVERY' [rtac (Drule.rotate_prems 1 ctrans), rtac surj_imp_ordLeq_inst, rtac subsetI,
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   313
        Method.insert_tac inserts, REPEAT_DETERM o dtac meta_spec,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   314
        REPEAT_DETERM o eresolve_tac [exE, Tactic.make_elim conjunct1], etac CollectE,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   315
        if live = 1 then K all_tac
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   316
        else REPEAT_DETERM_N (live - 2) o (etac conjE THEN' rotate_tac ~1) THEN' etac conjE,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   317
        rtac (Drule.rotate_prems 1 @{thm image_eqI}), rtac @{thm SigmaI}, rtac @{thm UNIV_I},
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   318
        CONJ_WRAP_GEN' (rtac @{thm SigmaI})
53290
b6c3be868217 renamed BNF fact
blanchet
parents: 53289
diff changeset
   319
          (K (etac @{thm If_the_inv_into_in_Func} THEN' atac)) set_maps,
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   320
        rtac sym,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   321
        rtac (Drule.rotate_prems 1
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   322
           ((@{thm box_equals} OF [map_cong0 OF replicate live @{thm If_the_inv_into_f_f},
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
   323
             map_comp RS sym, map_id]) RSN (2, trans))),
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   324
        REPEAT_DETERM_N (2 * live) o atac,
55642
63beb38e9258 adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents: 55414
diff changeset
   325
        REPEAT_DETERM_N live o rtac (@{thm prod.case} RS trans),
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   326
        rtac refl,
52813
963297a24206 more robust tactic
traytel
parents: 52749
diff changeset
   327
        rtac @{thm surj_imp_ordLeq}, rtac subsetI, rtac (Drule.rotate_prems 1 @{thm image_eqI}),
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   328
        REPEAT_DETERM o eresolve_tac [CollectE, conjE], rtac CollectI,
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   329
        CONJ_WRAP' (fn thm =>
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   330
          rtac (thm RS ord_eq_le_trans) THEN' etac @{thm subset_trans[OF image_mono Un_upper1]})
53290
b6c3be868217 renamed BNF fact
blanchet
parents: 53289
diff changeset
   331
        set_maps,
52813
963297a24206 more robust tactic
traytel
parents: 52749
diff changeset
   332
        rtac sym,
55990
41c6b99c5fb7 more antiquotations;
wenzelm
parents: 55945
diff changeset
   333
        rtac (@{thm box_equals} OF [map_cong0 OF replicate live @{thm fun_cong[OF case_sum_o_inj(1)]},
53288
050d0bc9afa5 renamed BNF fact
blanchet
parents: 53287
diff changeset
   334
           map_comp RS sym, map_id])] 1
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 51916
diff changeset
   335
  end;
51916
eac9e9a45bf5 stronger monotonicity property for relators
traytel
parents: 51915
diff changeset
   336
55197
5a54ed681ba2 less hermetic tactics
traytel
parents: 55163
diff changeset
   337
fun mk_trivial_wit_tac ctxt wit_defs set_maps =
54189
c0186a0d8cb3 define a trivial nonemptiness witness if none is provided
traytel
parents: 53562
diff changeset
   338
  unfold_thms_tac ctxt wit_defs THEN HEADGOAL (EVERY' (map (fn thm =>
c0186a0d8cb3 define a trivial nonemptiness witness if none is provided
traytel
parents: 53562
diff changeset
   339
    dtac (thm RS equalityD1 RS set_mp) THEN' etac imageE THEN' atac) set_maps)) THEN ALLGOALS atac;
c0186a0d8cb3 define a trivial nonemptiness witness if none is provided
traytel
parents: 53562
diff changeset
   340
58106
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   341
fun mk_set_transfer_tac ctxt in_rel set_maps =
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   342
  Goal.conjunction_tac 1 THEN
58446
e89f57d1e46c generate 'rec_transfer' for datatypes
desharna
parents: 58106
diff changeset
   343
  EVERY (map (fn set_map => HEADGOAL (rtac rel_funI) THEN
58106
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   344
  REPEAT_DETERM (HEADGOAL (eresolve_tac (Tactic.make_elim (in_rel RS iffD1) ::
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   345
    @{thms exE conjE CollectE}))) THEN
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   346
  HEADGOAL (hyp_subst_tac ctxt THEN' rtac (@{thm iffD2[OF arg_cong2]} OF [set_map, set_map]) THEN'
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   347
    rtac @{thm rel_setI}) THEN
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   348
  REPEAT (HEADGOAL (etac imageE THEN' dtac @{thm set_mp} THEN' atac THEN'
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   349
    REPEAT_DETERM o (eresolve_tac @{thms CollectE case_prodE}) THEN' hyp_subst_tac ctxt THEN'
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   350
    rtac bexI THEN' etac @{thm subst_Pair[OF _ refl]} THEN' etac imageI))) set_maps);
c8cba801c483 generate 'set_transfer' for BNFs
desharna
parents: 58104
diff changeset
   351
49284
5f39b7940b49 spin off "bnf_def_tactics.ML"
blanchet
parents:
diff changeset
   352
end;