src/HOL/Tools/BNF/bnf_gfp_tactics.ML
changeset 55577 a6c2379078c8
parent 55541 fd9ea8ae28f6
child 55581 d1c228753d76
equal deleted inserted replaced
55576:315dd5920114 55577:a6c2379078c8
     7 Tactics for the codatatype construction.
     7 Tactics for the codatatype construction.
     8 *)
     8 *)
     9 
     9 
    10 signature BNF_GFP_TACTICS =
    10 signature BNF_GFP_TACTICS =
    11 sig
    11 sig
    12   val mk_Lev_sbd_tac: Proof.context -> cterm option list -> thm list -> thm list -> thm list list ->
       
    13     tactic
       
    14   val mk_bis_Gr_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> thm list -> tactic
    12   val mk_bis_Gr_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> thm list -> tactic
    15   val mk_bis_O_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
    13   val mk_bis_O_tac: Proof.context -> int -> thm -> thm list -> thm list -> tactic
    16   val mk_bis_Union_tac: Proof.context -> thm -> thm list -> tactic
    14   val mk_bis_Union_tac: Proof.context -> thm -> thm list -> tactic
    17   val mk_bis_converse_tac: int -> thm -> thm list -> thm list -> tactic
    15   val mk_bis_converse_tac: int -> thm -> thm list -> thm list -> tactic
    18   val mk_bis_rel_tac: Proof.context -> int -> thm -> thm list -> thm list -> thm list ->
    16   val mk_bis_rel_tac: Proof.context -> int -> thm -> thm list -> thm list -> thm list ->
    52     thm list -> thm list -> tactic
    50     thm list -> thm list -> tactic
    53   val mk_mor_T_final_tac: thm -> thm list -> thm list -> tactic
    51   val mk_mor_T_final_tac: thm -> thm list -> thm list -> tactic
    54   val mk_mor_UNIV_tac: thm list -> thm -> tactic
    52   val mk_mor_UNIV_tac: thm list -> thm -> tactic
    55   val mk_mor_beh_tac: Proof.context -> int -> thm -> thm -> thm list -> thm list -> thm list ->
    53   val mk_mor_beh_tac: Proof.context -> int -> thm -> thm -> thm list -> thm list -> thm list ->
    56     thm list -> thm list list -> thm list list -> thm list -> thm list -> thm list -> thm list ->
    54     thm list -> thm list list -> thm list list -> thm list -> thm list -> thm list -> thm list ->
    57     thm list -> thm list -> thm list -> thm list -> thm list list -> thm list list list ->
    55     thm list -> thm list -> thm list list -> thm list list list -> thm list list list ->
    58     thm list list list -> thm list list -> thm list -> thm list -> thm list -> tactic
    56     thm list list -> thm list -> thm list -> tactic
    59   val mk_mor_case_sum_tac: 'a list -> thm -> tactic
    57   val mk_mor_case_sum_tac: 'a list -> thm -> tactic
    60   val mk_mor_comp_tac: thm -> thm list -> thm list -> thm list -> tactic
    58   val mk_mor_comp_tac: thm -> thm list -> thm list -> thm list -> tactic
    61   val mk_mor_elim_tac: thm -> tactic
    59   val mk_mor_elim_tac: thm -> tactic
    62   val mk_mor_hset_rec_tac: int -> int -> cterm option list -> int -> thm list -> thm list ->
    60   val mk_mor_hset_rec_tac: int -> int -> cterm option list -> int -> thm list -> thm list ->
    63     thm list -> thm list list -> thm list list -> tactic
    61     thm list -> thm list list -> thm list list -> tactic
    64   val mk_mor_incl_tac: thm -> thm list -> tactic
    62   val mk_mor_incl_tac: thm -> thm list -> tactic
    65   val mk_mor_str_tac: 'a list -> thm -> tactic
    63   val mk_mor_str_tac: 'a list -> thm -> tactic
    66   val mk_mor_unfold_tac: int -> thm -> thm list -> thm list -> thm list -> thm list -> thm list ->
    64   val mk_mor_unfold_tac: int -> thm -> thm list -> thm list -> thm list -> thm list -> thm list ->
    67     thm list -> tactic
    65     thm list -> tactic
    68   val mk_prefCl_Lev_tac: Proof.context -> cterm option list -> thm list -> thm list -> tactic
       
    69   val mk_raw_coind_tac: thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm list ->
    66   val mk_raw_coind_tac: thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm -> thm list ->
    70     thm list -> thm list -> thm -> thm list -> tactic
    67     thm list -> thm list -> thm -> thm list -> tactic
    71   val mk_rel_coinduct_tac: Proof.context -> thm list -> thm list -> thm list -> thm list list ->
    68   val mk_rel_coinduct_tac: Proof.context -> thm list -> thm list -> thm list -> thm list list ->
    72     thm list -> thm list -> tactic
    69     thm list -> thm list -> tactic
    73   val mk_rel_coinduct_coind_tac: Proof.context -> int -> thm -> int list -> thm list -> thm list ->
    70   val mk_rel_coinduct_coind_tac: Proof.context -> int -> thm -> int list -> thm list -> thm list ->
   370         CONJ_WRAP' (fn (i, thm) => EVERY' [rtac (thm RS ord_eq_le_trans),
   367         CONJ_WRAP' (fn (i, thm) => EVERY' [rtac (thm RS ord_eq_le_trans),
   371           rtac @{thm image_subsetI}, rtac CollectI, rtac exI, rtac exI, rtac conjI, rtac refl,
   368           rtac @{thm image_subsetI}, rtac CollectI, rtac exI, rtac exI, rtac conjI, rtac refl,
   372           rtac conjI,
   369           rtac conjI,
   373           rtac conjI, etac @{thm empty_Shift}, dtac set_rev_mp,
   370           rtac conjI, etac @{thm empty_Shift}, dtac set_rev_mp,
   374             etac equalityD1, etac CollectD,
   371             etac equalityD1, etac CollectD,
   375           rtac conjI, etac @{thm Shift_clists},
   372           rtac ballI,
   376           rtac conjI, etac @{thm Shift_prefCl},
       
   377           rtac conjI, rtac ballI,
       
   378             rtac conjI, dtac @{thm iffD1[OF ball_conj_distrib]}, dtac conjunct1,
   373             rtac conjI, dtac @{thm iffD1[OF ball_conj_distrib]}, dtac conjunct1,
   379             SELECT_GOAL (unfold_thms_tac ctxt @{thms Succ_Shift shift_def}),
   374             SELECT_GOAL (unfold_thms_tac ctxt @{thms Succ_Shift shift_def}),
   380             etac bspec, etac @{thm ShiftD},
   375             etac bspec, etac @{thm ShiftD},
   381             CONJ_WRAP' (fn i => EVERY' [rtac ballI, etac CollectE, dtac @{thm ShiftD},
   376             CONJ_WRAP' (fn i => EVERY' [rtac ballI, etac CollectE, dtac @{thm ShiftD},
   382               dtac bspec, etac thin_rl, atac, dtac conjunct2, dtac (mk_conjunctN n i),
   377               dtac bspec, etac thin_rl, atac, dtac conjunct2, dtac (mk_conjunctN n i),
   385               rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
   380               rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
   386               rtac (@{thm append_Cons} RS sym RS arg_cong RS trans), atac,
   381               rtac (@{thm append_Cons} RS sym RS arg_cong RS trans), atac,
   387               CONJ_WRAP' (K (EVERY' [etac trans, rtac @{thm Collect_cong},
   382               CONJ_WRAP' (K (EVERY' [etac trans, rtac @{thm Collect_cong},
   388                 rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
   383                 rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
   389                 rtac (@{thm append_Cons} RS sym RS arg_cong)])) ks]) ks,
   384                 rtac (@{thm append_Cons} RS sym RS arg_cong)])) ks]) ks,
   390           rtac allI, rtac impI, REPEAT_DETERM o eresolve_tac [allE, impE],
       
   391           etac @{thm not_in_Shift}, rtac trans, rtac (@{thm shift_def} RS fun_cong), atac,
       
   392           dtac bspec, atac, dtac conjunct2, dtac (mk_conjunctN n i), dtac bspec,
   385           dtac bspec, atac, dtac conjunct2, dtac (mk_conjunctN n i), dtac bspec,
   393           etac @{thm set_mp[OF equalityD1]}, atac,
   386           etac @{thm set_mp[OF equalityD1]}, atac,
   394           REPEAT_DETERM o eresolve_tac [exE, conjE], rtac exI,
   387           REPEAT_DETERM o eresolve_tac [exE, conjE], rtac exI,
   395           rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
   388           rtac conjI, rtac (@{thm shift_def} RS fun_cong RS trans),
   396           etac (@{thm append_Nil} RS sym RS arg_cong RS trans),
   389           etac (@{thm append_Nil} RS sym RS arg_cong RS trans),
   399             rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
   392             rtac @{thm eqset_imp_iff}, rtac sym, rtac trans, rtac @{thm Succ_Shift},
   400             rtac (@{thm append_Nil} RS sym RS arg_cong)])) ks]) (ks ~~ active_sets)];
   393             rtac (@{thm append_Nil} RS sym RS arg_cong)])) ks]) (ks ~~ active_sets)];
   401   in
   394   in
   402     unfold_thms_tac ctxt defs THEN
   395     unfold_thms_tac ctxt defs THEN
   403     CONJ_WRAP' coalg_tac (ks ~~ (map (drop m) set_map0ss ~~ strT_defs)) 1
   396     CONJ_WRAP' coalg_tac (ks ~~ (map (drop m) set_map0ss ~~ strT_defs)) 1
   404   end;
       
   405 
       
   406 fun mk_Lev_sbd_tac ctxt cts Lev_0s Lev_Sucs to_sbdss =
       
   407   let
       
   408     val n = length Lev_0s;
       
   409     val ks = 1 upto n;
       
   410   in
       
   411     EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
       
   412       REPEAT_DETERM o rtac allI,
       
   413       CONJ_WRAP' (fn Lev_0 =>
       
   414         EVERY' (map rtac [ord_eq_le_trans, Lev_0, @{thm Nil_clists}])) Lev_0s,
       
   415       REPEAT_DETERM o rtac allI,
       
   416       CONJ_WRAP' (fn (Lev_Suc, to_sbds) =>
       
   417         EVERY' [rtac ord_eq_le_trans, rtac Lev_Suc,
       
   418           CONJ_WRAP_GEN' (rtac (Thm.permute_prems 0 1 @{thm Un_least}))
       
   419             (fn (i, to_sbd) => EVERY' [rtac subsetI,
       
   420               REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE], hyp_subst_tac ctxt,
       
   421               rtac @{thm Cons_clists}, rtac (mk_InN_Field n i), etac to_sbd,
       
   422               etac set_rev_mp, REPEAT_DETERM o etac allE,
       
   423               etac (mk_conjunctN n i)])
       
   424           (rev (ks ~~ to_sbds))])
       
   425       (Lev_Sucs ~~ to_sbdss)] 1
       
   426   end;
   397   end;
   427 
   398 
   428 fun mk_length_Lev_tac ctxt cts Lev_0s Lev_Sucs =
   399 fun mk_length_Lev_tac ctxt cts Lev_0s Lev_Sucs =
   429   let
   400   let
   430     val n = length Lev_0s;
   401     val n = length Lev_0s;
   446       Lev_Sucs] 1
   417       Lev_Sucs] 1
   447   end;
   418   end;
   448 
   419 
   449 fun mk_length_Lev'_tac length_Lev =
   420 fun mk_length_Lev'_tac length_Lev =
   450   EVERY' [ftac length_Lev, etac ssubst, atac] 1;
   421   EVERY' [ftac length_Lev, etac ssubst, atac] 1;
   451 
       
   452 fun mk_prefCl_Lev_tac ctxt cts Lev_0s Lev_Sucs =
       
   453   let
       
   454     val n = length Lev_0s;
       
   455     val ks = n downto 1;
       
   456   in
       
   457     EVERY' [rtac (Drule.instantiate' [] cts nat_induct),
       
   458       REPEAT_DETERM o rtac allI,
       
   459       CONJ_WRAP' (fn Lev_0 =>
       
   460         EVERY' [rtac impI, etac conjE, dtac (Lev_0 RS equalityD1 RS set_mp),
       
   461           etac @{thm singletonE}, hyp_subst_tac ctxt,
       
   462           dtac @{thm prefixeq_Nil[THEN subst, of "%x. x"]},
       
   463           hyp_subst_tac ctxt,
       
   464           rtac @{thm set_mp[OF equalityD2[OF trans[OF arg_cong[OF list.size(3)]]]]},
       
   465           rtac Lev_0, rtac @{thm singletonI}]) Lev_0s,
       
   466       REPEAT_DETERM o rtac allI,
       
   467       CONJ_WRAP' (fn (Lev_0, Lev_Suc) =>
       
   468         EVERY' [rtac impI, etac conjE, dtac (Lev_Suc RS equalityD1 RS set_mp),
       
   469           CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE))
       
   470             (fn i =>
       
   471               EVERY' [REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE], hyp_subst_tac ctxt,
       
   472               dtac @{thm prefixeq_Cons[THEN subst, of "%x. x"]}, etac disjE, hyp_subst_tac ctxt,
       
   473               rtac @{thm set_mp[OF equalityD2[OF trans[OF arg_cong[OF list.size(3)]]]]},
       
   474               rtac Lev_0, rtac @{thm singletonI},
       
   475               REPEAT_DETERM o eresolve_tac [exE, conjE], hyp_subst_tac ctxt,
       
   476               rtac @{thm set_mp[OF equalityD2[OF trans[OF arg_cong[OF length_Cons]]]]},
       
   477               rtac Lev_Suc, rtac (mk_UnIN n i), rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI,
       
   478               rtac refl, etac conjI, REPEAT_DETERM o etac allE, dtac (mk_conjunctN n i),
       
   479               etac mp, etac conjI, atac]) ks])
       
   480       (Lev_0s ~~ Lev_Sucs)] 1
       
   481   end;
       
   482 
   422 
   483 fun mk_rv_last_tac cTs cts rv_Nils rv_Conss =
   423 fun mk_rv_last_tac cTs cts rv_Nils rv_Conss =
   484   let
   424   let
   485     val n = length rv_Nils;
   425     val n = length rv_Nils;
   486     val ks = 1 upto n;
   426     val ks = 1 upto n;
   608               ks)
   548               ks)
   609           (rev (ks ~~ (from_to_sbds ~~ to_sbd_injs)))])
   549           (rev (ks ~~ (from_to_sbds ~~ to_sbd_injs)))])
   610       ((Lev_Sucs ~~ rv_Conss) ~~ (from_to_sbdss ~~ to_sbd_injss))] 1
   550       ((Lev_Sucs ~~ rv_Conss) ~~ (from_to_sbdss ~~ to_sbd_injss))] 1
   611   end;
   551   end;
   612 
   552 
   613 fun mk_mor_beh_tac ctxt m mor_def mor_cong beh_defs carT_defs strT_defs isNode_defs
   553 fun mk_mor_beh_tac ctxt m mor_def mor_cong beh_defs carT_defs strT_defs isNode_defs to_sbd_injss
   614   to_sbd_injss from_to_sbdss Lev_0s Lev_Sucs rv_Nils rv_Conss Lev_sbds length_Levs length_Lev's
   554   from_to_sbdss Lev_0s Lev_Sucs rv_Nils rv_Conss length_Levs length_Lev's rv_lastss set_Levsss
   615   prefCl_Levs rv_lastss set_Levsss set_image_Levsss set_map0ss
   555   set_image_Levsss set_map0ss map_comp_ids map_cong0s =
   616   map_comp_ids map_cong0s map_arg_congs =
       
   617   let
   556   let
   618     val n = length beh_defs;
   557     val n = length beh_defs;
   619     val ks = 1 upto n;
   558     val ks = 1 upto n;
   620 
   559 
   621     fun fbetw_tac (i, (carT_def, (isNode_def, (Lev_0, (rv_Nil, (Lev_sbd,
   560     fun fbetw_tac (i, (carT_def, (isNode_def, (Lev_0, (rv_Nil, ((length_Lev, length_Lev'),
   622       ((length_Lev, length_Lev'), (prefCl_Lev, (rv_lasts, (set_map0s,
   561       (rv_lasts, (set_map0s, (set_Levss, set_image_Levss))))))))) =
   623         (set_Levss, set_image_Levss))))))))))) =
       
   624       EVERY' [rtac ballI, rtac (carT_def RS equalityD2 RS set_mp),
   562       EVERY' [rtac ballI, rtac (carT_def RS equalityD2 RS set_mp),
   625         rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, rtac conjI,
   563         rtac CollectI, REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, rtac conjI,
   626         rtac conjI,
   564         rtac conjI,
   627           rtac @{thm UN_I}, rtac UNIV_I, rtac (Lev_0 RS equalityD2 RS set_mp),
   565           rtac @{thm UN_I}, rtac UNIV_I, rtac (Lev_0 RS equalityD2 RS set_mp),
   628           rtac @{thm singletonI},
   566           rtac @{thm singletonI},
   629         rtac conjI,
   567         (**)
   630           rtac @{thm UN_least}, rtac Lev_sbd,
       
   631         rtac conjI,
       
   632           rtac @{thm prefCl_UN}, rtac ssubst, rtac @{thm PrefCl_def}, REPEAT_DETERM o rtac allI,
       
   633           rtac impI, etac conjE, rtac exI, rtac conjI, rtac @{thm ord_le_eq_trans},
       
   634           etac @{thm prefixeq_length_le}, etac length_Lev, rtac prefCl_Lev, etac conjI, atac,
       
   635         rtac conjI,
       
   636           rtac ballI, etac @{thm UN_E}, rtac conjI,
   568           rtac ballI, etac @{thm UN_E}, rtac conjI,
   637           if n = 1 then K all_tac else rtac (mk_sumEN n),
   569           if n = 1 then K all_tac else rtac (mk_sumEN n),
   638           EVERY' (map5 (fn i => fn isNode_def => fn set_map0s => fn set_Levs => fn set_image_Levs =>
   570           EVERY' (map5 (fn i => fn isNode_def => fn set_map0s => fn set_Levs => fn set_image_Levs =>
   639             EVERY' [rtac (mk_disjIN n i), rtac (isNode_def RS ssubst),
   571             EVERY' [rtac (mk_disjIN n i), rtac (isNode_def RS ssubst),
   640               rtac exI, rtac conjI,
   572               rtac exI, rtac conjI,
   641               (if n = 1 then rtac @{thm if_P} THEN' etac length_Lev'
   573               if n = 1 then rtac refl
   642               else rtac (@{thm if_P} RS arg_cong RS trans) THEN' etac length_Lev' THEN'
   574               else etac (sum_weak_case_cong RS trans) THEN' rtac (mk_sum_caseN n i),
   643                 etac (sum_weak_case_cong RS trans) THEN' rtac (mk_sum_caseN n i)),
       
   644               CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
   575               CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
   645                 EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
   576                 EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
   646                   rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, etac set_Lev,
   577                   rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, etac set_Lev,
   647                   if n = 1 then rtac refl else atac, atac, rtac subsetI,
   578                   if n = 1 then rtac refl else atac, atac, rtac subsetI,
   648                   REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
   579                   REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
   655             (set_Levs, set_image_Levs))))) =>
   586             (set_Levs, set_image_Levs))))) =>
   656             EVERY' [rtac ballI,
   587             EVERY' [rtac ballI,
   657               REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
   588               REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
   658               rtac (rev_mp OF [rv_last, impI]), etac exE, rtac (isNode_def RS ssubst),
   589               rtac (rev_mp OF [rv_last, impI]), etac exE, rtac (isNode_def RS ssubst),
   659               rtac exI, rtac conjI,
   590               rtac exI, rtac conjI,
   660               (if n = 1 then rtac @{thm if_P} THEN' etac length_Lev'
   591               if n = 1 then rtac refl
   661               else rtac (@{thm if_P} RS trans) THEN' etac length_Lev' THEN'
   592               else etac (sum_weak_case_cong RS trans) THEN' rtac (mk_sum_caseN n i),
   662                 etac (sum_weak_case_cong RS trans) THEN' rtac (mk_sum_caseN n i)),
       
   663               CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
   593               CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
   664                 EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
   594                 EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
   665                   rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, etac set_Lev,
   595                   rtac CollectI, rtac @{thm SuccI}, rtac @{thm UN_I}, rtac UNIV_I, etac set_Lev,
   666                   if n = 1 then rtac refl else atac, atac, rtac subsetI,
   596                   if n = 1 then rtac refl else atac, atac, rtac subsetI,
   667                   REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
   597                   REPEAT_DETERM o eresolve_tac [CollectE, @{thm SuccE}, @{thm UN_E}],
   671                   etac @{thm set_mp[OF equalityD1[OF arg_cong[OF length_append_singleton]]]},
   601                   etac @{thm set_mp[OF equalityD1[OF arg_cong[OF length_append_singleton]]]},
   672                   if n = 1 then rtac refl else atac])
   602                   if n = 1 then rtac refl else atac])
   673               (drop m set_map0s ~~ (set_Levs ~~ set_image_Levs))])
   603               (drop m set_map0s ~~ (set_Levs ~~ set_image_Levs))])
   674           (ks ~~ (rv_lasts ~~ (isNode_defs ~~ (set_map0ss ~~
   604           (ks ~~ (rv_lasts ~~ (isNode_defs ~~ (set_map0ss ~~
   675             (set_Levss ~~ set_image_Levss))))),
   605             (set_Levss ~~ set_image_Levss))))),
   676         (**)
       
   677           rtac allI, rtac impI, rtac @{thm if_not_P}, rtac notI,
       
   678           etac notE, etac @{thm UN_I[OF UNIV_I]},
       
   679         (*root isNode*)
   606         (*root isNode*)
   680           rtac (isNode_def RS ssubst), rtac exI, rtac conjI, rtac (@{thm if_P} RS trans),
   607           rtac (isNode_def RS ssubst), rtac exI, rtac conjI,
   681           rtac length_Lev', rtac (Lev_0 RS equalityD2 RS set_mp), rtac @{thm singletonI},
       
   682           CONVERSION (Conv.top_conv
   608           CONVERSION (Conv.top_conv
   683             (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
   609             (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
   684           if n = 1 then rtac refl else rtac (mk_sum_caseN n i),
   610           if n = 1 then rtac refl else rtac (mk_sum_caseN n i),
   685           CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
   611           CONJ_WRAP' (fn (set_map0, (set_Lev, set_image_Lev)) =>
   686             EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
   612             EVERY' [rtac (set_map0 RS trans), rtac equalityI, rtac @{thm image_subsetI},
   693               etac @{thm set_mp[OF equalityD1[OF arg_cong[OF
   619               etac @{thm set_mp[OF equalityD1[OF arg_cong[OF
   694                 trans[OF length_append_singleton arg_cong[of _ _ Suc, OF list.size(3)]]]]]},
   620                 trans[OF length_append_singleton arg_cong[of _ _ Suc, OF list.size(3)]]]]]},
   695               rtac rv_Nil])
   621               rtac rv_Nil])
   696           (drop m set_map0s ~~ (nth set_Levss (i - 1) ~~ nth set_image_Levss (i - 1)))];
   622           (drop m set_map0s ~~ (nth set_Levss (i - 1) ~~ nth set_image_Levss (i - 1)))];
   697 
   623 
   698     fun mor_tac (i, (strT_def, (((Lev_0, Lev_Suc), (rv_Nil, rv_Cons)),
   624     fun mor_tac (i, (strT_def, ((Lev_Suc, (rv_Nil, rv_Cons)),
   699       ((map_comp_id, (map_cong0, map_arg_cong)), (length_Lev', (from_to_sbds, to_sbd_injs)))))) =
   625       ((map_comp_id, map_cong0), (length_Lev', (from_to_sbds, to_sbd_injs)))))) =
   700       EVERY' [rtac ballI, rtac sym, rtac trans, rtac strT_def,
   626       EVERY' [rtac ballI, rtac sym, rtac trans, rtac strT_def,
   701         rtac (@{thm if_P} RS (if n = 1 then map_arg_cong else sum_weak_case_cong) RS trans),
       
   702         rtac (@{thm list.size(3)} RS arg_cong RS trans RS equalityD2 RS set_mp),
       
   703         rtac Lev_0, rtac @{thm singletonI},
       
   704         CONVERSION (Conv.top_conv
   627         CONVERSION (Conv.top_conv
   705           (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
   628           (K (Conv.try_conv (Conv.rewr_conv (rv_Nil RS eq_reflection)))) ctxt),
   706         if n = 1 then K all_tac
   629         if n = 1 then K all_tac
   707         else (rtac (sum_weak_case_cong RS trans) THEN'
   630         else (rtac (sum_weak_case_cong RS trans) THEN'
   708           rtac (mk_sum_caseN n i) THEN' rtac (mk_sum_caseN n i RS trans)),
   631           rtac (mk_sum_caseN n i) THEN' rtac (mk_sum_caseN n i RS trans)),
   724             (rev ks),
   647             (rev ks),
   725             rtac @{thm UN_least}, rtac subsetI, rtac CollectI, rtac @{thm UN_I[OF UNIV_I]},
   648             rtac @{thm UN_least}, rtac subsetI, rtac CollectI, rtac @{thm UN_I[OF UNIV_I]},
   726             rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i'), rtac CollectI,
   649             rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i'), rtac CollectI,
   727             REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, etac conjI, atac,
   650             REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, etac conjI, atac,
   728             rtac trans, rtac @{thm shift_def}, rtac ssubst, rtac @{thm fun_eq_iff}, rtac allI,
   651             rtac trans, rtac @{thm shift_def}, rtac ssubst, rtac @{thm fun_eq_iff}, rtac allI,
   729             rtac @{thm if_cong}, rtac (@{thm length_Cons} RS arg_cong RS trans), rtac iffI,
       
   730             dtac asm_rl, dtac asm_rl, dtac asm_rl,
       
   731             dtac (Lev_Suc RS equalityD1 RS set_mp),
       
   732             CONJ_WRAP_GEN' (etac (Thm.permute_prems 1 1 UnE)) (fn i'' =>
       
   733               EVERY' [REPEAT_DETERM o eresolve_tac [CollectE, exE, conjE],
       
   734                 dtac list_inject_iffD1, etac conjE,
       
   735                 if i' = i'' then EVERY' [dtac (mk_InN_inject n i'),
       
   736                   dtac (Thm.permute_prems 0 2 (to_sbd_inj RS iffD1)),
       
   737                   atac, atac, hyp_subst_tac ctxt, atac]
       
   738                 else etac (mk_InN_not_InM i' i'' RS notE)])
       
   739             (rev ks),
       
   740             rtac (Lev_Suc RS equalityD2 RS set_mp), rtac (mk_UnIN n i'), rtac CollectI,
       
   741             REPEAT_DETERM o rtac exI, rtac conjI, rtac refl, etac conjI, atac,
       
   742             CONVERSION (Conv.top_conv
   652             CONVERSION (Conv.top_conv
   743               (K (Conv.try_conv (Conv.rewr_conv (rv_Cons RS eq_reflection)))) ctxt),
   653               (K (Conv.try_conv (Conv.rewr_conv (rv_Cons RS eq_reflection)))) ctxt),
   744             if n = 1 then K all_tac
   654             if n = 1 then K all_tac
   745             else rtac sum_weak_case_cong THEN' rtac (mk_sum_caseN n i' RS trans),
   655             else rtac sum_weak_case_cong THEN' rtac (mk_sum_caseN n i' RS trans),
   746             SELECT_GOAL (unfold_thms_tac ctxt [from_to_sbd]), rtac refl,
   656             SELECT_GOAL (unfold_thms_tac ctxt [from_to_sbd]), rtac refl])
   747             rtac refl])
       
   748         ks to_sbd_injs from_to_sbds)];
   657         ks to_sbd_injs from_to_sbds)];
   749   in
   658   in
   750     (rtac mor_cong THEN'
   659     (rtac mor_cong THEN'
   751     EVERY' (map (fn thm => rtac (thm RS ext)) beh_defs) THEN'
   660     EVERY' (map (fn thm => rtac (thm RS ext)) beh_defs) THEN'
   752     stac mor_def THEN' rtac conjI THEN'
   661     stac mor_def THEN' rtac conjI THEN'
   753     CONJ_WRAP' fbetw_tac
   662     CONJ_WRAP' fbetw_tac
   754       (ks ~~ (carT_defs ~~ (isNode_defs ~~ (Lev_0s ~~ (rv_Nils ~~ (Lev_sbds ~~
   663       (ks ~~ (carT_defs ~~ (isNode_defs ~~ (Lev_0s ~~ (rv_Nils ~~ ((length_Levs ~~ length_Lev's) ~~
   755         ((length_Levs ~~ length_Lev's) ~~ (prefCl_Levs ~~ (rv_lastss ~~
   664         (rv_lastss ~~ (set_map0ss ~~ (set_Levsss ~~ set_image_Levsss))))))))) THEN'
   756           (set_map0ss ~~ (set_Levsss ~~ set_image_Levsss))))))))))) THEN'
       
   757     CONJ_WRAP' mor_tac
   665     CONJ_WRAP' mor_tac
   758       (ks ~~ (strT_defs ~~ (((Lev_0s ~~ Lev_Sucs) ~~ (rv_Nils ~~ rv_Conss)) ~~
   666       (ks ~~ (strT_defs ~~ ((Lev_Sucs ~~ (rv_Nils ~~ rv_Conss)) ~~
   759         ((map_comp_ids ~~ (map_cong0s ~~ map_arg_congs)) ~~
   667         ((map_comp_ids ~~ map_cong0s) ~~
   760           (length_Lev's ~~ (from_to_sbdss ~~ to_sbd_injss))))))) 1
   668           (length_Lev's ~~ (from_to_sbdss ~~ to_sbd_injss))))))) 1
   761   end;
   669   end;
   762 
   670 
   763 fun mk_congruent_str_final_tac m lsbisE map_comp_id map_cong0 equiv_LSBISs =
   671 fun mk_congruent_str_final_tac m lsbisE map_comp_id map_cong0 equiv_LSBISs =
   764   EVERY' [rtac @{thm congruentI}, dtac lsbisE,
   672   EVERY' [rtac @{thm congruentI}, dtac lsbisE,