608 fun mk_prod ((t1, T1), (t2, T2)) = (HOLogic.pair_const T1 T2 $ t1 $ t2, HOLogic.mk_prodT (T1, T2)) |
608 fun mk_prod ((t1, T1), (t2, T2)) = (HOLogic.pair_const T1 T2 $ t1 $ t2, HOLogic.mk_prodT (T1, T2)) |
609 fun mk_tuple [] = (HOLogic.unit, HOLogic.unitT) |
609 fun mk_tuple [] = (HOLogic.unit, HOLogic.unitT) |
610 | mk_tuple tTs = foldr1 mk_prod tTs |
610 | mk_tuple tTs = foldr1 mk_prod tTs |
611 fun mk_split_abs (T as Type (@{type_name Product_Type.prod}, [T1, T2])) t = |
611 fun mk_split_abs (T as Type (@{type_name Product_Type.prod}, [T1, T2])) t = |
612 absdummy T |
612 absdummy T |
613 (HOLogic.split_const (T1, T2, @{typ bool}) $ (mk_split_abs T1 (mk_split_abs T2 t))) |
613 (HOLogic.case_prod_const (T1, T2, @{typ bool}) $ (mk_split_abs T1 (mk_split_abs T2 t))) |
614 | mk_split_abs T t = absdummy T t |
614 | mk_split_abs T t = absdummy T t |
615 val args = rev (fst (fold_map mk_bounds (rev (binder_types T)) 0)) |
615 val args = rev (fst (fold_map mk_bounds (rev (binder_types T)) 0)) |
616 val (inargs, outargs) = split_mode mode args |
616 val (inargs, outargs) = split_mode mode args |
617 val (_, outTs) = split_map_modeT (fn _ => fn T => (SOME T, NONE)) mode (binder_types T) |
617 val (_, outTs) = split_map_modeT (fn _ => fn T => (SOME T, NONE)) mode (binder_types T) |
618 val inner_term = Predicate_Comp_Funs.mk_Eval (list_comb (P, inargs), fst (mk_tuple (outargs ~~ outTs))) |
618 val inner_term = Predicate_Comp_Funs.mk_Eval (list_comb (P, inargs), fst (mk_tuple (outargs ~~ outTs))) |
1021 end |
1021 end |
1022 |
1022 |
1023 |
1023 |
1024 (* Definition of executable functions and their intro and elim rules *) |
1024 (* Definition of executable functions and their intro and elim rules *) |
1025 |
1025 |
1026 fun strip_split_abs (Const (@{const_name uncurry}, _) $ t) = strip_split_abs t |
1026 fun strip_split_abs (Const (@{const_name case_prod}, _) $ t) = strip_split_abs t |
1027 | strip_split_abs (Abs (_, _, t)) = strip_split_abs t |
1027 | strip_split_abs (Abs (_, _, t)) = strip_split_abs t |
1028 | strip_split_abs t = t |
1028 | strip_split_abs t = t |
1029 |
1029 |
1030 fun mk_args is_eval (m as Pair (m1, m2), T as Type (@{type_name Product_Type.prod}, [T1, T2])) names = |
1030 fun mk_args is_eval (m as Pair (m1, m2), T as Type (@{type_name Product_Type.prod}, [T1, T2])) names = |
1031 if eq_mode (m, Input) orelse eq_mode (m, Output) then |
1031 if eq_mode (m, Input) orelse eq_mode (m, Output) then |
1084 val funpropI = HOLogic.mk_Trueprop (Predicate_Comp_Funs.mk_Eval (list_comb (funtrm, inargs), |
1084 val funpropI = HOLogic.mk_Trueprop (Predicate_Comp_Funs.mk_Eval (list_comb (funtrm, inargs), |
1085 HOLogic.mk_tuple outargs)) |
1085 HOLogic.mk_tuple outargs)) |
1086 val introtrm = Logic.list_implies (predpropI :: param_eqs, funpropI) |
1086 val introtrm = Logic.list_implies (predpropI :: param_eqs, funpropI) |
1087 val simprules = |
1087 val simprules = |
1088 [defthm, @{thm eval_pred}, |
1088 [defthm, @{thm eval_pred}, |
1089 @{thm "split_beta"}, @{thm "fst_conv"}, @{thm "snd_conv"}, @{thm pair_collapse}] |
1089 @{thm "split_beta"}, @{thm "fst_conv"}, @{thm "snd_conv"}, @{thm prod.collapse}] |
1090 val unfolddef_tac = |
1090 val unfolddef_tac = |
1091 Simplifier.asm_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps simprules) 1 |
1091 Simplifier.asm_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps simprules) 1 |
1092 val introthm = Goal.prove ctxt |
1092 val introthm = Goal.prove ctxt |
1093 (argnames @ hoarg_names' @ ["y"]) [] introtrm (fn _ => unfolddef_tac) |
1093 (argnames @ hoarg_names' @ ["y"]) [] introtrm (fn _ => unfolddef_tac) |
1094 val P = HOLogic.mk_Trueprop (Free ("P", HOLogic.boolT)); |
1094 val P = HOLogic.mk_Trueprop (Free ("P", HOLogic.boolT)); |
1746 let |
1746 let |
1747 val inner_t = |
1747 val inner_t = |
1748 (case t_compr of |
1748 (case t_compr of |
1749 (Const (@{const_name Collect}, _) $ t) => t |
1749 (Const (@{const_name Collect}, _) $ t) => t |
1750 | _ => error ("Not a set comprehension: " ^ Syntax.string_of_term ctxt t_compr)) |
1750 | _ => error ("Not a set comprehension: " ^ Syntax.string_of_term ctxt t_compr)) |
1751 val (body, Ts, fp) = HOLogic.strip_psplits inner_t; |
1751 val (body, Ts, fp) = HOLogic.strip_ptupleabs inner_t; |
1752 val output_names = Name.variant_list (Term.add_free_names body []) |
1752 val output_names = Name.variant_list (Term.add_free_names body []) |
1753 (map (fn i => "x" ^ string_of_int i) (1 upto length Ts)) |
1753 (map (fn i => "x" ^ string_of_int i) (1 upto length Ts)) |
1754 val output_frees = map2 (curry Free) output_names (rev Ts) |
1754 val output_frees = map2 (curry Free) output_names (rev Ts) |
1755 val body = subst_bounds (output_frees, body) |
1755 val body = subst_bounds (output_frees, body) |
1756 val T_compr = HOLogic.mk_ptupleT fp Ts |
1756 val T_compr = HOLogic.mk_ptupleT fp Ts |