src/HOL/BNF/Tools/bnf_def_tactics.ML
changeset 51893 596baae88a88
parent 51798 ad3a241def73
child 51894 7c43b8df0f5d
equal deleted inserted replaced
51892:e5432ec161ff 51893:596baae88a88
    14   val mk_map_cong_tac: Proof.context -> thm -> tactic
    14   val mk_map_cong_tac: Proof.context -> thm -> tactic
    15   val mk_in_mono_tac: int -> tactic
    15   val mk_in_mono_tac: int -> tactic
    16   val mk_map_wppull_tac: thm -> thm -> thm -> thm -> thm list -> tactic
    16   val mk_map_wppull_tac: thm -> thm -> thm -> thm -> thm list -> tactic
    17   val mk_set_map': thm -> thm
    17   val mk_set_map': thm -> thm
    18 
    18 
    19   val mk_srel_Gr_tac: thm list -> thm -> thm -> thm -> thm -> thm list ->
    19   val mk_rel_Grp_tac: thm list -> thm -> thm -> thm -> thm -> thm list ->
    20     {prems: thm list, context: Proof.context} -> tactic
    20     {prems: thm list, context: Proof.context} -> tactic
    21   val mk_srel_Id_tac: int -> thm -> thm -> {prems: 'a, context: Proof.context} -> tactic
    21   val mk_rel_eq_tac: int -> thm -> thm -> thm -> {prems: 'a, context: Proof.context} -> tactic
    22   val mk_srel_O_tac: thm list -> thm -> thm -> thm -> thm -> thm list ->
    22   val mk_rel_OO_tac: thm list -> thm -> thm -> thm -> thm -> thm list ->
    23     {prems: thm list, context: Proof.context} -> tactic
    23     {prems: thm list, context: Proof.context} -> tactic
    24   val mk_in_srel_tac: thm list -> int -> {prems: 'b, context: Proof.context} -> tactic
    24   val mk_in_rel_tac: thm list -> {prems: 'b, context: Proof.context} -> tactic
    25   val mk_srel_converse_tac: thm -> tactic
    25   val mk_rel_conversep_tac: thm -> thm -> tactic
    26   val mk_srel_converse_le_tac: thm list -> thm -> thm -> thm -> thm list ->
    26   val mk_rel_conversep_le_tac: thm list -> thm -> thm -> thm -> thm list ->
    27     {prems: thm list, context: Proof.context} -> tactic
    27     {prems: thm list, context: Proof.context} -> tactic
    28   val mk_srel_mono_tac: thm list -> thm -> {prems: 'a, context: Proof.context} -> tactic
    28   val mk_rel_mono_tac: thm list -> thm -> {prems: 'a, context: Proof.context} -> tactic
    29 end;
    29 end;
    30 
    30 
    31 structure BNF_Def_Tactics : BNF_DEF_TACTICS =
    31 structure BNF_Def_Tactics : BNF_DEF_TACTICS =
    32 struct
    32 struct
    33 
    33 
    69       rtac (map_comp RS trans RS sym), rtac map_cong0,
    69       rtac (map_comp RS trans RS sym), rtac map_cong0,
    70       REPEAT_DETERM_N (length set_maps) o EVERY' [rtac (o_apply RS trans),
    70       REPEAT_DETERM_N (length set_maps) o EVERY' [rtac (o_apply RS trans),
    71         rtac (o_apply RS trans RS sym), rtac (o_apply RS trans), rtac thm,
    71         rtac (o_apply RS trans RS sym), rtac (o_apply RS trans), rtac thm,
    72         rtac conjunct2, etac bspec, etac set_mp, atac]]) [conjunct1, conjunct2]] 1;
    72         rtac conjunct2, etac bspec, etac set_mp, atac]]) [conjunct1, conjunct2]] 1;
    73 
    73 
    74 fun mk_srel_Gr_tac srel_O_Grs map_id map_cong0 map_id' map_comp set_maps
    74 fun mk_rel_Grp_tac rel_OO_Grps map_id map_cong0 map_id' map_comp set_maps
    75   {context = ctxt, prems = _} =
    75   {context = ctxt, prems = _} =
    76   let
    76   let
    77     val n = length set_maps;
    77     val n = length set_maps;
    78   in
    78   in
    79     if null set_maps then
    79     if null set_maps then
    80       unfold_thms_tac ctxt srel_O_Grs THEN EVERY' [rtac @{thm Gr_UNIV_id}, rtac map_id] 1
    80       unfold_thms_tac ctxt ((map_id RS @{thm Grp_UNIV_id}) :: rel_OO_Grps) THEN
    81     else unfold_thms_tac ctxt (@{thm Gr_def} :: srel_O_Grs) THEN
    81       rtac @{thm Grp_UNIV_idI[OF refl]} 1
    82       EVERY' [rtac equalityI, rtac subsetI,
    82     else unfold_thms_tac ctxt rel_OO_Grps THEN
    83         REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE, @{thm relcompE}, @{thm converseE}],
    83       EVERY' [rtac @{thm antisym}, rtac @{thm predicate2I},
    84         REPEAT_DETERM o dtac Pair_eqD,
    84         REPEAT_DETERM o
    85         REPEAT_DETERM o etac conjE, hyp_subst_tac ctxt,
    85           eresolve_tac [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
    86         rtac CollectI, rtac exI, rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl,
    86         hyp_subst_tac ctxt, rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac map_cong0,
    87         rtac sym, rtac trans, rtac map_comp, rtac map_cong0,
    87         REPEAT_DETERM_N n o EVERY' [rtac @{thm Collect_split_Grp_eqD}, etac @{thm set_mp}, atac],
    88         REPEAT_DETERM_N n o EVERY' [dtac @{thm set_rev_mp}, atac,
       
    89           REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE], hyp_subst_tac ctxt,
       
    90           rtac (o_apply RS trans), rtac (@{thm fst_conv} RS arg_cong RS trans),
       
    91           rtac (@{thm snd_conv} RS sym)],
       
    92         rtac CollectI,
    88         rtac CollectI,
    93         CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS @{thm ord_eq_le_trans}),
    89         CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS @{thm ord_eq_le_trans}),
    94           rtac @{thm image_subsetI}, dtac @{thm set_rev_mp}, atac,
    90           rtac @{thm image_subsetI}, rtac @{thm Collect_split_Grp_inD}, etac @{thm set_mp}, atac])
    95           REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE], hyp_subst_tac ctxt,
    91         set_maps,
    96           stac @{thm fst_conv}, atac]) set_maps,
    92         rtac @{thm predicate2I}, REPEAT_DETERM o eresolve_tac [@{thm GrpE}, exE, conjE],
    97         rtac @{thm subrelI}, etac CollectE, REPEAT_DETERM o eresolve_tac [exE, conjE],
    93         hyp_subst_tac ctxt,
    98         REPEAT_DETERM o dtac Pair_eqD,
    94         rtac @{thm relcomppI}, rtac @{thm conversepI},
    99         REPEAT_DETERM o etac conjE, hyp_subst_tac ctxt,
       
   100         rtac @{thm relcompI}, rtac @{thm converseI},
       
   101         EVERY' (map2 (fn convol => fn map_id =>
    95         EVERY' (map2 (fn convol => fn map_id =>
   102           EVERY' [rtac CollectI, rtac exI, rtac conjI,
    96           EVERY' [rtac @{thm GrpI}, rtac (box_equals OF [map_cong0, map_comp RS sym, map_id]),
   103             rtac Pair_eqI, rtac conjI, rtac refl, rtac sym,
       
   104             rtac (box_equals OF [map_cong0, map_comp RS sym, map_id]),
       
   105             REPEAT_DETERM_N n o rtac (convol RS fun_cong),
    97             REPEAT_DETERM_N n o rtac (convol RS fun_cong),
   106             REPEAT_DETERM o eresolve_tac [CollectE, conjE],
    98             REPEAT_DETERM o eresolve_tac [CollectE, conjE],
   107             rtac CollectI,
    99             rtac CollectI,
   108             CONJ_WRAP' (fn thm =>
   100             CONJ_WRAP' (fn thm =>
   109               EVERY' [rtac @{thm ord_eq_le_trans}, rtac thm, rtac @{thm image_subsetI},
   101               EVERY' [rtac @{thm ord_eq_le_trans}, rtac thm, rtac @{thm image_subsetI},
   110                 rtac @{thm convol_memI[of id _ "%x. x", OF id_apply refl]}, etac set_mp, atac])
   102                 rtac @{thm convol_mem_GrpI[OF refl]}, etac set_mp, atac])
   111             set_maps])
   103             set_maps])
   112           @{thms fst_convol snd_convol} [map_id', refl])] 1
   104           @{thms fst_convol snd_convol} [map_id', refl])] 1
   113   end;
   105   end;
   114 
   106 
   115 fun mk_srel_Id_tac n srel_Gr map_id {context = ctxt, prems = _} =
   107 fun mk_rel_eq_tac n rel_Grp rel_cong map_id {context = ctxt, prems = _} =
   116   unfold_thms_tac ctxt [srel_Gr, @{thm Id_alt}] THEN
   108   (EVERY' (rtac (rel_cong RS trans) :: replicate n (rtac @{thm eq_alt})) THEN'
   117   (if n = 0 then rtac refl 1
   109   rtac (rel_Grp RSN (2, @{thm box_equals[OF _ sym sym[OF eq_alt]]})) THEN'
   118   else EVERY' [rtac @{thm arg_cong2[of _ _ _ _ Gr]},
   110   (if n = 0 then rtac refl
   119     rtac equalityI, rtac subset_UNIV, rtac subsetI, rtac CollectI,
   111   else EVERY' [rtac @{thm arg_cong2[of _ _ _ _ "Grp"]},
   120     CONJ_WRAP' (K (rtac subset_UNIV)) (1 upto n), rtac map_id] 1);
   112     rtac @{thm equalityI}, rtac subset_UNIV, rtac subsetI, rtac CollectI,
       
   113     CONJ_WRAP' (K (rtac subset_UNIV)) (1 upto n), rtac map_id])) 1;
   121 
   114 
   122 fun mk_srel_mono_tac srel_O_Grs in_mono {context = ctxt, prems = _} =
   115 fun mk_rel_mono_tac rel_OO_Grps in_mono {context = ctxt, prems = _} =
   123   unfold_thms_tac ctxt srel_O_Grs THEN
   116   unfold_thms_tac ctxt rel_OO_Grps THEN
   124     EVERY' [rtac @{thm relcomp_mono}, rtac @{thm iffD2[OF converse_mono]},
   117     EVERY' [rtac @{thm relcompp_mono}, rtac @{thm iffD2[OF conversep_mono]},
   125       rtac @{thm Gr_mono}, rtac in_mono, REPEAT_DETERM o atac,
   118       rtac @{thm Grp_mono}, rtac in_mono, REPEAT_DETERM o etac @{thm Collect_split_mono},
   126       rtac @{thm Gr_mono}, rtac in_mono, REPEAT_DETERM o atac] 1;
   119       rtac @{thm Grp_mono}, rtac in_mono, REPEAT_DETERM o etac @{thm Collect_split_mono}] 1;
   127 
   120 
   128 fun mk_srel_converse_le_tac srel_O_Grs srel_Id map_cong0 map_comp set_maps
   121 fun mk_rel_conversep_le_tac rel_OO_Grps rel_eq map_cong0 map_comp set_maps
   129   {context = ctxt, prems = _} =
   122   {context = ctxt, prems = _} =
   130   let
   123   let
   131     val n = length set_maps;
   124     val n = length set_maps;
   132   in
   125   in
   133     if null set_maps then
   126     if null set_maps then rtac (rel_eq RS @{thm leq_conversepI}) 1
   134       unfold_thms_tac ctxt [srel_Id] THEN rtac equalityD2 1 THEN rtac @{thm converse_Id} 1
   127     else unfold_thms_tac ctxt (rel_OO_Grps) THEN
   135     else unfold_thms_tac ctxt (@{thm Gr_def} :: srel_O_Grs) THEN
   128       EVERY' [rtac @{thm predicate2I},
   136       EVERY' [rtac @{thm subrelI},
   129         REPEAT_DETERM o
   137         REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE, @{thm relcompE}, @{thm converseE}],
   130           eresolve_tac [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
   138         REPEAT_DETERM o dtac Pair_eqD,
   131         hyp_subst_tac ctxt, rtac @{thm conversepI}, rtac @{thm relcomppI}, rtac @{thm conversepI},
   139         REPEAT_DETERM o etac conjE, hyp_subst_tac ctxt, rtac @{thm converseI},
   132         EVERY' (map (fn thm => EVERY' [rtac @{thm GrpI}, rtac sym, rtac trans,
   140         rtac @{thm relcompI}, rtac @{thm converseI},
       
   141         EVERY' (map (fn thm => EVERY' [rtac CollectI, rtac exI,
       
   142           rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl, rtac trans,
       
   143           rtac map_cong0, REPEAT_DETERM_N n o rtac thm,
   133           rtac map_cong0, REPEAT_DETERM_N n o rtac thm,
   144           rtac (map_comp RS sym), rtac CollectI,
   134           rtac (map_comp RS sym), rtac CollectI,
   145           CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS @{thm ord_eq_le_trans}),
   135           CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS @{thm ord_eq_le_trans}),
   146             etac @{thm flip_rel}]) set_maps]) [@{thm snd_fst_flip}, @{thm fst_snd_flip}])] 1
   136             etac @{thm flip_pred}]) set_maps]) [@{thm snd_fst_flip}, @{thm fst_snd_flip}])] 1
   147   end;
   137   end;
   148 
   138 
   149 fun mk_srel_converse_tac le_converse =
   139 fun mk_rel_conversep_tac le_conversep rel_mono =
   150   EVERY' [rtac equalityI, rtac le_converse, rtac @{thm xt1(6)}, rtac @{thm converse_shift},
   140   EVERY' [rtac @{thm antisym}, rtac le_conversep, rtac @{thm xt1(6)}, rtac @{thm conversep_shift},
   151     rtac le_converse, REPEAT_DETERM o stac @{thm converse_converse}, rtac subset_refl] 1;
   141     rtac le_conversep, rtac @{thm iffD2[OF conversep_mono]}, rtac rel_mono,
       
   142     REPEAT_DETERM o rtac @{thm eq_refl[OF sym[OF conversep_conversep]]}] 1;
   152 
   143 
   153 fun mk_srel_O_tac srel_O_Grs srel_Id map_cong0 map_wppull map_comp set_maps
   144 fun mk_rel_OO_tac rel_OO_Grs rel_eq map_cong0 map_wppull map_comp set_maps
   154   {context = ctxt, prems = _} =
   145   {context = ctxt, prems = _} =
   155   let
   146   let
   156     val n = length set_maps;
   147     val n = length set_maps;
   157     fun in_tac nthO_in = rtac CollectI THEN'
   148     fun in_tac nthO_in = rtac CollectI THEN'
   158         CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS @{thm ord_eq_le_trans}),
   149         CONJ_WRAP' (fn thm => EVERY' [rtac (thm RS @{thm ord_eq_le_trans}),
   159           rtac @{thm image_subsetI}, rtac nthO_in, etac set_mp, atac]) set_maps;
   150           rtac @{thm image_subsetI}, rtac nthO_in, etac set_mp, atac]) set_maps;
   160   in
   151   in
   161     if null set_maps then unfold_thms_tac ctxt [srel_Id] THEN rtac (@{thm Id_O_R} RS sym) 1
   152     if null set_maps then rtac (rel_eq RS @{thm eq_OOI}) 1
   162     else unfold_thms_tac ctxt (@{thm Gr_def} :: srel_O_Grs) THEN
   153     else unfold_thms_tac ctxt rel_OO_Grs THEN
   163       EVERY' [rtac equalityI, rtac @{thm subrelI},
   154       EVERY' [rtac @{thm antisym}, rtac @{thm predicate2I},
   164         REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE, @{thm relcompE}, @{thm converseE}],
   155         REPEAT_DETERM o
   165         REPEAT_DETERM o dtac Pair_eqD,
   156           eresolve_tac [CollectE, exE, conjE, @{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
   166         REPEAT_DETERM o etac conjE, hyp_subst_tac ctxt,
   157         hyp_subst_tac ctxt,
   167         rtac @{thm relcompI}, rtac @{thm relcompI}, rtac @{thm converseI},
   158         rtac @{thm relcomppI}, rtac @{thm relcomppI}, rtac @{thm conversepI}, rtac @{thm GrpI},
   168         rtac CollectI, rtac exI, rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl,
   159         rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
   169         rtac sym, rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
   160         REPEAT_DETERM_N n o rtac @{thm fst_fstOp},
   170         REPEAT_DETERM_N n o rtac @{thm fst_fstO},
   161         in_tac @{thm fstOp_in},
   171         in_tac @{thm fstO_in},
   162         rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac map_cong0,
   172         rtac CollectI, rtac exI, rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl,
   163         REPEAT_DETERM_N n o EVERY' [rtac trans, rtac o_apply, 
   173         rtac sym, rtac trans, rtac map_comp, rtac map_cong0,
   164           rtac ballE, rtac subst,
   174         REPEAT_DETERM_N n o EVERY' [rtac trans, rtac o_apply, rtac ballE, rtac subst,
   165           rtac @{thm csquare_def}, rtac @{thm csquare_fstOp_sndOp}, atac, etac notE,
   175           rtac @{thm csquare_def}, rtac @{thm csquare_fstO_sndO}, atac, etac notE,
       
   176           etac set_mp, atac],
   166           etac set_mp, atac],
   177         in_tac @{thm fstO_in},
   167         in_tac @{thm fstOp_in},
   178         rtac @{thm relcompI}, rtac @{thm converseI},
   168         rtac @{thm relcomppI}, rtac @{thm conversepI}, rtac @{thm GrpI},
   179         rtac CollectI, rtac exI, rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl,
   169         rtac trans, rtac map_comp, rtac map_cong0,
   180         rtac sym, rtac trans, rtac map_comp, rtac map_cong0,
       
   181         REPEAT_DETERM_N n o rtac o_apply,
   170         REPEAT_DETERM_N n o rtac o_apply,
   182         in_tac @{thm sndO_in},
   171         in_tac @{thm sndOp_in},
   183         rtac CollectI, rtac exI, rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl,
   172         rtac @{thm GrpI}, rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
   184         rtac sym, rtac trans, rtac map_comp, rtac sym, rtac map_cong0,
   173         REPEAT_DETERM_N n o rtac @{thm snd_sndOp},
   185         REPEAT_DETERM_N n o rtac @{thm snd_sndO},
   174         in_tac @{thm sndOp_in},
   186         in_tac @{thm sndO_in},
   175         rtac @{thm predicate2I},
   187         rtac @{thm subrelI},
   176         REPEAT_DETERM o eresolve_tac [@{thm relcomppE}, @{thm conversepE}, @{thm GrpE}],
   188         REPEAT_DETERM o eresolve_tac [CollectE, @{thm relcompE}, @{thm converseE}],
   177         hyp_subst_tac ctxt,
   189         REPEAT_DETERM o eresolve_tac [exE, conjE],
       
   190         REPEAT_DETERM o dtac Pair_eqD,
       
   191         REPEAT_DETERM o etac conjE, hyp_subst_tac ctxt,
       
   192         rtac allE, rtac subst, rtac @{thm wppull_def}, rtac map_wppull,
   178         rtac allE, rtac subst, rtac @{thm wppull_def}, rtac map_wppull,
   193         CONJ_WRAP' (K (rtac @{thm wppull_fstO_sndO})) set_maps,
   179         CONJ_WRAP' (K (rtac @{thm wppull_fstOp_sndOp})) set_maps,
   194         etac allE, etac impE, etac conjI, etac conjI, atac,
   180         etac allE, etac impE, etac conjI, etac conjI, etac sym,
   195         REPEAT_DETERM o eresolve_tac [bexE, conjE],
   181         REPEAT_DETERM o eresolve_tac [bexE, conjE],
   196         rtac @{thm relcompI}, rtac @{thm converseI},
   182         rtac @{thm relcomppI}, rtac @{thm conversepI},
   197         EVERY' (map (fn thm => EVERY' [rtac CollectI, rtac exI,
   183         EVERY' (map (fn thm => EVERY' [rtac @{thm GrpI}, rtac trans,
   198           rtac conjI, rtac Pair_eqI, rtac conjI, rtac refl, rtac sym, rtac trans,
       
   199           rtac trans, rtac map_cong0, REPEAT_DETERM_N n o rtac thm,
   184           rtac trans, rtac map_cong0, REPEAT_DETERM_N n o rtac thm,
   200           rtac (map_comp RS sym), atac, atac]) [@{thm fst_fstO}, @{thm snd_sndO}])] 1
   185           rtac (map_comp RS sym), atac, atac]) [@{thm fst_fstOp}, @{thm snd_sndOp}])] 1
   201   end;
   186   end;
   202 
   187 
   203 fun mk_in_srel_tac srel_O_Grs m {context = ctxt, prems = _} =
   188 fun mk_in_rel_tac rel_OO_Grs {context = ctxt, prems = _} =
   204   let
   189   unfold_thms_tac ctxt rel_OO_Grs THEN
   205     val ls' = replicate (Int.max (1, m)) ();
   190   EVERY' [rtac iffI,
   206   in
   191     REPEAT_DETERM o eresolve_tac [@{thm GrpE}, @{thm relcomppE}, @{thm conversepE}],
   207     unfold_thms_tac ctxt (srel_O_Grs @
   192     hyp_subst_tac ctxt, rtac exI, rtac conjI, atac, rtac conjI, rtac refl, rtac refl,
   208       @{thms Gr_def converse_unfold relcomp_unfold mem_Collect_eq prod.cases Pair_eq}) THEN
   193     REPEAT_DETERM o eresolve_tac [exE, conjE], rtac @{thm relcomppI}, rtac @{thm conversepI},
   209     EVERY' [rtac iffI, REPEAT_DETERM o eresolve_tac [exE, conjE], hyp_subst_tac ctxt, rtac exI,
   194     etac @{thm GrpI}, atac, etac @{thm GrpI}, atac] 1;
   210       rtac conjI, CONJ_WRAP' (K atac) ls', rtac conjI, rtac refl, rtac refl,
       
   211       REPEAT_DETERM o eresolve_tac [exE, conjE], rtac exI, rtac conjI,
       
   212       REPEAT_DETERM_N 2 o EVERY' [rtac exI, rtac conjI, etac @{thm conjI[OF refl sym]},
       
   213         CONJ_WRAP' (K atac) ls']] 1
       
   214   end;
       
   215 
   195 
   216 end;
   196 end;