142 val mk_convol: term * term -> term |
142 val mk_convol: term * term -> term |
143 |
143 |
144 val Inl_const: typ -> typ -> term |
144 val Inl_const: typ -> typ -> term |
145 val Inr_const: typ -> typ -> term |
145 val Inr_const: typ -> typ -> term |
146 |
146 |
|
147 val mk_case_sum: term * term -> term |
|
148 val mk_case_sumN: term list -> term |
|
149 val mk_case_sumN_balanced: term list -> term |
147 val mk_Inl: typ -> term -> term |
150 val mk_Inl: typ -> term -> term |
148 val mk_Inr: typ -> term -> term |
151 val mk_Inr: typ -> term -> term |
149 val mk_InN: typ list -> term -> int -> term |
152 val mk_InN: typ list -> term -> int -> term |
150 val mk_InN_balanced: typ -> int -> term -> int -> term |
153 val mk_InN_balanced: typ -> int -> term -> int -> term |
151 val mk_sum_case: term * term -> term |
|
152 val mk_sum_caseN: term list -> term |
|
153 val mk_sum_caseN_balanced: term list -> term |
|
154 |
154 |
155 val dest_sumT: typ -> typ * typ |
155 val dest_sumT: typ -> typ * typ |
156 val dest_sumTN: int -> typ -> typ list |
156 val dest_sumTN: int -> typ -> typ list |
157 val dest_sumTN_balanced: int -> typ -> typ list |
157 val dest_sumTN_balanced: int -> typ -> typ list |
158 val dest_tupleT: int -> typ -> typ list |
158 val dest_tupleT: int -> typ -> typ list |
164 val mk_union: term * term -> term |
164 val mk_union: term * term -> term |
165 |
165 |
166 val mk_sumEN: int -> thm |
166 val mk_sumEN: int -> thm |
167 val mk_sumEN_balanced: int -> thm |
167 val mk_sumEN_balanced: int -> thm |
168 val mk_sumEN_tupled_balanced: int list -> thm |
168 val mk_sumEN_tupled_balanced: int list -> thm |
169 val mk_sum_casesN: int -> int -> thm |
169 val mk_sum_caseN: int -> int -> thm |
170 val mk_sum_casesN_balanced: int -> int -> thm |
170 val mk_sum_caseN_balanced: int -> int -> thm |
171 |
171 |
172 val fixpoint: ('a * 'a -> bool) -> ('a list -> 'a list) -> 'a list -> 'a list |
172 val fixpoint: ('a * 'a -> bool) -> ('a list -> 'a list) -> 'a list -> 'a list |
173 |
173 |
174 val mk_rel_xtor_co_induct_thm: fp_kind -> term list -> term list -> term list -> term list -> |
174 val mk_rel_xtor_co_induct_thm: fp_kind -> term list -> term list -> term list -> term list -> |
175 term list -> term list -> term list -> term list -> |
175 term list -> term list -> term list -> term list -> |
407 in |
407 in |
408 Balanced_Tree.access {left = mk_Inl dummyT, right = mk_Inr dummyT, init = t} n k |
408 Balanced_Tree.access {left = mk_Inl dummyT, right = mk_Inr dummyT, init = t} n k |
409 |> repair_types sum_T |
409 |> repair_types sum_T |
410 end; |
410 end; |
411 |
411 |
412 fun mk_sum_case (f, g) = |
412 fun mk_case_sum (f, g) = |
413 let |
413 let |
414 val fT = fastype_of f; |
414 val fT = fastype_of f; |
415 val gT = fastype_of g; |
415 val gT = fastype_of g; |
416 in |
416 in |
417 Const (@{const_name sum_case}, |
417 Const (@{const_name case_sum}, |
418 fT --> gT --> mk_sumT (domain_type fT, domain_type gT) --> range_type fT) $ f $ g |
418 fT --> gT --> mk_sumT (domain_type fT, domain_type gT) --> range_type fT) $ f $ g |
419 end; |
419 end; |
420 |
420 |
421 val mk_sum_caseN = Library.foldr1 mk_sum_case; |
421 val mk_case_sumN = Library.foldr1 mk_case_sum; |
422 val mk_sum_caseN_balanced = Balanced_Tree.make mk_sum_case; |
422 val mk_case_sumN_balanced = Balanced_Tree.make mk_case_sum; |
423 |
423 |
424 fun If_const T = Const (@{const_name If}, HOLogic.boolT --> T --> T --> T); |
424 fun If_const T = Const (@{const_name If}, HOLogic.boolT --> T --> T --> T); |
425 fun mk_If p t f = let val T = fastype_of t in If_const T $ p $ t $ f end; |
425 fun mk_If p t f = let val T = fastype_of t in If_const T $ p $ t $ f end; |
426 |
426 |
427 fun mk_Field r = |
427 fun mk_Field r = |
468 let val n = length ms in |
468 let val n = length ms in |
469 if forall (curry op = 1) ms then mk_sumEN_balanced n |
469 if forall (curry op = 1) ms then mk_sumEN_balanced n |
470 else mk_sumEN_balanced' n (map mk_tupled_allIN ms) |
470 else mk_sumEN_balanced' n (map mk_tupled_allIN ms) |
471 end; |
471 end; |
472 |
472 |
473 fun mk_sum_casesN 1 1 = refl |
473 fun mk_sum_caseN 1 1 = refl |
474 | mk_sum_casesN _ 1 = @{thm sum.cases(1)} |
474 | mk_sum_caseN _ 1 = @{thm sum.case(1)} |
475 | mk_sum_casesN 2 2 = @{thm sum.cases(2)} |
475 | mk_sum_caseN 2 2 = @{thm sum.case(2)} |
476 | mk_sum_casesN n k = trans OF [@{thm sum_case_step(2)}, mk_sum_casesN (n - 1) (k - 1)]; |
476 | mk_sum_caseN n k = trans OF [@{thm case_sum_step(2)}, mk_sum_caseN (n - 1) (k - 1)]; |
477 |
477 |
478 fun mk_sum_step base step thm = |
478 fun mk_sum_step base step thm = |
479 if Thm.eq_thm_prop (thm, refl) then base else trans OF [step, thm]; |
479 if Thm.eq_thm_prop (thm, refl) then base else trans OF [step, thm]; |
480 |
480 |
481 fun mk_sum_casesN_balanced 1 1 = refl |
481 fun mk_sum_caseN_balanced 1 1 = refl |
482 | mk_sum_casesN_balanced n k = |
482 | mk_sum_caseN_balanced n k = |
483 Balanced_Tree.access {left = mk_sum_step @{thm sum.cases(1)} @{thm sum_case_step(1)}, |
483 Balanced_Tree.access {left = mk_sum_step @{thm sum.cases(1)} @{thm case_sum_step(1)}, |
484 right = mk_sum_step @{thm sum.cases(2)} @{thm sum_case_step(2)}, init = refl} n k; |
484 right = mk_sum_step @{thm sum.cases(2)} @{thm case_sum_step(2)}, init = refl} n k; |
485 |
485 |
486 fun mk_rel_xtor_co_induct_thm fp pre_rels pre_phis rels phis xs ys xtors xtor's tac lthy = |
486 fun mk_rel_xtor_co_induct_thm fp pre_rels pre_phis rels phis xs ys xtors xtor's tac lthy = |
487 let |
487 let |
488 val pre_relphis = map (fn rel => Term.list_comb (rel, phis @ pre_phis)) pre_rels; |
488 val pre_relphis = map (fn rel => Term.list_comb (rel, phis @ pre_phis)) pre_rels; |
489 val relphis = map (fn rel => Term.list_comb (rel, phis)) rels; |
489 val relphis = map (fn rel => Term.list_comb (rel, phis)) rels; |
530 val n = length sym_map_comps; |
530 val n = length sym_map_comps; |
531 val rewrite_comp_comp2 = fp_case fp @{thm rewriteR_comp_comp2} @{thm rewriteL_comp_comp2}; |
531 val rewrite_comp_comp2 = fp_case fp @{thm rewriteR_comp_comp2} @{thm rewriteL_comp_comp2}; |
532 val rewrite_comp_comp = fp_case fp @{thm rewriteR_comp_comp} @{thm rewriteL_comp_comp}; |
532 val rewrite_comp_comp = fp_case fp @{thm rewriteR_comp_comp} @{thm rewriteL_comp_comp}; |
533 val map_cong_passive_args1 = replicate m (fp_case fp @{thm id_comp} @{thm comp_id} RS fun_cong); |
533 val map_cong_passive_args1 = replicate m (fp_case fp @{thm id_comp} @{thm comp_id} RS fun_cong); |
534 val map_cong_active_args1 = replicate n (if is_rec |
534 val map_cong_active_args1 = replicate n (if is_rec |
535 then fp_case fp @{thm convol_o} @{thm o_sum_case} RS fun_cong |
535 then fp_case fp @{thm convol_o} @{thm o_case_sum} RS fun_cong |
536 else refl); |
536 else refl); |
537 val map_cong_passive_args2 = replicate m (fp_case fp @{thm comp_id} @{thm id_comp} RS fun_cong); |
537 val map_cong_passive_args2 = replicate m (fp_case fp @{thm comp_id} @{thm id_comp} RS fun_cong); |
538 val map_cong_active_args2 = replicate n (if is_rec |
538 val map_cong_active_args2 = replicate n (if is_rec |
539 then fp_case fp @{thm map_pair_o_convol_id} @{thm sum_case_o_sum_map_id} |
539 then fp_case fp @{thm map_pair_o_convol_id} @{thm case_sum_o_sum_map_id} |
540 else fp_case fp @{thm id_comp} @{thm comp_id} RS fun_cong); |
540 else fp_case fp @{thm id_comp} @{thm comp_id} RS fun_cong); |
541 fun mk_map_congs passive active = map (fn thm => thm OF (passive @ active) RS ext) map_cong0s; |
541 fun mk_map_congs passive active = map (fn thm => thm OF (passive @ active) RS ext) map_cong0s; |
542 val map_cong1s = mk_map_congs map_cong_passive_args1 map_cong_active_args1; |
542 val map_cong1s = mk_map_congs map_cong_passive_args1 map_cong_active_args1; |
543 val map_cong2s = mk_map_congs map_cong_passive_args2 map_cong_active_args2; |
543 val map_cong2s = mk_map_congs map_cong_passive_args2 map_cong_active_args2; |
544 |
544 |