164 val mk_sum_casesN: int -> int -> thm |
164 val mk_sum_casesN: int -> int -> thm |
165 val mk_sum_casesN_balanced: int -> int -> thm |
165 val mk_sum_casesN_balanced: int -> int -> thm |
166 |
166 |
167 val fixpoint: ('a * 'a -> bool) -> ('a list -> 'a list) -> 'a list -> 'a list |
167 val fixpoint: ('a * 'a -> bool) -> ('a list -> 'a list) -> 'a list -> 'a list |
168 |
168 |
|
169 val mk_rel_co_induct_thm: fp_kind -> term list -> term list -> term list -> term list -> |
|
170 term list -> term list -> term list -> term list -> |
|
171 ({prems: thm list, context: Proof.context} -> tactic) -> Proof.context -> thm |
|
172 |
169 val fp_bnf: (binding list -> (string * sort) list -> typ list * typ list list -> |
173 val fp_bnf: (binding list -> (string * sort) list -> typ list * typ list list -> |
170 BNF_Def.bnf list -> local_theory -> 'a) -> |
174 BNF_Def.bnf list -> local_theory -> 'a) -> |
171 binding list -> (string * sort) list -> ((string * sort) * typ) list -> local_theory -> |
175 binding list -> (string * sort) list -> ((string * sort) * typ) list -> local_theory -> |
172 BNF_Def.bnf list * 'a |
176 BNF_Def.bnf list * 'a |
173 end; |
177 end; |
457 fun mk_sum_casesN_balanced 1 1 = refl |
461 fun mk_sum_casesN_balanced 1 1 = refl |
458 | mk_sum_casesN_balanced n k = |
462 | mk_sum_casesN_balanced n k = |
459 Balanced_Tree.access {left = mk_sum_step @{thm sum.cases(1)} @{thm sum_case_step(1)}, |
463 Balanced_Tree.access {left = mk_sum_step @{thm sum.cases(1)} @{thm sum_case_step(1)}, |
460 right = mk_sum_step @{thm sum.cases(2)} @{thm sum_case_step(2)}, init = refl} n k; |
464 right = mk_sum_step @{thm sum.cases(2)} @{thm sum_case_step(2)}, init = refl} n k; |
461 |
465 |
|
466 fun mk_rel_co_induct_thm fp pre_rels pre_phis rels phis xs ys xtors xtor's tac lthy = |
|
467 let |
|
468 val pre_relphis = map (fn rel => Term.list_comb (rel, phis @ pre_phis)) pre_rels; |
|
469 val relphis = map (fn rel => Term.list_comb (rel, phis)) rels; |
|
470 fun mk_xtor fp' xtor x = if fp = fp' then xtor $ x else x; |
|
471 val dtor = mk_xtor Greatest_FP; |
|
472 val ctor = mk_xtor Least_FP; |
|
473 fun flip f x y = if fp = Greatest_FP then f y x else f x y; |
|
474 |
|
475 fun mk_prem pre_relphi phi x y xtor xtor' = |
|
476 HOLogic.mk_Trueprop (list_all_free [x, y] (flip (curry HOLogic.mk_imp) |
|
477 (pre_relphi $ (dtor xtor x) $ (dtor xtor' y)) (phi $ (ctor xtor x) $ (ctor xtor' y)))); |
|
478 val prems = map6 mk_prem pre_relphis pre_phis xs ys xtors xtor's; |
|
479 |
|
480 val concl = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj |
|
481 (map2 (flip mk_leq) relphis pre_phis)); |
|
482 in |
|
483 Goal.prove_sorry lthy [] [] |
|
484 (fold_rev Logic.all (phis @ pre_phis) (Logic.list_implies (prems, concl))) tac |
|
485 |> Thm.close_derivation |
|
486 |> (fn thm => thm OF (replicate (length pre_rels) @{thm allI[OF allI[OF impI]]})) |
|
487 end; |
|
488 |
462 fun fp_bnf construct_fp bs resBs eqs lthy = |
489 fun fp_bnf construct_fp bs resBs eqs lthy = |
463 let |
490 let |
464 val timer = time (Timer.startRealTimer ()); |
491 val timer = time (Timer.startRealTimer ()); |
465 val (lhss, rhss) = split_list eqs; |
492 val (lhss, rhss) = split_list eqs; |
466 |
493 |