# HG changeset patch # User berghofe # Date 1013001035 -3600 # Node ID 21486a0557d131947eafe25d0777168849739b9f # Parent 3905bc0e900201fa2f5b9bcd67a7357a6007b39b Added function could_unify to speed up rewriting of proof terms. diff -r 3905bc0e9002 -r 21486a0557d1 src/Pure/proofterm.ML --- a/src/Pure/proofterm.ML Wed Feb 06 14:09:55 2002 +0100 +++ b/src/Pure/proofterm.ML Wed Feb 06 14:10:35 2002 +0100 @@ -975,6 +975,35 @@ | subst _ _ t = t in subst 0 0 end; +(*A fast unification filter: true unless the two terms cannot be unified. + Terms must be NORMAL. Treats all Vars as distinct. *) +fun could_unify prf1 prf2 = + let + fun matchrands (prf1 %% prf2) (prf1' %% prf2') = + could_unify prf2 prf2' andalso matchrands prf1 prf1' + | matchrands (prf % Some t) (prf' % Some t') = + Term.could_unify (t, t') andalso matchrands prf prf' + | matchrands (prf % _) (prf' % _) = matchrands prf prf' + | matchrands _ _ = true + + fun head_of (prf %% _) = head_of prf + | head_of (prf % _) = head_of prf + | head_of prf = prf + + in case (head_of prf1, head_of prf2) of + (_, Hyp (Var _)) => true + | (Hyp (Var _), _) => true + | (PThm ((a, _), _, propa, _), PThm ((b, _), _, propb, _)) => + a = b andalso propa = propb andalso matchrands prf1 prf2 + | (PAxm (a, _, _), PAxm (b, _, _)) => a = b andalso matchrands prf1 prf2 + | (PBound i, PBound j) => i = j andalso matchrands prf1 prf2 + | (AbsP _, _) => true (*because of possible eta equality*) + | (Abst _, _) => true + | (_, AbsP _) => true + | (_, Abst _) => true + | _ => false + end; + (**** rewriting on proof terms ****) fun rewrite_prf tymatch (rules, procs) prf = @@ -985,7 +1014,7 @@ Some prf' => Some prf' | None => get_first (fn (prf1, prf2) => Some (prf_subst (match_proof Ts tymatch ([], (Vartab.empty, [])) (prf1, prf)) prf2) - handle PMatch => None) rules); + handle PMatch => None) (filter (could_unify prf o fst) rules)); fun rew0 Ts (prf as AbsP (_, _, prf' %% PBound 0)) = if prf_loose_Pbvar1 prf' 0 then rew Ts prf