470 ((is_some gfp_sugar_thms, map5 mk_spec fp_sugars p_iss q_issss f_issss f_Tssss, missing_res_Ts, |
470 ((is_some gfp_sugar_thms, map5 mk_spec fp_sugars p_iss q_issss f_issss f_Tssss, missing_res_Ts, |
471 co_induct_of coinduct_thms, strong_co_induct_of coinduct_thms, co_induct_of coinduct_thmss, |
471 co_induct_of coinduct_thms, strong_co_induct_of coinduct_thms, co_induct_of coinduct_thmss, |
472 strong_co_induct_of coinduct_thmss), lthy') |
472 strong_co_induct_of coinduct_thmss), lthy') |
473 end; |
473 end; |
474 |
474 |
475 val const_name = try (fn Const (v, _) => v); |
|
476 val undef_const = Const (@{const_name undefined}, dummyT); |
475 val undef_const = Const (@{const_name undefined}, dummyT); |
477 |
476 |
478 val abs_tuple = HOLogic.tupled_lambda o HOLogic.mk_tuple; |
477 val abs_tuple = HOLogic.tupled_lambda o HOLogic.mk_tuple; |
479 fun abstract vs = |
478 fun abstract vs = |
480 let fun a n (t $ u) = a n t $ a n u |
479 let fun a n (t $ u) = a n t $ a n u |
481 | a n (Abs (v, T, b)) = Abs (v, T, a (n + 1) b) |
480 | a n (Abs (v, T, b)) = Abs (v, T, a (n + 1) b) |
482 | a n t = let val idx = find_index (equal t) vs in |
481 | a n t = let val idx = find_index (equal t) vs in |
483 if idx < 0 then t else Bound (n + idx) end |
482 if idx < 0 then t else Bound (n + idx) end |
484 in a 0 end; |
483 in a 0 end; |
485 fun mk_prod1 Ts (t, u) = HOLogic.pair_const (fastype_of1 (Ts, t)) (fastype_of1 (Ts, u)) $ t $ u; |
484 |
486 fun mk_tuple1 Ts = the_default HOLogic.unit o try (foldr1 (mk_prod1 Ts)); |
485 fun mk_prod1 bound_Ts (t, u) = |
|
486 HOLogic.pair_const (fastype_of1 (bound_Ts, t)) (fastype_of1 (bound_Ts, u)) $ t $ u; |
|
487 fun mk_tuple1 bound_Ts = the_default HOLogic.unit o try (foldr1 (mk_prod1 bound_Ts)); |
487 |
488 |
488 type coeqn_data_disc = { |
489 type coeqn_data_disc = { |
489 fun_name: string, |
490 fun_name: string, |
490 fun_T: typ, |
491 fun_T: typ, |
491 fun_args: term list, |
492 fun_args: term list, |
737 fun rewrite bound_Ts U T (Abs (v, V, b)) = Abs (v, V, rewrite (V :: bound_Ts) U T b) |
738 fun rewrite bound_Ts U T (Abs (v, V, b)) = Abs (v, V, rewrite (V :: bound_Ts) U T b) |
738 | rewrite bound_Ts U T (t as _ $ _) = |
739 | rewrite bound_Ts U T (t as _ $ _) = |
739 let val (u, vs) = strip_comb t in |
740 let val (u, vs) = strip_comb t in |
740 if is_Free u andalso has_call u then |
741 if is_Free u andalso has_call u then |
741 Inr_const U T $ mk_tuple1 bound_Ts vs |
742 Inr_const U T $ mk_tuple1 bound_Ts vs |
742 else if const_name u = SOME @{const_name prod_case} then |
743 else if try (fst o dest_Const) u = SOME @{const_name prod_case} then |
743 map (rewrite bound_Ts U T) vs |> chop 1 |>> HOLogic.mk_split o the_single |> list_comb |
744 map (rewrite bound_Ts U T) vs |> chop 1 |>> HOLogic.mk_split o the_single |> list_comb |
744 else |
745 else |
745 list_comb (rewrite bound_Ts U T u, map (rewrite bound_Ts U T) vs) |
746 list_comb (rewrite bound_Ts U T u, map (rewrite bound_Ts U T) vs) |
746 end |
747 end |
747 | rewrite _ U T t = |
748 | rewrite _ U T t = |