146 else |
146 else |
147 let |
147 let |
148 val (r, dep, branches) = find_cong_rule ctx fvar h congs_deps t |
148 val (r, dep, branches) = find_cong_rule ctx fvar h congs_deps t |
149 fun subtree (ctx', fixes, assumes, st) = |
149 fun subtree (ctx', fixes, assumes, st) = |
150 ((fixes, |
150 ((fixes, |
151 map (assume o cterm_of (ProofContext.theory_of ctx)) assumes), |
151 map (Thm.assume o cterm_of (ProofContext.theory_of ctx)) assumes), |
152 mk_tree' ctx' st) |
152 mk_tree' ctx' st) |
153 in |
153 in |
154 Cong (r, dep, map subtree branches) |
154 Cong (r, dep, map subtree branches) |
155 end |
155 end |
156 in |
156 in |
163 val cf = cterm_of thy f |
163 val cf = cterm_of thy f |
164 |
164 |
165 fun inst_term t = |
165 fun inst_term t = |
166 subst_bound(f, abstract_over (fvar, t)) |
166 subst_bound(f, abstract_over (fvar, t)) |
167 |
167 |
168 val inst_thm = forall_elim cf o forall_intr cfvar |
168 val inst_thm = Thm.forall_elim cf o Thm.forall_intr cfvar |
169 |
169 |
170 fun inst_tree_aux (Leaf t) = Leaf t |
170 fun inst_tree_aux (Leaf t) = Leaf t |
171 | inst_tree_aux (Cong (crule, deps, branches)) = |
171 | inst_tree_aux (Cong (crule, deps, branches)) = |
172 Cong (inst_thm crule, deps, map inst_branch branches) |
172 Cong (inst_thm crule, deps, map inst_branch branches) |
173 | inst_tree_aux (RCall (t, str)) = |
173 | inst_tree_aux (RCall (t, str)) = |
174 RCall (inst_term t, inst_tree_aux str) |
174 RCall (inst_term t, inst_tree_aux str) |
175 and inst_branch ((fxs, assms), str) = |
175 and inst_branch ((fxs, assms), str) = |
176 ((fxs, map (assume o cterm_of thy o inst_term o prop_of) assms), |
176 ((fxs, map (Thm.assume o cterm_of thy o inst_term o prop_of) assms), |
177 inst_tree_aux str) |
177 inst_tree_aux str) |
178 in |
178 in |
179 inst_tree_aux tr |
179 inst_tree_aux tr |
180 end |
180 end |
181 |
181 |
186 fun export_term (fixes, assumes) = |
186 fun export_term (fixes, assumes) = |
187 fold_rev (curry Logic.mk_implies o prop_of) assumes |
187 fold_rev (curry Logic.mk_implies o prop_of) assumes |
188 #> fold_rev (Logic.all o Free) fixes |
188 #> fold_rev (Logic.all o Free) fixes |
189 |
189 |
190 fun export_thm thy (fixes, assumes) = |
190 fun export_thm thy (fixes, assumes) = |
191 fold_rev (implies_intr o cprop_of) assumes |
191 fold_rev (Thm.implies_intr o cprop_of) assumes |
192 #> fold_rev (forall_intr o cterm_of thy o Free) fixes |
192 #> fold_rev (Thm.forall_intr o cterm_of thy o Free) fixes |
193 |
193 |
194 fun import_thm thy (fixes, athms) = |
194 fun import_thm thy (fixes, athms) = |
195 fold (forall_elim o cterm_of thy o Free) fixes |
195 fold (Thm.forall_elim o cterm_of thy o Free) fixes |
196 #> fold Thm.elim_implies athms |
196 #> fold Thm.elim_implies athms |
197 |
197 |
198 |
198 |
199 (* folds in the order of the dependencies of a graph. *) |
199 (* folds in the order of the dependencies of a graph. *) |
200 fun fold_deps G f x = |
200 fun fold_deps G f x = |
239 snd o traverse_help ([], []) tr [] |
239 snd o traverse_help ([], []) tr [] |
240 end |
240 end |
241 |
241 |
242 fun rewrite_by_tree thy h ih x tr = |
242 fun rewrite_by_tree thy h ih x tr = |
243 let |
243 let |
244 fun rewrite_help _ _ x (Leaf t) = (reflexive (cterm_of thy t), x) |
244 fun rewrite_help _ _ x (Leaf t) = (Thm.reflexive (cterm_of thy t), x) |
245 | rewrite_help fix h_as x (RCall (_ $ arg, st)) = |
245 | rewrite_help fix h_as x (RCall (_ $ arg, st)) = |
246 let |
246 let |
247 val (inner, (lRi,ha)::x') = rewrite_help fix h_as x st (* "a' = a" *) |
247 val (inner, (lRi,ha)::x') = rewrite_help fix h_as x st (* "a' = a" *) |
248 |
248 |
249 val iha = import_thm thy (fix, h_as) ha (* (a', h a') : G *) |
249 val iha = import_thm thy (fix, h_as) ha (* (a', h a') : G *) |
250 |> Conv.fconv_rule (Conv.arg_conv (Conv.comb_conv (Conv.arg_conv (K inner)))) |
250 |> Conv.fconv_rule (Conv.arg_conv (Conv.comb_conv (Conv.arg_conv (K inner)))) |
251 (* (a, h a) : G *) |
251 (* (a, h a) : G *) |
252 val inst_ih = instantiate' [] [SOME (cterm_of thy arg)] ih |
252 val inst_ih = instantiate' [] [SOME (cterm_of thy arg)] ih |
253 val eq = implies_elim (implies_elim inst_ih lRi) iha (* h a = f a *) |
253 val eq = Thm.implies_elim (Thm.implies_elim inst_ih lRi) iha (* h a = f a *) |
254 |
254 |
255 val h_a'_eq_h_a = combination (reflexive (cterm_of thy h)) inner |
255 val h_a'_eq_h_a = Thm.combination (Thm.reflexive (cterm_of thy h)) inner |
256 val h_a_eq_f_a = eq RS eq_reflection |
256 val h_a_eq_f_a = eq RS eq_reflection |
257 val result = transitive h_a'_eq_h_a h_a_eq_f_a |
257 val result = Thm.transitive h_a'_eq_h_a h_a_eq_f_a |
258 in |
258 in |
259 (result, x') |
259 (result, x') |
260 end |
260 end |
261 | rewrite_help fix h_as x (Cong (crule, deps, branches)) = |
261 | rewrite_help fix h_as x (Cong (crule, deps, branches)) = |
262 let |
262 let |