fixed issue with bound variables in prem prems + tuning
authorblanchet
Fri Sep 14 22:23:10 2012 +0200 (2012-09-14)
changeset 4937819237e465055
parent 49377 7003b063a985
child 49379 7860bd1429f4
fixed issue with bound variables in prem prems + tuning
src/HOL/Codatatype/Tools/bnf_fp_sugar.ML
src/HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
     1.1 --- a/src/HOL/Codatatype/Tools/bnf_fp_sugar.ML	Fri Sep 14 22:23:10 2012 +0200
     1.2 +++ b/src/HOL/Codatatype/Tools/bnf_fp_sugar.ML	Fri Sep 14 22:23:10 2012 +0200
     1.3 @@ -565,12 +565,12 @@
     1.4                  | i => [([], (i + 1, x))])
     1.5                | mk_raw_prem_prems _ _ = [];
     1.6  
     1.7 -            fun close_prem_prem (Free x') t =
     1.8 -              fold_rev Logic.all
     1.9 -                (map Free (drop (nn + 1) (rev (Term.add_frees t (x' :: phis'))))) t;
    1.10 +            fun close_prem_prem xs t =
    1.11 +              fold_rev Logic.all (map Free (drop (nn + length xs)
    1.12 +                (rev (Term.add_frees t (map dest_Free xs @ phis'))))) t;
    1.13  
    1.14 -            fun mk_prem_prem (xysets, (j, x)) =
    1.15 -              close_prem_prem x (Logic.list_implies (map (fn (x', (y, set)) =>
    1.16 +            fun mk_prem_prem xs (xysets, (j, x)) =
    1.17 +              close_prem_prem xs (Logic.list_implies (map (fn (x', (y, set)) =>
    1.18                    HOLogic.mk_Trueprop (HOLogic.mk_mem (y, set $ x'))) xysets,
    1.19                  HOLogic.mk_Trueprop (nth phis (j - 1) $ x)));
    1.20  
    1.21 @@ -578,14 +578,12 @@
    1.22                let
    1.23                  val (xs, names_lthy') = names_lthy |> mk_Frees "x" ctr_Ts;
    1.24                  val pprems = maps (mk_raw_prem_prems names_lthy') xs;
    1.25 -              in
    1.26 -                (xs, pprems, HOLogic.mk_Trueprop (phi $ Term.list_comb (ctr, xs)))
    1.27 -              end;
    1.28 +              in (xs, pprems, HOLogic.mk_Trueprop (phi $ Term.list_comb (ctr, xs))) end;
    1.29  
    1.30              val raw_premss = map3 (map2 o mk_raw_prem) phis ctrss ctr_Tsss;
    1.31  
    1.32              fun mk_prem (xs, raw_pprems, concl) =
    1.33 -              fold_rev Logic.all xs (Logic.list_implies (map mk_prem_prem raw_pprems, concl));
    1.34 +              fold_rev Logic.all xs (Logic.list_implies (map (mk_prem_prem xs) raw_pprems, concl));
    1.35  
    1.36              val goal =
    1.37                Library.foldr (Logic.list_implies o apfst (map mk_prem)) (raw_premss,
    1.38 @@ -598,19 +596,19 @@
    1.39                  val buckets = Library.partition_list has_index 1 nn pprems;
    1.40                  val pps = map length buckets;
    1.41                in
    1.42 -                map (fn pprem as (_ (*xysets*), (kk, _)) =>
    1.43 +                map (fn pprem as (xysets, (kk, _)) =>
    1.44                    ((nth pps (kk - 1), find_index (curry (op =) pprem) (nth buckets (kk - 1)) + 1),
    1.45 -                   kk)) pprems
    1.46 +                   (length xysets, kk))) pprems
    1.47                end;
    1.48  
    1.49 -            val ppjjkksss = map (map (mk_raw_prem_prems_indices o #2)) raw_premss;
    1.50 +            val ixsss = map (map (mk_raw_prem_prems_indices o #2)) raw_premss;
    1.51  
    1.52              val fld_induct' = fp_induct OF (map mk_sumEN_tupled_balanced mss);
    1.53  
    1.54              val induct_thm =
    1.55                Skip_Proof.prove lthy [] [] goal (fn {context = ctxt, ...} =>
    1.56 -                mk_induct_tac ctxt ns mss ppjjkksss (flat ctr_defss) fld_induct'
    1.57 -                  nested_set_natural's pre_set_defss)
    1.58 +                mk_induct_tac ctxt ns mss ixsss (flat ctr_defss) fld_induct' nested_set_natural's
    1.59 +                  pre_set_defss)
    1.60                |> singleton (Proof_Context.export names_lthy lthy)
    1.61            in
    1.62              `(conj_dests nn) induct_thm
     2.1 --- a/src/HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML	Fri Sep 14 22:23:10 2012 +0200
     2.2 +++ b/src/HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML	Fri Sep 14 22:23:10 2012 +0200
     2.3 @@ -14,7 +14,8 @@
     2.4      tactic
     2.5    val mk_half_distinct_tac: Proof.context -> thm -> thm list -> tactic
     2.6    val mk_induct_tac: Proof.context -> int list -> int list list ->
     2.7 -    ((int * int) * int) list list list -> thm list -> thm -> thm list -> thm list list -> tactic
     2.8 +    ((int * int) * (int * int)) list list list -> thm list -> thm -> thm list -> thm list list ->
     2.9 +    tactic
    2.10    val mk_inject_tac: Proof.context -> thm -> thm -> tactic
    2.11    val mk_iter_like_tac: thm list -> thm list -> thm list -> thm -> thm -> Proof.context -> tactic
    2.12  end;
    2.13 @@ -111,34 +112,37 @@
    2.14  val induct_prem_prem_thms_delayed =
    2.15    @{thms fsts_def[abs_def] snds_def[abs_def] sum_setl_def[abs_def] sum_setr_def[abs_def]};
    2.16  
    2.17 +fun mk_induct_prem_prem_endgame_tac ctxt qq =
    2.18 +  atac ORELSE'
    2.19 +  rtac @{thm singletonI} ORELSE'
    2.20 +  (REPEAT_DETERM o (SELECT_GOAL (Local_Defs.unfold_tac ctxt @{thms Union_iff bex_simps(6)}) THEN'
    2.21 +     etac @{thm induct_set_step}) THEN'
    2.22 +   (atac ORELSE' blast_tac ctxt));
    2.23 +
    2.24  (* TODO: Get rid of the "blast_tac" *)
    2.25 -fun mk_induct_discharge_prem_prems_tac ctxt nn ppjjkks set_natural's pre_set_defs =
    2.26 -  EVERY' (maps (fn ((pp, jj), kk) =>
    2.27 -    [select_prem_tac nn (dtac meta_spec) (nn - kk + 1), rotate_tac ~1, etac meta_mp,
    2.28 +fun mk_induct_discharge_prem_prems_tac ctxt nn ixs set_natural's pre_set_defs =
    2.29 +  EVERY' (maps (fn ((pp, jj), (qq, kk)) =>
    2.30 +    [select_prem_tac nn (dtac meta_spec) (nn - kk + 1), rotate_tac ~1,(*###*) etac meta_mp,
    2.31       SELECT_GOAL (Local_Defs.unfold_tac ctxt pre_set_defs), (* ### why on a line of its own? *)
    2.32       SELECT_GOAL (Local_Defs.unfold_tac ctxt (set_natural's @ induct_prem_prem_thms)),
    2.33       SELECT_GOAL (Local_Defs.unfold_tac ctxt
    2.34         (induct_prem_prem_thms_delayed @ induct_prem_prem_thms)),
    2.35       rtac (mk_UnIN pp jj),
    2.36 -     atac ORELSE'
    2.37 -     rtac @{thm singletonI} ORELSE'
    2.38 -     (REPEAT_DETERM o (SELECT_GOAL (Local_Defs.unfold_tac ctxt @{thms Union_iff bex_simps(6)}) THEN'
    2.39 -          etac @{thm induct_set_step}) THEN'
    2.40 -      (atac ORELSE' blast_tac ctxt))]) (rev ppjjkks)) 1;
    2.41 +     mk_induct_prem_prem_endgame_tac ctxt qq]) (rev ixs)) 1;
    2.42  
    2.43 -fun mk_induct_discharge_prem_tac ctxt nn n set_natural's pre_set_defs m k ppjjkks =
    2.44 +fun mk_induct_discharge_prem_tac ctxt nn n set_natural's pre_set_defs m k ixs =
    2.45    EVERY [mk_induct_prepare_prem_tac n m k,
    2.46 -    mk_induct_prepare_prem_prems_tac (length ppjjkks), atac 1,
    2.47 -    mk_induct_discharge_prem_prems_tac ctxt nn ppjjkks set_natural's pre_set_defs];
    2.48 +    mk_induct_prepare_prem_prems_tac (length ixs), atac 1,
    2.49 +    mk_induct_discharge_prem_prems_tac ctxt nn ixs set_natural's pre_set_defs];
    2.50  
    2.51 -fun mk_induct_tac ctxt ns mss ppjjkksss ctr_defs fld_induct' set_natural's pre_set_defss =
    2.52 +fun mk_induct_tac ctxt ns mss ixsss ctr_defs fld_induct' set_natural's pre_set_defss =
    2.53    let
    2.54      val nn = length ns;
    2.55      val n = Integer.sum ns;
    2.56    in
    2.57      mk_induct_prelude_tac ctxt ctr_defs fld_induct' THEN
    2.58      EVERY (map4 (EVERY oooo map3 o mk_induct_discharge_prem_tac ctxt nn n set_natural's)
    2.59 -      pre_set_defss mss (unflat mss (1 upto n)) ppjjkksss)
    2.60 +      pre_set_defss mss (unflat mss (1 upto n)) ixsss)
    2.61    end;
    2.62  
    2.63  end;