src/HOL/BNF/Tools/bnf_gfp_tactics.ML
changeset 49541 32fb6e4c7f4b
parent 49516 d4859efc1096
child 49542 b39354db8629
equal deleted inserted replaced
49540:b1bdbb099f99 49541:32fb6e4c7f4b
  1218         ext, o_apply RS trans,  o_apply RS trans RS sym, map_cong] @
  1218         ext, o_apply RS trans,  o_apply RS trans RS sym, map_cong] @
  1219         replicate m (@{thm id_o} RS fun_cong) @
  1219         replicate m (@{thm id_o} RS fun_cong) @
  1220         replicate n (@{thm o_id} RS fun_cong))))
  1220         replicate n (@{thm o_id} RS fun_cong))))
  1221     maps map_comps map_congs)] 1;
  1221     maps map_comps map_congs)] 1;
  1222 
  1222 
  1223 fun mk_mcong_tac m coinduct_tac map_comp's map_simps map_congs set_naturalss set_hsetss
  1223 fun mk_mcong_tac m coinduct_tac map_comp's dtor_maps map_congs set_naturalss set_hsetss
  1224   set_hset_hsetsss =
  1224   set_hset_hsetsss =
  1225   let
  1225   let
  1226     val n = length map_comp's;
  1226     val n = length map_comp's;
  1227     val ks = 1 upto n;
  1227     val ks = 1 upto n;
  1228   in
  1228   in
  1229     EVERY' ([rtac rev_mp,
  1229     EVERY' ([rtac rev_mp,
  1230       coinduct_tac] @
  1230       coinduct_tac] @
  1231       maps (fn (((((map_comp'_trans, map_simps_trans), map_cong), set_naturals), set_hsets),
  1231       maps (fn (((((map_comp'_trans, dtor_maps_trans), map_cong), set_naturals), set_hsets),
  1232         set_hset_hsetss) =>
  1232         set_hset_hsetss) =>
  1233         [REPEAT_DETERM o eresolve_tac [exE, conjE], hyp_subst_tac, rtac exI, rtac conjI, rtac conjI,
  1233         [REPEAT_DETERM o eresolve_tac [exE, conjE], hyp_subst_tac, rtac exI, rtac conjI, rtac conjI,
  1234          rtac map_comp'_trans, rtac sym, rtac map_simps_trans, rtac map_cong,
  1234          rtac map_comp'_trans, rtac sym, rtac dtor_maps_trans, rtac map_cong,
  1235          REPEAT_DETERM_N m o (rtac o_apply_trans_sym THEN' rtac @{thm id_apply}),
  1235          REPEAT_DETERM_N m o (rtac o_apply_trans_sym THEN' rtac @{thm id_apply}),
  1236          REPEAT_DETERM_N n o rtac fst_convol_fun_cong_sym,
  1236          REPEAT_DETERM_N n o rtac fst_convol_fun_cong_sym,
  1237          rtac map_comp'_trans, rtac sym, rtac map_simps_trans, rtac map_cong,
  1237          rtac map_comp'_trans, rtac sym, rtac dtor_maps_trans, rtac map_cong,
  1238          EVERY' (maps (fn set_hset =>
  1238          EVERY' (maps (fn set_hset =>
  1239            [rtac o_apply_trans_sym, rtac (@{thm id_apply} RS trans), etac CollectE,
  1239            [rtac o_apply_trans_sym, rtac (@{thm id_apply} RS trans), etac CollectE,
  1240            REPEAT_DETERM o etac conjE, etac bspec, etac set_hset]) set_hsets),
  1240            REPEAT_DETERM o etac conjE, etac bspec, etac set_hset]) set_hsets),
  1241          REPEAT_DETERM_N n o rtac snd_convol_fun_cong_sym,
  1241          REPEAT_DETERM_N n o rtac snd_convol_fun_cong_sym,
  1242          CONJ_WRAP' (fn (set_natural, set_hset_hsets) =>
  1242          CONJ_WRAP' (fn (set_natural, set_hset_hsets) =>
  1245              rtac @{thm image_mono}, rtac subsetI, rtac CollectI, etac CollectE,
  1245              rtac @{thm image_mono}, rtac subsetI, rtac CollectI, etac CollectE,
  1246              REPEAT_DETERM o etac conjE,
  1246              REPEAT_DETERM o etac conjE,
  1247              CONJ_WRAP' (fn set_hset_hset =>
  1247              CONJ_WRAP' (fn set_hset_hset =>
  1248                EVERY' [rtac ballI, etac bspec, etac set_hset_hset, atac]) set_hset_hsets])
  1248                EVERY' [rtac ballI, etac bspec, etac set_hset_hset, atac]) set_hset_hsets])
  1249            (drop m set_naturals ~~ set_hset_hsetss)])
  1249            (drop m set_naturals ~~ set_hset_hsetss)])
  1250         (map (fn th => th RS trans) map_comp's ~~ map (fn th => th RS trans) map_simps ~~
  1250         (map (fn th => th RS trans) map_comp's ~~ map (fn th => th RS trans) dtor_maps ~~
  1251           map_congs ~~ set_naturalss ~~ set_hsetss ~~ set_hset_hsetsss) @
  1251           map_congs ~~ set_naturalss ~~ set_hsetss ~~ set_hset_hsetsss) @
  1252       [rtac impI,
  1252       [rtac impI,
  1253        CONJ_WRAP' (fn k =>
  1253        CONJ_WRAP' (fn k =>
  1254          EVERY' [rtac impI, dtac (mk_conjunctN n k), etac mp, rtac exI, rtac conjI, etac CollectI,
  1254          EVERY' [rtac impI, dtac (mk_conjunctN n k), etac mp, rtac exI, rtac conjI, etac CollectI,
  1255            rtac conjI, rtac refl, rtac refl]) ks]) 1
  1255            rtac conjI, rtac refl, rtac refl]) ks]) 1
  1258 fun mk_map_unique_tac unfold_unique map_comps {context = ctxt, prems = _} =
  1258 fun mk_map_unique_tac unfold_unique map_comps {context = ctxt, prems = _} =
  1259   rtac unfold_unique 1 THEN
  1259   rtac unfold_unique 1 THEN
  1260   unfold_thms_tac ctxt (map (fn thm => thm RS sym) map_comps @ @{thms o_assoc id_o o_id}) THEN
  1260   unfold_thms_tac ctxt (map (fn thm => thm RS sym) map_comps @ @{thms o_assoc id_o o_id}) THEN
  1261   ALLGOALS (etac sym);
  1261   ALLGOALS (etac sym);
  1262 
  1262 
  1263 fun mk_col_natural_tac cts rec_0s rec_Sucs map_simps set_naturalss
  1263 fun mk_col_natural_tac cts rec_0s rec_Sucs dtor_maps set_naturalss
  1264   {context = ctxt, prems = _} =
  1264   {context = ctxt, prems = _} =
  1265   let
  1265   let
  1266     val n = length map_simps;
  1266     val n = length dtor_maps;
  1267   in
  1267   in
  1268     EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  1268     EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
  1269       REPEAT_DETERM o rtac allI, SELECT_GOAL (unfold_thms_tac ctxt rec_0s),
  1269       REPEAT_DETERM o rtac allI, SELECT_GOAL (unfold_thms_tac ctxt rec_0s),
  1270       CONJ_WRAP' (K (rtac @{thm image_empty})) rec_0s,
  1270       CONJ_WRAP' (K (rtac @{thm image_empty})) rec_0s,
  1271       REPEAT_DETERM o rtac allI,
  1271       REPEAT_DETERM o rtac allI,
  1272       CONJ_WRAP' (fn (rec_Suc, (map_simp, set_nats)) => EVERY'
  1272       CONJ_WRAP' (fn (rec_Suc, (dtor_map, set_nats)) => EVERY'
  1273         [SELECT_GOAL (unfold_thms_tac ctxt
  1273         [SELECT_GOAL (unfold_thms_tac ctxt
  1274           (rec_Suc :: map_simp :: set_nats @ @{thms image_Un image_UN UN_simps(10)})),
  1274           (rec_Suc :: dtor_map :: set_nats @ @{thms image_Un image_UN UN_simps(10)})),
  1275         rtac @{thm Un_cong}, rtac refl,
  1275         rtac @{thm Un_cong}, rtac refl,
  1276         CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_cong}))
  1276         CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_cong}))
  1277           (fn i => EVERY' [rtac @{thm UN_cong[OF refl]},
  1277           (fn i => EVERY' [rtac @{thm UN_cong[OF refl]},
  1278             REPEAT_DETERM o etac allE, etac (mk_conjunctN n i)]) (n downto 1)])
  1278             REPEAT_DETERM o etac allE, etac (mk_conjunctN n i)]) (n downto 1)])
  1279       (rec_Sucs ~~ (map_simps ~~ set_naturalss))] 1
  1279       (rec_Sucs ~~ (dtor_maps ~~ set_naturalss))] 1
  1280   end;
  1280   end;
  1281 
  1281 
  1282 fun mk_set_natural_tac hset_def col_natural =
  1282 fun mk_set_natural_tac hset_def col_natural =
  1283   EVERY' (map rtac [ext, (o_apply RS trans), (hset_def RS trans), sym,
  1283   EVERY' (map rtac [ext, (o_apply RS trans), (hset_def RS trans), sym,
  1284     (o_apply RS trans), (@{thm image_cong} OF [hset_def, refl] RS trans),
  1284     (o_apply RS trans), (@{thm image_cong} OF [hset_def, refl] RS trans),
  1492   unfold_thms_tac ctxt (unfolds @ set_nats @ @{thms image_id id_apply}) THEN
  1492   unfold_thms_tac ctxt (unfolds @ set_nats @ @{thms image_id id_apply}) THEN
  1493   ALLGOALS (REPEAT_DETERM o etac imageE THEN' TRY o hyp_subst_tac) THEN
  1493   ALLGOALS (REPEAT_DETERM o etac imageE THEN' TRY o hyp_subst_tac) THEN
  1494   ALLGOALS (TRY o
  1494   ALLGOALS (TRY o
  1495     FIRST' [rtac TrueI, rtac refl, etac (refl RSN (2, mp)), dresolve_tac wits THEN' etac FalseE])
  1495     FIRST' [rtac TrueI, rtac refl, etac (refl RSN (2, mp)), dresolve_tac wits THEN' etac FalseE])
  1496 
  1496 
  1497 fun mk_dtor_srel_tac in_Jsrels i in_srel map_comp map_cong map_simp set_simps dtor_inject dtor_ctor
  1497 fun mk_dtor_srel_tac in_Jsrels i in_srel map_comp map_cong dtor_map set_simps dtor_inject dtor_ctor
  1498   set_naturals set_incls set_set_inclss =
  1498   set_naturals set_incls set_set_inclss =
  1499   let
  1499   let
  1500     val m = length set_incls;
  1500     val m = length set_incls;
  1501     val n = length set_set_inclss;
  1501     val n = length set_set_inclss;
  1502     val (passive_set_naturals, active_set_naturals) = chop m set_naturals;
  1502     val (passive_set_naturals, active_set_naturals) = chop m set_naturals;
  1517         (in_Jsrels ~~ (active_set_naturals ~~ set_set_inclss)),
  1517         (in_Jsrels ~~ (active_set_naturals ~~ set_set_inclss)),
  1518         CONJ_WRAP' (fn conv =>
  1518         CONJ_WRAP' (fn conv =>
  1519           EVERY' [rtac trans, rtac map_comp, rtac trans, rtac map_cong,
  1519           EVERY' [rtac trans, rtac map_comp, rtac trans, rtac map_cong,
  1520           REPEAT_DETERM_N m o rtac @{thm fun_cong[OF o_id]},
  1520           REPEAT_DETERM_N m o rtac @{thm fun_cong[OF o_id]},
  1521           REPEAT_DETERM_N n o EVERY' (map rtac [trans, o_apply, conv]),
  1521           REPEAT_DETERM_N n o EVERY' (map rtac [trans, o_apply, conv]),
  1522           rtac trans, rtac sym, rtac map_simp, rtac (dtor_inject RS iffD2), atac])
  1522           rtac trans, rtac sym, rtac dtor_map, rtac (dtor_inject RS iffD2), atac])
  1523         @{thms fst_conv snd_conv}];
  1523         @{thms fst_conv snd_conv}];
  1524     val only_if_tac =
  1524     val only_if_tac =
  1525       EVERY' [dtac (in_srel RS iffD1), REPEAT_DETERM o eresolve_tac [exE, conjE, CollectE],
  1525       EVERY' [dtac (in_srel RS iffD1), REPEAT_DETERM o eresolve_tac [exE, conjE, CollectE],
  1526         rtac (in_Jsrel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
  1526         rtac (in_Jsrel RS iffD2), rtac exI, rtac conjI, rtac CollectI,
  1527         CONJ_WRAP' (fn (set_simp, passive_set_natural) =>
  1527         CONJ_WRAP' (fn (set_simp, passive_set_natural) =>
  1538                 dtac (Thm.permute_prems 0 1 @{thm ssubst_mem}), atac,
  1538                 dtac (Thm.permute_prems 0 1 @{thm ssubst_mem}), atac,
  1539                 hyp_subst_tac, REPEAT_DETERM o eresolve_tac [CollectE, conjE], atac])
  1539                 hyp_subst_tac, REPEAT_DETERM o eresolve_tac [CollectE, conjE], atac])
  1540             (rev (active_set_naturals ~~ in_Jsrels))])
  1540             (rev (active_set_naturals ~~ in_Jsrels))])
  1541         (set_simps ~~ passive_set_naturals),
  1541         (set_simps ~~ passive_set_naturals),
  1542         rtac conjI,
  1542         rtac conjI,
  1543         REPEAT_DETERM_N 2 o EVERY'[rtac (dtor_inject RS iffD1), rtac trans, rtac map_simp,
  1543         REPEAT_DETERM_N 2 o EVERY'[rtac (dtor_inject RS iffD1), rtac trans, rtac dtor_map,
  1544           rtac box_equals, rtac map_comp, rtac (dtor_ctor RS sym RS arg_cong), rtac trans,
  1544           rtac box_equals, rtac map_comp, rtac (dtor_ctor RS sym RS arg_cong), rtac trans,
  1545           rtac map_cong, REPEAT_DETERM_N m o rtac @{thm fun_cong[OF o_id]},
  1545           rtac map_cong, REPEAT_DETERM_N m o rtac @{thm fun_cong[OF o_id]},
  1546           EVERY' (map (fn in_Jsrel => EVERY' [rtac trans, rtac o_apply, dtac set_rev_mp, atac,
  1546           EVERY' (map (fn in_Jsrel => EVERY' [rtac trans, rtac o_apply, dtac set_rev_mp, atac,
  1547             dtac @{thm ssubst_mem[OF pair_collapse]}, dtac (in_Jsrel RS iffD1),
  1547             dtac @{thm ssubst_mem[OF pair_collapse]}, dtac (in_Jsrel RS iffD1),
  1548             dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE, atac]) in_Jsrels),
  1548             dtac @{thm someI_ex}, REPEAT_DETERM o etac conjE, atac]) in_Jsrels),