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 |
17 val expand_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 -> |
18 val expand_of_class : theory -> typ list -> term option list -> Proofterm.proof -> |
19 (Proofterm.proof * Proofterm.proof) option |
19 (Proofterm.proof * Proofterm.proof) option |
20 end; |
20 end; |
21 |
21 |
22 structure ProofRewriteRules : PROOF_REWRITE_RULES = |
22 structure ProofRewriteRules : PROOF_REWRITE_RULES = |
340 end; |
340 end; |
341 |
341 |
342 |
342 |
343 (**** expand OfClass proofs ****) |
343 (**** expand OfClass proofs ****) |
344 |
344 |
345 fun mk_of_sort_proof thy hs (T, S) = |
345 fun expand_of_sort_proof thy hyps (T, S) = |
346 let |
346 let |
347 val hs' = map |
347 val of_class_hyps = map (fn SOME t => try Logic.dest_of_class t | NONE => NONE) hyps; |
348 (fn SOME t => (SOME (Logic.dest_of_class t) handle TERM _ => NONE) |
348 fun of_class_index p = |
349 | NONE => NONE) hs; |
349 (case find_index (fn SOME h => h = p | NONE => false) of_class_hyps of |
350 val sorts = AList.coalesce (op =) (rev (map_filter I hs')); |
350 ~1 => raise Fail "expand_of_class_proof: missing class hypothesis" |
|
351 | i => PBound i); |
|
352 |
|
353 val sorts = AList.coalesce (op =) (rev (map_filter I of_class_hyps)); |
351 fun get_sort T = the_default [] (AList.lookup (op =) sorts T); |
354 fun get_sort T = the_default [] (AList.lookup (op =) sorts T); |
352 val subst = map_atyps |
355 val subst = map_atyps |
353 (fn T as TVar (ixn, _) => TVar (ixn, get_sort T) |
356 (fn T as TVar (ai, _) => TVar (ai, get_sort T) |
354 | T as TFree (s, _) => TFree (s, get_sort T)); |
357 | T as TFree (a, _) => TFree (a, get_sort T)); |
355 fun hyp T_c = case find_index (equal (SOME T_c)) hs' of |
358 |
356 ~1 => error "expand_of_class: missing class hypothesis" |
359 fun reconstruct prop = |
357 | i => PBound i; |
360 Proofterm.reconstruct_proof thy prop #> |
358 fun reconstruct prf prop = prf |> |
361 Proofterm.expand_proof thy [("", NONE)] #> |
359 Proofterm.reconstruct_proof thy prop |> |
362 Same.commit (Proofterm.map_proof_same Same.same Same.same of_class_index); |
360 Proofterm.expand_proof thy [("", NONE)] |> |
363 in |
361 Same.commit (Proofterm.map_proof_same Same.same Same.same hyp) |
364 map2 reconstruct (Logic.mk_of_sort (T, S)) |
362 in |
|
363 map2 reconstruct |
|
364 (Proofterm.of_sort_proof (Sign.classes_of thy) (Thm.classrel_proof thy) (Thm.arity_proof thy) |
365 (Proofterm.of_sort_proof (Sign.classes_of thy) (Thm.classrel_proof thy) (Thm.arity_proof thy) |
365 (OfClass o apfst Type.strip_sorts) (subst T, S)) |
366 (OfClass o apfst Type.strip_sorts) (subst T, S)) |
366 (Logic.mk_of_sort (T, S)) |
|
367 end; |
367 end; |
368 |
368 |
369 fun expand_of_class thy Ts hs (OfClass (T, c)) = |
369 fun expand_of_class thy (_: typ list) hs (OfClass (T, c)) = |
370 mk_of_sort_proof thy hs (T, [c]) |> |
370 SOME (expand_of_sort_proof thy hs (T, [c]) |> hd, Proofterm.no_skel) |
371 hd |> rpair Proofterm.no_skel |> SOME |
371 | expand_of_class _ _ _ _ = NONE; |
372 | expand_of_class thy Ts hs _ = NONE; |
|
373 |
372 |
374 end; |
373 end; |