155 val (fts,its) = |
155 val (fts,its) = |
156 (map (snd o snd) fnvs, |
156 (map (snd o snd) fnvs, |
157 map (fn ((vn,vi),(tT,t)) => (cert(Var ((vn,vi),tT)), cert t)) invs) |
157 map (fn ((vn,vi),(tT,t)) => (cert(Var ((vn,vi),tT)), cert t)) invs) |
158 val ctyenv = map (fn ((vn,vi),(s,ty)) => (certy (TVar((vn,vi),s)), certy ty)) (Vartab.dest tyenv) |
158 val ctyenv = map (fn ((vn,vi),(s,ty)) => (certy (TVar((vn,vi),s)), certy ty)) (Vartab.dest tyenv) |
159 in ((fts ~~ (replicate (length fts) ctxt), |
159 in ((fts ~~ (replicate (length fts) ctxt), |
160 Library.apfst (FWD (instantiate (ctyenv, its) cong))), bds) |
160 Library.apfst (FWD (Drule.instantiate_normalize (ctyenv, its) cong))), bds) |
161 end handle Pattern.MATCH => decomp_genreif da congs (t,ctxt) bds)) |
161 end handle Pattern.MATCH => decomp_genreif da congs (t,ctxt) bds)) |
162 end; |
162 end; |
163 |
163 |
164 (* looks for the atoms equation and instantiates it with the right number *) |
164 (* looks for the atoms equation and instantiates it with the right number *) |
165 fun mk_decompatom eqs (t,ctxt) bds = (([], fn (_, bds) => |
165 fun mk_decompatom eqs (t,ctxt) bds = (([], fn (_, bds) => |
228 (fold (AList.delete (fn (((a: string),_),(b,_)) => a = b)) |
228 (fold (AList.delete (fn (((a: string),_),(b,_)) => a = b)) |
229 (map (fn n => (n,0)) xns) tml) |
229 (map (fn n => (n,0)) xns) tml) |
230 val substt = |
230 val substt = |
231 let val ih = Drule.cterm_rule (Thm.instantiate (subst_ty,[])) |
231 let val ih = Drule.cterm_rule (Thm.instantiate (subst_ty,[])) |
232 in map (fn (v,t) => (ih v, ih t)) (subst_ns@subst_vs@cts) end |
232 in map (fn (v,t) => (ih v, ih t)) (subst_ns@subst_vs@cts) end |
233 val th = (instantiate (subst_ty, substt) eq) RS sym |
233 val th = (Drule.instantiate_normalize (subst_ty, substt) eq) RS sym |
234 in (hd (Variable.export ctxt'' ctxt [th]), bds) end) |
234 in (hd (Variable.export ctxt'' ctxt [th]), bds) end) |
235 handle Pattern.MATCH => tryeqs eqs bds) |
235 handle Pattern.MATCH => tryeqs eqs bds) |
236 in tryeqs (filter isat eqs) bds end), bds); |
236 in tryeqs (filter isat eqs) bds end), bds); |
237 |
237 |
238 (* Generic reification procedure: *) |
238 (* Generic reification procedure: *) |
275 val vars = th |> prop_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> snd |
275 val vars = th |> prop_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> snd |
276 |> strip_comb |> snd |> filter is_listVar |
276 |> strip_comb |> snd |> filter is_listVar |
277 val cert = cterm_of (Proof_Context.theory_of ctxt) |
277 val cert = cterm_of (Proof_Context.theory_of ctxt) |
278 val cvs = map (fn (v as Var(n,t)) => (cert v, |
278 val cvs = map (fn (v as Var(n,t)) => (cert v, |
279 the (AList.lookup Type.could_unify bds t) |> snd |> HOLogic.mk_list (dest_listT t) |> cert)) vars |
279 the (AList.lookup Type.could_unify bds t) |> snd |> HOLogic.mk_list (dest_listT t) |> cert)) vars |
280 val th' = instantiate ([], cvs) th |
280 val th' = Drule.instantiate_normalize ([], cvs) th |
281 val t' = (fst o HOLogic.dest_eq o HOLogic.dest_Trueprop o prop_of) th' |
281 val t' = (fst o HOLogic.dest_eq o HOLogic.dest_Trueprop o prop_of) th' |
282 val th'' = Goal.prove ctxt [] [] (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, t'))) |
282 val th'' = Goal.prove ctxt [] [] (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, t'))) |
283 (fn _ => simp_tac (simpset_of ctxt) 1) |
283 (fn _ => simp_tac (simpset_of ctxt) 1) |
284 in FWD trans [th'',th'] |
284 in FWD trans [th'',th'] |
285 end |
285 end |