src/HOL/Tools/rewrite_hol_proof.ML
changeset 37310 96e2b9a6f074
parent 37233 b78f31ca4675
child 59058 a78612c67ec0
equal deleted inserted replaced
37309:38ce84c83738 37310:96e2b9a6f074
    10   val elim_cong: typ list -> term option list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option
    10   val elim_cong: typ list -> term option list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option
    11 end;
    11 end;
    12 
    12 
    13 structure RewriteHOLProof : REWRITE_HOL_PROOF =
    13 structure RewriteHOLProof : REWRITE_HOL_PROOF =
    14 struct
    14 struct
    15 
       
    16 open Proofterm;
       
    17 
    15 
    18 val rews = map (pairself (Proof_Syntax.proof_of_term @{theory} true) o
    16 val rews = map (pairself (Proof_Syntax.proof_of_term @{theory} true) o
    19     Logic.dest_equals o Logic.varify_global o Proof_Syntax.read_term @{theory} true propT)
    17     Logic.dest_equals o Logic.varify_global o Proof_Syntax.read_term @{theory} true propT)
    20 
    18 
    21   (** eliminate meta-equality rules **)
    19   (** eliminate meta-equality rules **)
   309 fun strip_cong ps (PThm (_, (("HOL.cong", _, _), _)) % _ % _ % SOME x % SOME y %%
   307 fun strip_cong ps (PThm (_, (("HOL.cong", _, _), _)) % _ % _ % SOME x % SOME y %%
   310       prfa %% prfT %% prf1 %% prf2) = strip_cong (((x, y), (prf2, prfa)) :: ps) prf1
   308       prfa %% prfT %% prf1 %% prf2) = strip_cong (((x, y), (prf2, prfa)) :: ps) prf1
   311   | strip_cong ps (PThm (_, (("HOL.refl", _, _), _)) % SOME f %% _) = SOME (f, ps)
   309   | strip_cong ps (PThm (_, (("HOL.refl", _, _), _)) % SOME f %% _) = SOME (f, ps)
   312   | strip_cong _ _ = NONE;
   310   | strip_cong _ _ = NONE;
   313 
   311 
   314 val subst_prf = fst (strip_combt (fst (strip_combP (Thm.proof_of subst))));
   312 val subst_prf = fst (Proofterm.strip_combt (fst (Proofterm.strip_combP (Thm.proof_of subst))));
   315 val sym_prf = fst (strip_combt (fst (strip_combP (Thm.proof_of sym))));
   313 val sym_prf = fst (Proofterm.strip_combt (fst (Proofterm.strip_combP (Thm.proof_of sym))));
   316 
   314 
   317 fun make_subst Ts prf xs (_, []) = prf
   315 fun make_subst Ts prf xs (_, []) = prf
   318   | make_subst Ts prf xs (f, ((x, y), (prf', clprf)) :: ps) =
   316   | make_subst Ts prf xs (f, ((x, y), (prf', clprf)) :: ps) =
   319       let val T = fastype_of1 (Ts, x)
   317       let val T = fastype_of1 (Ts, x)
   320       in if x aconv y then make_subst Ts prf (xs @ [x]) (f, ps)
   318       in if x aconv y then make_subst Ts prf (xs @ [x]) (f, ps)
   321         else change_type (SOME [T]) subst_prf %> x %> y %>
   319         else Proofterm.change_type (SOME [T]) subst_prf %> x %> y %>
   322           Abs ("z", T, list_comb (incr_boundvars 1 f,
   320           Abs ("z", T, list_comb (incr_boundvars 1 f,
   323             map (incr_boundvars 1) xs @ Bound 0 ::
   321             map (incr_boundvars 1) xs @ Bound 0 ::
   324             map (incr_boundvars 1 o snd o fst) ps)) %% clprf %% prf' %%
   322             map (incr_boundvars 1 o snd o fst) ps)) %% clprf %% prf' %%
   325           make_subst Ts prf (xs @ [x]) (f, ps)
   323           make_subst Ts prf (xs @ [x]) (f, ps)
   326       end;
   324       end;
   327 
   325 
   328 fun make_sym Ts ((x, y), (prf, clprf)) =
   326 fun make_sym Ts ((x, y), (prf, clprf)) =
   329   ((y, x), (change_type (SOME [fastype_of1 (Ts, x)]) sym_prf %> x %> y %% clprf %% prf, clprf));
   327   ((y, x),
       
   328     (Proofterm.change_type (SOME [fastype_of1 (Ts, x)]) sym_prf %> x %> y %% clprf %% prf, clprf));
   330 
   329 
   331 fun mk_AbsP P t = AbsP ("H", Option.map HOLogic.mk_Trueprop P, t);
   330 fun mk_AbsP P t = AbsP ("H", Option.map HOLogic.mk_Trueprop P, t);
   332 
   331 
   333 fun elim_cong_aux Ts (PThm (_, (("HOL.iffD1", _, _), _)) % _ % _ %% prf1 %% prf2) =
   332 fun elim_cong_aux Ts (PThm (_, (("HOL.iffD1", _, _), _)) % _ % _ %% prf1 %% prf2) =
   334       Option.map (make_subst Ts prf2 []) (strip_cong [] prf1)
   333       Option.map (make_subst Ts prf2 []) (strip_cong [] prf1)
   335   | elim_cong_aux Ts (PThm (_, (("HOL.iffD1", _, _), _)) % P % _ %% prf) =
   334   | elim_cong_aux Ts (PThm (_, (("HOL.iffD1", _, _), _)) % P % _ %% prf) =
   336       Option.map (mk_AbsP P o make_subst Ts (PBound 0) [])
   335       Option.map (mk_AbsP P o make_subst Ts (PBound 0) [])
   337         (strip_cong [] (incr_pboundvars 1 0 prf))
   336         (strip_cong [] (Proofterm.incr_pboundvars 1 0 prf))
   338   | elim_cong_aux Ts (PThm (_, (("HOL.iffD2", _, _), _)) % _ % _ %% prf1 %% prf2) =
   337   | elim_cong_aux Ts (PThm (_, (("HOL.iffD2", _, _), _)) % _ % _ %% prf1 %% prf2) =
   339       Option.map (make_subst Ts prf2 [] o
   338       Option.map (make_subst Ts prf2 [] o
   340         apsnd (map (make_sym Ts))) (strip_cong [] prf1)
   339         apsnd (map (make_sym Ts))) (strip_cong [] prf1)
   341   | elim_cong_aux Ts (PThm (_, (("HOL.iffD2", _, _), _)) % _ % P %% prf) =
   340   | elim_cong_aux Ts (PThm (_, (("HOL.iffD2", _, _), _)) % _ % P %% prf) =
   342       Option.map (mk_AbsP P o make_subst Ts (PBound 0) [] o
   341       Option.map (mk_AbsP P o make_subst Ts (PBound 0) [] o
   343         apsnd (map (make_sym Ts))) (strip_cong [] (incr_pboundvars 1 0 prf))
   342         apsnd (map (make_sym Ts))) (strip_cong [] (Proofterm.incr_pboundvars 1 0 prf))
   344   | elim_cong_aux _ _ = NONE;
   343   | elim_cong_aux _ _ = NONE;
   345 
   344 
   346 fun elim_cong Ts hs prf = Option.map (rpair no_skel) (elim_cong_aux Ts prf);
   345 fun elim_cong Ts hs prf = Option.map (rpair Proofterm.no_skel) (elim_cong_aux Ts prf);
   347 
   346 
   348 end;
   347 end;