29 |
29 |
30 (** auxiliary **) |
30 (** auxiliary **) |
31 |
31 |
32 val distinct_lemma = @{lemma "f x \<noteq> f y ==> x \<noteq> y" by iprover}; |
32 val distinct_lemma = @{lemma "f x \<noteq> f y ==> x \<noteq> y" by iprover}; |
33 val (_ $ (_ $ (_ $ (distinct_f $ _) $ _))) = hd (prems_of distinct_lemma); |
33 val (_ $ (_ $ (_ $ (distinct_f $ _) $ _))) = hd (prems_of distinct_lemma); |
34 |
|
35 val collect_simp = rewrite_rule [mk_meta_eq mem_Collect_eq]; |
|
36 |
34 |
37 fun exh_thm_of (dt_info : Datatype_Aux.info Symtab.table) tname = |
35 fun exh_thm_of (dt_info : Datatype_Aux.info Symtab.table) tname = |
38 #exhaust (the (Symtab.lookup dt_info tname)); |
36 #exhaust (the (Symtab.lookup dt_info tname)); |
39 |
37 |
40 val In0_inject = @{thm In0_inject}; |
38 val In0_inject = @{thm In0_inject}; |
269 |
267 |
270 (*********** isomorphisms for new types (introduced by typedef) ***********) |
268 (*********** isomorphisms for new types (introduced by typedef) ***********) |
271 |
269 |
272 val _ = Datatype_Aux.message config "Proving isomorphism properties ..."; |
270 val _ = Datatype_Aux.message config "Proving isomorphism properties ..."; |
273 |
271 |
|
272 val collect_simp = rewrite_rule (Proof_Context.init_global thy4) [mk_meta_eq mem_Collect_eq]; |
|
273 |
274 val newT_iso_axms = typedefs |> map (fn (_, (_, {Abs_inverse, Rep_inverse, Rep, ...})) => |
274 val newT_iso_axms = typedefs |> map (fn (_, (_, {Abs_inverse, Rep_inverse, Rep, ...})) => |
275 (collect_simp Abs_inverse, Rep_inverse, collect_simp Rep)); |
275 (collect_simp Abs_inverse, Rep_inverse, collect_simp Rep)); |
276 |
276 |
277 val newT_iso_inj_thms = typedefs |> map (fn (_, (_, {Abs_inject, Rep_inject, ...})) => |
277 val newT_iso_inj_thms = typedefs |> map (fn (_, (_, {Abs_inject, Rep_inject, ...})) => |
278 (collect_simp Abs_inject RS iffD1, Rep_inject RS iffD1)); |
278 (collect_simp Abs_inject RS iffD1, Rep_inject RS iffD1)); |
353 (* prove characteristic equations *) |
353 (* prove characteristic equations *) |
354 |
354 |
355 val rewrites = def_thms @ map mk_meta_eq rec_rewrites; |
355 val rewrites = def_thms @ map mk_meta_eq rec_rewrites; |
356 val char_thms' = |
356 val char_thms' = |
357 map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn |
357 map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn |
358 (fn _ => EVERY [rewrite_goals_tac rewrites, rtac refl 1])) eqns; |
358 (fn {context = ctxt, ...} => EVERY [rewrite_goals_tac ctxt rewrites, rtac refl 1])) eqns; |
359 |
359 |
360 in (thy', char_thms' @ char_thms) end; |
360 in (thy', char_thms' @ char_thms) end; |
361 |
361 |
362 val (thy5, iso_char_thms) = |
362 val (thy5, iso_char_thms) = |
363 fold_rev make_iso_defs (tl descr) (Sign.add_path big_name thy4, []); |
363 fold_rev make_iso_defs (tl descr) (Sign.add_path big_name thy4, []); |
416 |
416 |
417 val inj_thm = |
417 val inj_thm = |
418 Goal.prove_sorry_global thy5 [] [] |
418 Goal.prove_sorry_global thy5 [] [] |
419 (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl1)) |
419 (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl1)) |
420 (fn {context = ctxt, ...} => EVERY |
420 (fn {context = ctxt, ...} => EVERY |
421 [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1, |
421 [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1, |
422 REPEAT (EVERY |
422 REPEAT (EVERY |
423 [rtac allI 1, rtac impI 1, |
423 [rtac allI 1, rtac impI 1, |
424 Datatype_Aux.exh_tac (exh_thm_of dt_info) 1, |
424 Datatype_Aux.exh_tac (exh_thm_of dt_info) 1, |
425 REPEAT (EVERY |
425 REPEAT (EVERY |
426 [hyp_subst_tac ctxt 1, |
426 [hyp_subst_tac ctxt 1, |
427 rewrite_goals_tac rewrites, |
427 rewrite_goals_tac ctxt rewrites, |
428 REPEAT (dresolve_tac [In0_inject, In1_inject] 1), |
428 REPEAT (dresolve_tac [In0_inject, In1_inject] 1), |
429 (eresolve_tac [In0_not_In1 RS notE, In1_not_In0 RS notE] 1) |
429 (eresolve_tac [In0_not_In1 RS notE, In1_not_In0 RS notE] 1) |
430 ORELSE (EVERY |
430 ORELSE (EVERY |
431 [REPEAT (eresolve_tac (Scons_inject :: |
431 [REPEAT (eresolve_tac (Scons_inject :: |
432 map make_elim [Leaf_inject, Inl_inject, Inr_inject]) 1), |
432 map make_elim [Leaf_inject, Inl_inject, Inr_inject]) 1), |
441 val inj_thms'' = map (fn r => r RS datatype_injI) (Datatype_Aux.split_conj_thm inj_thm); |
441 val inj_thms'' = map (fn r => r RS datatype_injI) (Datatype_Aux.split_conj_thm inj_thm); |
442 |
442 |
443 val elem_thm = |
443 val elem_thm = |
444 Goal.prove_sorry_global thy5 [] [] |
444 Goal.prove_sorry_global thy5 [] [] |
445 (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl2)) |
445 (HOLogic.mk_Trueprop (Datatype_Aux.mk_conj ind_concl2)) |
446 (fn _ => |
446 (fn {context = ctxt, ...} => |
447 EVERY [(Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1, |
447 EVERY [ |
448 rewrite_goals_tac rewrites, |
448 (Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1, |
|
449 rewrite_goals_tac ctxt rewrites, |
449 REPEAT ((resolve_tac rep_intrs THEN_ALL_NEW |
450 REPEAT ((resolve_tac rep_intrs THEN_ALL_NEW |
450 ((REPEAT o etac allE) THEN' ares_tac elem_thms)) 1)]); |
451 ((REPEAT o etac allE) THEN' ares_tac elem_thms)) 1)]); |
451 |
452 |
452 in (inj_thms'' @ inj_thms, elem_thms @ Datatype_Aux.split_conj_thm elem_thm) end; |
453 in (inj_thms'' @ inj_thms, elem_thms @ Datatype_Aux.split_conj_thm elem_thm) end; |
453 |
454 |
478 val iso_thms = |
479 val iso_thms = |
479 if length descr = 1 then [] |
480 if length descr = 1 then [] |
480 else |
481 else |
481 drop (length newTs) (Datatype_Aux.split_conj_thm |
482 drop (length newTs) (Datatype_Aux.split_conj_thm |
482 (Goal.prove_sorry_global thy5 [] [] iso_t (fn {context = ctxt, ...} => EVERY |
483 (Goal.prove_sorry_global thy5 [] [] iso_t (fn {context = ctxt, ...} => EVERY |
483 [(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 ctxt) 1, |
484 REPEAT (rtac TrueI 1), |
485 REPEAT (rtac TrueI 1), |
485 rewrite_goals_tac (mk_meta_eq @{thm choice_eq} :: |
486 rewrite_goals_tac ctxt (mk_meta_eq @{thm choice_eq} :: |
486 Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs), |
487 Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs), |
487 rewrite_goals_tac (map Thm.symmetric range_eqs), |
488 rewrite_goals_tac ctxt (map Thm.symmetric range_eqs), |
488 REPEAT (EVERY |
489 REPEAT (EVERY |
489 [REPEAT (eresolve_tac ([rangeE, ex1_implies_ex RS exE] @ |
490 [REPEAT (eresolve_tac ([rangeE, ex1_implies_ex RS exE] @ |
490 maps (mk_funs_inv thy5 o #1) newT_iso_axms) 1), |
491 maps (mk_funs_inv thy5 o #1) newT_iso_axms) 1), |
491 TRY (hyp_subst_tac ctxt 1), |
492 TRY (hyp_subst_tac ctxt 1), |
492 rtac (sym RS range_eqI) 1, |
493 rtac (sym RS range_eqI) 1, |
509 let |
510 let |
510 val inj_thms = map fst newT_iso_inj_thms; |
511 val inj_thms = map fst newT_iso_inj_thms; |
511 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; |
512 in |
513 in |
513 Goal.prove_sorry_global thy5 [] [] eqn |
514 Goal.prove_sorry_global thy5 [] [] eqn |
514 (fn _ => EVERY |
515 (fn {context = ctxt, ...} => EVERY |
515 [resolve_tac inj_thms 1, |
516 [resolve_tac inj_thms 1, |
516 rewrite_goals_tac rewrites, |
517 rewrite_goals_tac ctxt rewrites, |
517 rtac refl 3, |
518 rtac refl 3, |
518 resolve_tac rep_intrs 2, |
519 resolve_tac rep_intrs 2, |
519 REPEAT (resolve_tac iso_elem_thms 1)]) |
520 REPEAT (resolve_tac iso_elem_thms 1)]) |
520 end; |
521 end; |
521 |
522 |
632 (Logic.strip_imp_prems dt_induct_prop) |
633 (Logic.strip_imp_prems dt_induct_prop) |
633 (Logic.strip_imp_concl dt_induct_prop) |
634 (Logic.strip_imp_concl dt_induct_prop) |
634 (fn {context = ctxt, prems, ...} => |
635 (fn {context = ctxt, prems, ...} => |
635 EVERY |
636 EVERY |
636 [rtac indrule_lemma' 1, |
637 [rtac indrule_lemma' 1, |
637 (Datatype_Aux.ind_tac rep_induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac) 1, |
638 (Datatype_Aux.ind_tac rep_induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1, |
638 EVERY (map (fn (prem, r) => (EVERY |
639 EVERY (map (fn (prem, r) => (EVERY |
639 [REPEAT (eresolve_tac Abs_inverse_thms 1), |
640 [REPEAT (eresolve_tac Abs_inverse_thms 1), |
640 simp_tac (put_simpset HOL_basic_ss ctxt |
641 simp_tac (put_simpset HOL_basic_ss ctxt |
641 addsimps (Thm.symmetric r :: Rep_inverse_thms')) 1, |
642 addsimps (Thm.symmetric r :: Rep_inverse_thms')) 1, |
642 DEPTH_SOLVE_1 (ares_tac [prem] 1 ORELSE etac allE 1)])) |
643 DEPTH_SOLVE_1 (ares_tac [prem] 1 ORELSE etac allE 1)])) |