src/HOL/Tools/Old_Datatype/old_rep_datatype.ML
changeset 60781 2da59cdf531c
parent 60774 6c28d8ed2488
child 63239 d562c9948dee
equal deleted inserted replaced
60780:7e2c8a63a8f8 60781:2da59cdf531c
    44           Abs ("z", T', Const (@{const_name True}, T''))) induct_Ps;
    44           Abs ("z", T', Const (@{const_name True}, T''))) induct_Ps;
    45         val P =
    45         val P =
    46           Abs ("z", T, HOLogic.imp $ HOLogic.mk_eq (Var (("a", maxidx + 1), T), Bound 0) $
    46           Abs ("z", T, HOLogic.imp $ HOLogic.mk_eq (Var (("a", maxidx + 1), T), Bound 0) $
    47             Var (("P", 0), HOLogic.boolT));
    47             Var (("P", 0), HOLogic.boolT));
    48         val insts = take i dummyPs @ (P :: drop (i + 1) dummyPs);
    48         val insts = take i dummyPs @ (P :: drop (i + 1) dummyPs);
    49         val insts' = map (Thm.global_cterm_of thy) induct_Ps ~~ map (Thm.global_cterm_of thy) insts;
       
    50         val induct' =
       
    51           refl RS
       
    52             (nth (Old_Datatype_Aux.split_conj_thm (cterm_instantiate insts' induct)) i
       
    53              RSN (2, rev_mp));
       
    54       in
    49       in
    55         Goal.prove_sorry_global thy []
    50         Goal.prove_sorry_global thy []
    56           (Logic.strip_imp_prems t)
    51           (Logic.strip_imp_prems t)
    57           (Logic.strip_imp_concl t)
    52           (Logic.strip_imp_concl t)
    58           (fn {context = ctxt, prems, ...} =>
    53           (fn {context = ctxt, prems, ...} =>
    59             EVERY
    54             let
    60               [resolve_tac ctxt [induct'] 1,
    55               val insts' = map (#1 o dest_Var) induct_Ps ~~ map (Thm.cterm_of ctxt) insts;
    61                REPEAT (resolve_tac ctxt [TrueI] 1),
    56               val induct' =
    62                REPEAT ((resolve_tac ctxt [impI] 1) THEN (eresolve_tac ctxt prems 1)),
    57                 refl RS
    63                REPEAT (resolve_tac ctxt [TrueI] 1)])
    58                   (nth (Old_Datatype_Aux.split_conj_thm (infer_instantiate ctxt insts' induct)) i
       
    59                    RSN (2, rev_mp));
       
    60             in
       
    61               EVERY
       
    62                 [resolve_tac ctxt [induct'] 1,
       
    63                  REPEAT (resolve_tac ctxt [TrueI] 1),
       
    64                  REPEAT ((resolve_tac ctxt [impI] 1) THEN (eresolve_tac ctxt prems 1)),
       
    65                  REPEAT (resolve_tac ctxt [TrueI] 1)]
       
    66             end)
    64       end;
    67       end;
    65 
    68 
    66     val casedist_thms =
    69     val casedist_thms =
    67       map_index prove_casedist_thm (newTs ~~ Old_Datatype_Prop.make_casedists descr);
    70       map_index prove_casedist_thm (newTs ~~ Old_Datatype_Prop.make_casedists descr);
    68   in
    71   in
   204               absfree ("y", T2) (set_t $ Old_Datatype_Aux.mk_Free "x" T1 i $ Free ("y", T2)))
   207               absfree ("y", T2) (set_t $ Old_Datatype_Aux.mk_Free "x" T1 i $ Free ("y", T2)))
   205                 (rec_sets ~~ recTs ~~ rec_result_Ts ~~ (1 upto length recTs));
   208                 (rec_sets ~~ recTs ~~ rec_result_Ts ~~ (1 upto length recTs));
   206         val insts =
   209         val insts =
   207           map (fn ((i, T), t) => absfree ("x" ^ string_of_int i, T) t)
   210           map (fn ((i, T), t) => absfree ("x" ^ string_of_int i, T) t)
   208             ((1 upto length recTs) ~~ recTs ~~ rec_unique_ts);
   211             ((1 upto length recTs) ~~ recTs ~~ rec_unique_ts);
   209         val induct' = induct
       
   210           |> cterm_instantiate
       
   211             (map (Thm.global_cterm_of thy1) induct_Ps ~~ map (Thm.global_cterm_of thy1) insts);
       
   212       in
   212       in
   213         Old_Datatype_Aux.split_conj_thm (Goal.prove_sorry_global thy1 [] []
   213         Old_Datatype_Aux.split_conj_thm (Goal.prove_sorry_global thy1 [] []
   214           (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj rec_unique_ts))
   214           (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj rec_unique_ts))
   215           (fn {context = ctxt, ...} =>
   215           (fn {context = ctxt, ...} =>
   216             #1 (fold (mk_unique_tac ctxt) (descr' ~~ rec_elims ~~ recTs ~~ rec_result_Ts)
   216             let
   217               (((resolve_tac ctxt [induct'] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1 THEN
   217               val induct' =
   218                   rewrite_goals_tac ctxt [mk_meta_eq @{thm choice_eq}], rec_intrs)))))
   218                 infer_instantiate ctxt
       
   219                   (map (#1 o dest_Var) induct_Ps ~~ map (Thm.cterm_of ctxt) insts) induct;
       
   220             in
       
   221               #1 (fold (mk_unique_tac ctxt) (descr' ~~ rec_elims ~~ recTs ~~ rec_result_Ts)
       
   222                 (((resolve_tac ctxt [induct'] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1 THEN
       
   223                     rewrite_goals_tac ctxt [mk_meta_eq @{thm choice_eq}], rec_intrs)))
       
   224             end))
   219       end;
   225       end;
   220 
   226 
   221     val rec_total_thms = map (fn r => r RS @{thm theI'}) rec_unique_thms;
   227     val rec_total_thms = map (fn r => r RS @{thm theI'}) rec_unique_thms;
   222 
   228 
   223     (* define primrec combinators *)
   229     (* define primrec combinators *)
   378     val newTs = take (length (hd descr)) recTs;
   384     val newTs = take (length (hd descr)) recTs;
   379 
   385 
   380     fun prove_split_thms ((((((t1, t2), inject), dist_rewrites'), exhaustion), case_thms'), T) =
   386     fun prove_split_thms ((((((t1, t2), inject), dist_rewrites'), exhaustion), case_thms'), T) =
   381       let
   387       let
   382         val _ $ (_ $ lhs $ _) = hd (Logic.strip_assums_hyp (hd (Thm.prems_of exhaustion)));
   388         val _ $ (_ $ lhs $ _) = hd (Logic.strip_assums_hyp (hd (Thm.prems_of exhaustion)));
       
   389         val ctxt = Proof_Context.init_global thy;
   383         val exhaustion' = exhaustion
   390         val exhaustion' = exhaustion
   384           |> cterm_instantiate [apply2 (Thm.global_cterm_of thy) (lhs, Free ("x", T))];
   391           |> infer_instantiate ctxt [(#1 (dest_Var lhs), Thm.cterm_of ctxt (Free ("x", T)))];
   385         fun tac ctxt =
   392         val tac =
   386           EVERY [resolve_tac ctxt [exhaustion'] 1,
   393           EVERY [resolve_tac ctxt [exhaustion'] 1,
   387             ALLGOALS (asm_simp_tac
   394             ALLGOALS (asm_simp_tac
   388               (put_simpset HOL_ss ctxt addsimps (dist_rewrites' @ inject @ case_thms')))];
   395               (put_simpset HOL_ss ctxt addsimps (dist_rewrites' @ inject @ case_thms')))];
   389       in
   396       in
   390         (Goal.prove_sorry_global thy [] [] t1 (tac o #context),
   397         (Goal.prove_sorry_global thy [] [] t1 (K tac),
   391          Goal.prove_sorry_global thy [] [] t2 (tac o #context))
   398          Goal.prove_sorry_global thy [] [] t2 (K tac))
   392       end;
   399       end;
   393 
   400 
   394     val split_thm_pairs =
   401     val split_thm_pairs =
   395       map prove_split_thms
   402       map prove_split_thms
   396         (Old_Datatype_Prop.make_splits case_names descr thy ~~ constr_inject ~~
   403         (Old_Datatype_Prop.make_splits case_names descr thy ~~ constr_inject ~~
   449     fun prove_case_cong ((t, nchotomy), case_rewrites) =
   456     fun prove_case_cong ((t, nchotomy), case_rewrites) =
   450       let
   457       let
   451         val Const (@{const_name Pure.imp}, _) $ tm $ _ = t;
   458         val Const (@{const_name Pure.imp}, _) $ tm $ _ = t;
   452         val Const (@{const_name Trueprop}, _) $ (Const (@{const_name HOL.eq}, _) $ _ $ Ma) = tm;
   459         val Const (@{const_name Trueprop}, _) $ (Const (@{const_name HOL.eq}, _) $ _ $ Ma) = tm;
   453         val nchotomy' = nchotomy RS spec;
   460         val nchotomy' = nchotomy RS spec;
   454         val [v] = Term.add_vars (Thm.concl_of nchotomy') [];
   461         val [v] = Term.add_var_names (Thm.concl_of nchotomy') [];
   455         val nchotomy'' =
       
   456           cterm_instantiate [apply2 (Thm.global_cterm_of thy) (Var v, Ma)] nchotomy';
       
   457       in
   462       in
   458         Goal.prove_sorry_global thy [] (Logic.strip_imp_prems t) (Logic.strip_imp_concl t)
   463         Goal.prove_sorry_global thy [] (Logic.strip_imp_prems t) (Logic.strip_imp_concl t)
   459           (fn {context = ctxt, prems, ...} =>
   464           (fn {context = ctxt, prems, ...} =>
   460             let
   465             let
       
   466               val nchotomy'' =
       
   467                 infer_instantiate ctxt [(v, Thm.cterm_of ctxt Ma)] nchotomy';
   461               val simplify = asm_simp_tac (put_simpset HOL_ss ctxt addsimps (prems @ case_rewrites))
   468               val simplify = asm_simp_tac (put_simpset HOL_ss ctxt addsimps (prems @ case_rewrites))
   462             in
   469             in
   463               EVERY [
   470               EVERY [
   464                 simp_tac (put_simpset HOL_ss ctxt addsimps [hd prems]) 1,
   471                 simp_tac (put_simpset HOL_ss ctxt addsimps [hd prems]) 1,
   465                 cut_tac nchotomy'' 1,
   472                 cut_tac nchotomy'' 1,