113 val (free_vars, prop, ranT, name_ctxt) = mk_funeq arity (fastype_of f) name_ctxt ([], f); |
113 val (free_vars, prop, ranT, name_ctxt) = mk_funeq arity (fastype_of f) name_ctxt ([], f); |
114 val (rhs_var, arg_vars) = (case free_vars of x :: xs => (x, rev xs)); |
114 val (rhs_var, arg_vars) = (case free_vars of x :: xs => (x, rev xs)); |
115 val args = HOLogic.mk_tuple arg_vars; |
115 val args = HOLogic.mk_tuple arg_vars; |
116 val domT = R |> dest_Free |> snd |> hd o snd o dest_Type; |
116 val domT = R |> dest_Free |> snd |> hd o snd o dest_Type; |
117 |
117 |
118 val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Proof_Context.cterm_of ctxt |
118 val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Thm.cterm_of ctxt |
119 val sumtree_inj = Sum_Tree.mk_inj domT n_fs (idx+1) args; |
119 val sumtree_inj = Sum_Tree.mk_inj domT n_fs (idx+1) args; |
120 |
120 |
121 val cprop = Proof_Context.cterm_of ctxt prop; |
121 val cprop = Thm.cterm_of ctxt prop; |
122 |
122 |
123 val asms = [cprop, Proof_Context.cterm_of ctxt (HOLogic.mk_Trueprop (dom $ sumtree_inj))]; |
123 val asms = [cprop, Thm.cterm_of ctxt (HOLogic.mk_Trueprop (dom $ sumtree_inj))]; |
124 val asms_thms = map Thm.assume asms; |
124 val asms_thms = map Thm.assume asms; |
125 |
125 |
126 fun prep_subgoal_tac i = |
126 fun prep_subgoal_tac i = |
127 REPEAT (eresolve_tac ctxt @{thms Pair_inject} i) |
127 REPEAT (eresolve_tac ctxt @{thms Pair_inject} i) |
128 THEN Method.insert_tac (case asms_thms of thm :: thms => (thm RS sym) :: thms) i |
128 THEN Method.insert_tac (case asms_thms of thm :: thms => (thm RS sym) :: thms) i |
131 THEN bool_subst_tac ctxt i; |
131 THEN bool_subst_tac ctxt i; |
132 |
132 |
133 val elim_stripped = |
133 val elim_stripped = |
134 nth cases idx |
134 nth cases idx |
135 |> Thm.forall_elim P |
135 |> Thm.forall_elim P |
136 |> Thm.forall_elim (Proof_Context.cterm_of ctxt args) |
136 |> Thm.forall_elim (Thm.cterm_of ctxt args) |
137 |> Tactic.rule_by_tactic ctxt (ALLGOALS prep_subgoal_tac) |
137 |> Tactic.rule_by_tactic ctxt (ALLGOALS prep_subgoal_tac) |
138 |> fold_rev Thm.implies_intr asms |
138 |> fold_rev Thm.implies_intr asms |
139 |> Thm.forall_intr (Proof_Context.cterm_of ctxt rhs_var); |
139 |> Thm.forall_intr (Thm.cterm_of ctxt rhs_var); |
140 |
140 |
141 val bool_elims = |
141 val bool_elims = |
142 (case ranT of |
142 (case ranT of |
143 Type (@{type_name bool}, []) => mk_bool_elims ctxt elim_stripped |
143 Type (@{type_name bool}, []) => mk_bool_elims ctxt elim_stripped |
144 | _ => []); |
144 | _ => []); |
145 |
145 |
146 fun unstrip rl = |
146 fun unstrip rl = |
147 rl |
147 rl |
148 |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) arg_vars |
148 |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) arg_vars |
149 |> Thm.forall_intr P |
149 |> Thm.forall_intr P |
150 in |
150 in |
151 map unstrip (elim_stripped :: bool_elims) |
151 map unstrip (elim_stripped :: bool_elims) |
152 end; |
152 end; |
153 in |
153 in |