src/HOL/Tools/Datatype/datatype.ML
changeset 51551 88d1d19fb74f
parent 49835 31f32ec4d766
child 51717 9e7d1c139569
equal deleted inserted replaced
51550:cec08df2c030 51551:88d1d19fb74f
   353 
   353 
   354         (* prove characteristic equations *)
   354         (* prove characteristic equations *)
   355 
   355 
   356         val rewrites = def_thms @ map mk_meta_eq rec_rewrites;
   356         val rewrites = def_thms @ map mk_meta_eq rec_rewrites;
   357         val char_thms' =
   357         val char_thms' =
   358           map (fn eqn => Skip_Proof.prove_global thy' [] [] eqn
   358           map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn
   359             (fn _ => EVERY [rewrite_goals_tac rewrites, rtac refl 1])) eqns;
   359             (fn _ => EVERY [rewrite_goals_tac rewrites, rtac refl 1])) eqns;
   360 
   360 
   361       in (thy', char_thms' @ char_thms) end;
   361       in (thy', char_thms' @ char_thms) end;
   362 
   362 
   363     val (thy5, iso_char_thms) =
   363     val (thy5, iso_char_thms) =
   375         fun mk_thm i =
   375         fun mk_thm i =
   376           let
   376           let
   377             val Ts = map (TFree o rpair HOLogic.typeS) (Name.variant_list used (replicate i "'t"));
   377             val Ts = map (TFree o rpair HOLogic.typeS) (Name.variant_list used (replicate i "'t"));
   378             val f = Free ("f", Ts ---> U);
   378             val f = Free ("f", Ts ---> U);
   379           in
   379           in
   380             Skip_Proof.prove_global thy [] []
   380             Goal.prove_sorry_global thy [] []
   381               (Logic.mk_implies
   381               (Logic.mk_implies
   382                 (HOLogic.mk_Trueprop (HOLogic.list_all
   382                 (HOLogic.mk_Trueprop (HOLogic.list_all
   383                    (map (pair "x") Ts, S $ Datatype_Aux.app_bnds f i)),
   383                    (map (pair "x") Ts, S $ Datatype_Aux.app_bnds f i)),
   384                  HOLogic.mk_Trueprop (HOLogic.mk_eq (fold_rev (Term.abs o pair "x") Ts
   384                  HOLogic.mk_Trueprop (HOLogic.mk_eq (fold_rev (Term.abs o pair "x") Ts
   385                    (r $ (a $ Datatype_Aux.app_bnds f i)), f))))
   385                    (r $ (a $ Datatype_Aux.app_bnds f i)), f))))
   414 
   414 
   415         val rewrites = map mk_meta_eq iso_char_thms;
   415         val rewrites = map mk_meta_eq iso_char_thms;
   416         val inj_thms' = map snd newT_iso_inj_thms @ map (fn r => r RS @{thm injD}) inj_thms;
   416         val inj_thms' = map snd newT_iso_inj_thms @ map (fn r => r RS @{thm injD}) inj_thms;
   417 
   417 
   418         val inj_thm =
   418         val inj_thm =
   419           Skip_Proof.prove_global thy5 [] []
   419           Goal.prove_sorry_global thy5 [] []
   420             (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl1))
   420             (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl1))
   421             (fn _ => EVERY
   421             (fn _ => EVERY
   422               [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1,
   422               [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1,
   423                REPEAT (EVERY
   423                REPEAT (EVERY
   424                  [rtac allI 1, rtac impI 1,
   424                  [rtac allI 1, rtac impI 1,
   440                            atac 1]))])])])]);
   440                            atac 1]))])])])]);
   441 
   441 
   442         val inj_thms'' = map (fn r => r RS datatype_injI) (Datatype_Aux.split_conj_thm inj_thm);
   442         val inj_thms'' = map (fn r => r RS datatype_injI) (Datatype_Aux.split_conj_thm inj_thm);
   443 
   443 
   444         val elem_thm =
   444         val elem_thm =
   445           Skip_Proof.prove_global thy5 [] []
   445           Goal.prove_sorry_global thy5 [] []
   446             (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl2))
   446             (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl2))
   447             (fn _ =>
   447             (fn _ =>
   448               EVERY [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1,
   448               EVERY [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1,
   449                 rewrite_goals_tac rewrites,
   449                 rewrite_goals_tac rewrites,
   450                 REPEAT ((resolve_tac rep_intrs THEN_ALL_NEW
   450                 REPEAT ((resolve_tac rep_intrs THEN_ALL_NEW
   478 
   478 
   479     val iso_thms =
   479     val iso_thms =
   480       if length descr = 1 then []
   480       if length descr = 1 then []
   481       else
   481       else
   482         drop (length newTs) (Datatype_Aux.split_conj_thm
   482         drop (length newTs) (Datatype_Aux.split_conj_thm
   483           (Skip_Proof.prove_global thy5 [] [] iso_t (fn _ => EVERY
   483           (Goal.prove_sorry_global thy5 [] [] iso_t (fn _ => EVERY
   484              [(Datatype_Aux.ind_tac rep_induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1,
   484              [(Datatype_Aux.ind_tac rep_induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1,
   485               REPEAT (rtac TrueI 1),
   485               REPEAT (rtac TrueI 1),
   486               rewrite_goals_tac (mk_meta_eq @{thm choice_eq} ::
   486               rewrite_goals_tac (mk_meta_eq @{thm choice_eq} ::
   487                 Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs),
   487                 Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs),
   488               rewrite_goals_tac (map Thm.symmetric range_eqs),
   488               rewrite_goals_tac (map Thm.symmetric range_eqs),
   509     fun prove_constr_rep_thm eqn =
   509     fun prove_constr_rep_thm eqn =
   510       let
   510       let
   511         val inj_thms = map fst newT_iso_inj_thms;
   511         val inj_thms = map fst newT_iso_inj_thms;
   512         val rewrites = @{thm o_def} :: constr_defs @ map (mk_meta_eq o #2) newT_iso_axms;
   512         val rewrites = @{thm o_def} :: constr_defs @ map (mk_meta_eq o #2) newT_iso_axms;
   513       in
   513       in
   514         Skip_Proof.prove_global thy5 [] [] eqn
   514         Goal.prove_sorry_global thy5 [] [] eqn
   515         (fn _ => EVERY
   515         (fn _ => EVERY
   516           [resolve_tac inj_thms 1,
   516           [resolve_tac inj_thms 1,
   517            rewrite_goals_tac rewrites,
   517            rewrite_goals_tac rewrites,
   518            rtac refl 3,
   518            rtac refl 3,
   519            resolve_tac rep_intrs 2,
   519            resolve_tac rep_intrs 2,
   535     fun prove_distinct_thms dist_rewrites' =
   535     fun prove_distinct_thms dist_rewrites' =
   536       let
   536       let
   537         fun prove [] = []
   537         fun prove [] = []
   538           | prove (t :: ts) =
   538           | prove (t :: ts) =
   539               let
   539               let
   540                 val dist_thm = Skip_Proof.prove_global thy5 [] [] t (fn _ =>
   540                 val dist_thm = Goal.prove_sorry_global thy5 [] [] t (fn _ =>
   541                   EVERY [simp_tac (HOL_ss addsimps dist_rewrites') 1])
   541                   EVERY [simp_tac (HOL_ss addsimps dist_rewrites') 1])
   542               in dist_thm :: Drule.zero_var_indexes (dist_thm RS not_sym) :: prove ts end;
   542               in dist_thm :: Drule.zero_var_indexes (dist_thm RS not_sym) :: prove ts end;
   543       in prove end;
   543       in prove end;
   544 
   544 
   545     val distinct_thms =
   545     val distinct_thms =
   553           map make_elim
   553           map make_elim
   554             (iso_inj_thms @
   554             (iso_inj_thms @
   555               [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject,
   555               [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject,
   556                Lim_inject, Suml_inject, Sumr_inject])
   556                Lim_inject, Suml_inject, Sumr_inject])
   557       in
   557       in
   558         Skip_Proof.prove_global thy5 [] [] t
   558         Goal.prove_sorry_global thy5 [] [] t
   559           (fn _ => EVERY
   559           (fn _ => EVERY
   560             [rtac iffI 1,
   560             [rtac iffI 1,
   561              REPEAT (etac conjE 2), hyp_subst_tac 2, rtac refl 2,
   561              REPEAT (etac conjE 2), hyp_subst_tac 2, rtac refl 2,
   562              dresolve_tac rep_congs 1, dtac box_equals 1,
   562              dresolve_tac rep_congs 1, dtac box_equals 1,
   563              REPEAT (resolve_tac rep_thms 1),
   563              REPEAT (resolve_tac rep_thms 1),
   608       split_list (map2 mk_indrule_lemma descr' recTs);
   608       split_list (map2 mk_indrule_lemma descr' recTs);
   609 
   609 
   610     val cert = cterm_of thy6;
   610     val cert = cterm_of thy6;
   611 
   611 
   612     val indrule_lemma =
   612     val indrule_lemma =
   613       Skip_Proof.prove_global thy6 [] []
   613       Goal.prove_sorry_global thy6 [] []
   614         (Logic.mk_implies
   614         (Logic.mk_implies
   615           (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj indrule_lemma_prems),
   615           (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj indrule_lemma_prems),
   616            HOLogic.mk_Trueprop (Datatype_Aux.mk_conj indrule_lemma_concls)))
   616            HOLogic.mk_Trueprop (Datatype_Aux.mk_conj indrule_lemma_concls)))
   617         (fn _ =>
   617         (fn _ =>
   618           EVERY
   618           EVERY
   627       else map (Free o apfst fst o dest_Var) Ps;
   627       else map (Free o apfst fst o dest_Var) Ps;
   628     val indrule_lemma' = cterm_instantiate (map cert Ps ~~ map cert frees) indrule_lemma;
   628     val indrule_lemma' = cterm_instantiate (map cert Ps ~~ map cert frees) indrule_lemma;
   629 
   629 
   630     val dt_induct_prop = Datatype_Prop.make_ind descr;
   630     val dt_induct_prop = Datatype_Prop.make_ind descr;
   631     val dt_induct =
   631     val dt_induct =
   632       Skip_Proof.prove_global thy6 []
   632       Goal.prove_sorry_global thy6 []
   633       (Logic.strip_imp_prems dt_induct_prop)
   633       (Logic.strip_imp_prems dt_induct_prop)
   634       (Logic.strip_imp_concl dt_induct_prop)
   634       (Logic.strip_imp_concl dt_induct_prop)
   635       (fn {prems, ...} =>
   635       (fn {prems, ...} =>
   636         EVERY
   636         EVERY
   637           [rtac indrule_lemma' 1,
   637           [rtac indrule_lemma' 1,