4 Simplification functions for proof terms involving meta level rules. |
4 Simplification functions for proof terms involving meta level rules. |
5 *) |
5 *) |
6 |
6 |
7 signature PROOF_REWRITE_RULES = |
7 signature PROOF_REWRITE_RULES = |
8 sig |
8 sig |
9 val rew : bool -> typ list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option |
9 val rew : bool -> typ list -> term option list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option |
10 val rprocs : bool -> |
10 val rprocs : bool -> |
11 (typ list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option) list |
11 (typ list -> term option list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option) list |
12 val rewrite_terms : (term -> term) -> Proofterm.proof -> Proofterm.proof |
12 val rewrite_terms : (term -> term) -> Proofterm.proof -> Proofterm.proof |
13 val elim_defs : theory -> bool -> thm list -> Proofterm.proof -> Proofterm.proof |
13 val elim_defs : theory -> bool -> thm list -> Proofterm.proof -> Proofterm.proof |
14 val elim_vars : (typ -> term) -> Proofterm.proof -> Proofterm.proof |
14 val elim_vars : (typ -> term) -> Proofterm.proof -> Proofterm.proof |
15 val hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof |
15 val hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof |
16 val un_hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof |
16 val un_hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof |
|
17 val mk_of_sort_proof : theory -> term option list -> typ * sort -> Proofterm.proof list |
|
18 val expand_of_class : theory -> typ list -> term option list -> Proofterm.proof -> |
|
19 (Proofterm.proof * Proofterm.proof) option |
17 end; |
20 end; |
18 |
21 |
19 structure ProofRewriteRules : PROOF_REWRITE_RULES = |
22 structure ProofRewriteRules : PROOF_REWRITE_RULES = |
20 struct |
23 struct |
21 |
24 |
22 open Proofterm; |
25 open Proofterm; |
23 |
26 |
24 fun rew b _ = |
27 fun rew b _ _ = |
25 let |
28 let |
26 fun ?? x = if b then SOME x else NONE; |
29 fun ?? x = if b then SOME x else NONE; |
27 fun ax (prf as PAxm (s, prop, _)) Ts = |
30 fun ax (prf as PAxm (s, prop, _)) Ts = |
28 if b then PAxm (s, prop, SOME Ts) else prf; |
31 if b then PAxm (s, prop, SOME Ts) else prf; |
29 fun ty T = if b then |
32 fun ty T = if b then |
217 (**** eliminate definitions in proof ****) |
220 (**** eliminate definitions in proof ****) |
218 |
221 |
219 fun vars_of t = rev (fold_aterms (fn v as Var _ => insert (op =) v | _ => I) t []); |
222 fun vars_of t = rev (fold_aterms (fn v as Var _ => insert (op =) v | _ => I) t []); |
220 |
223 |
221 fun insert_refl defs Ts (prf1 %% prf2) = |
224 fun insert_refl defs Ts (prf1 %% prf2) = |
222 insert_refl defs Ts prf1 %% insert_refl defs Ts prf2 |
225 let val (prf1', b) = insert_refl defs Ts prf1 |
|
226 in |
|
227 if b then (prf1', true) |
|
228 else (prf1' %% fst (insert_refl defs Ts prf2), false) |
|
229 end |
223 | insert_refl defs Ts (Abst (s, SOME T, prf)) = |
230 | insert_refl defs Ts (Abst (s, SOME T, prf)) = |
224 Abst (s, SOME T, insert_refl defs (T :: Ts) prf) |
231 (Abst (s, SOME T, fst (insert_refl defs (T :: Ts) prf)), false) |
225 | insert_refl defs Ts (AbsP (s, t, prf)) = |
232 | insert_refl defs Ts (AbsP (s, t, prf)) = |
226 AbsP (s, t, insert_refl defs Ts prf) |
233 (AbsP (s, t, fst (insert_refl defs Ts prf)), false) |
227 | insert_refl defs Ts prf = (case strip_combt prf of |
234 | insert_refl defs Ts prf = (case strip_combt prf of |
228 (PThm (_, ((s, prop, SOME Ts), _)), ts) => |
235 (PThm (_, ((s, prop, SOME Ts), _)), ts) => |
229 if member (op =) defs s then |
236 if member (op =) defs s then |
230 let |
237 let |
231 val vs = vars_of prop; |
238 val vs = vars_of prop; |
232 val tvars = Term.add_tvars prop [] |> rev; |
239 val tvars = Term.add_tvars prop [] |> rev; |
233 val (_, rhs) = Logic.dest_equals prop; |
240 val (_, rhs) = Logic.dest_equals (Logic.strip_imp_concl prop); |
234 val rhs' = Term.betapplys (subst_TVars (map fst tvars ~~ Ts) |
241 val rhs' = Term.betapplys (subst_TVars (map fst tvars ~~ Ts) |
235 (fold_rev (fn x => fn b => Abs ("", dummyT, abstract_over (x, b))) vs rhs), |
242 (fold_rev (fn x => fn b => Abs ("", dummyT, abstract_over (x, b))) vs rhs), |
236 map the ts); |
243 map the ts); |
237 in |
244 in |
238 change_type (SOME [fastype_of1 (Ts, rhs')]) reflexive_axm %> rhs' |
245 (change_type (SOME [fastype_of1 (Ts, rhs')]) reflexive_axm %> rhs', true) |
239 end |
246 end |
240 else prf |
247 else (prf, false) |
241 | (_, []) => prf |
248 | (_, []) => (prf, false) |
242 | (prf', ts) => proof_combt' (insert_refl defs Ts prf', ts)); |
249 | (prf', ts) => (proof_combt' (fst (insert_refl defs Ts prf'), ts), false)); |
243 |
250 |
244 fun elim_defs thy r defs prf = |
251 fun elim_defs thy r defs prf = |
245 let |
252 let |
246 val defs' = map (Logic.dest_equals o prop_of o Drule.abs_def) defs |
253 val defs' = map (Logic.dest_equals o |
|
254 map_types Type.strip_sorts o prop_of o Drule.abs_def) defs; |
247 val defnames = map Thm.derivation_name defs; |
255 val defnames = map Thm.derivation_name defs; |
248 val f = if not r then I else |
256 val f = if not r then I else |
249 let |
257 let |
250 val cnames = map (fst o dest_Const o fst) defs'; |
258 val cnames = map (fst o dest_Const o fst) defs'; |
251 val thms = fold_proof_atoms true |
259 val thms = fold_proof_atoms true |
325 fold (fn ((H, H'), i) => fn prf => prf %% hhf_proof H' H (PBound i)) |
333 fold (fn ((H, H'), i) => fn prf => prf %% hhf_proof H' H (PBound i)) |
326 (Hs ~~ Hs' ~~ (k - 1 downto 0)) |> |
334 (Hs ~~ Hs' ~~ (k - 1 downto 0)) |> |
327 mk_prf Q |
335 mk_prf Q |
328 end; |
336 end; |
329 |
337 |
|
338 |
|
339 (**** expand OfClass proofs ****) |
|
340 |
|
341 fun mk_of_sort_proof thy hs (T, S) = |
|
342 let |
|
343 val hs' = map |
|
344 (fn SOME t => (SOME (Logic.dest_of_class t) handle TERM _ => NONE) |
|
345 | NONE => NONE) hs; |
|
346 val sorts = AList.coalesce (op =) (rev (map_filter I hs')); |
|
347 fun get_sort T = the_default [] (AList.lookup (op =) sorts T); |
|
348 val subst = map_atyps |
|
349 (fn T as TVar (ixn, _) => TVar (ixn, get_sort T) |
|
350 | T as TFree (s, _) => TFree (s, get_sort T)); |
|
351 fun hyp T_c = case find_index (equal (SOME T_c)) hs' of |
|
352 ~1 => error "expand_of_class: missing class hypothesis" |
|
353 | i => PBound i; |
|
354 fun reconstruct prf prop = prf |> |
|
355 Reconstruct.reconstruct_proof thy prop |> |
|
356 Reconstruct.expand_proof thy [("", NONE)] |> |
|
357 Same.commit (map_proof_same Same.same Same.same hyp) |
|
358 in |
|
359 map2 reconstruct |
|
360 (of_sort_proof thy (OfClass o apfst Type.strip_sorts) (subst T, S)) |
|
361 (Logic.mk_of_sort (T, S)) |
|
362 end; |
|
363 |
|
364 fun expand_of_class thy Ts hs (OfClass (T, c)) = |
|
365 mk_of_sort_proof thy hs (T, [c]) |> |
|
366 hd |> rpair no_skel |> SOME |
|
367 | expand_of_class thy Ts hs _ = NONE; |
|
368 |
330 end; |
369 end; |