-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: equality resolution for
grind
(#6663)
This PR implements a basic equality resolution procedure for the `grind` tactic.
- Loading branch information
1 parent
906aa1b
commit e42f7d9
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/- | ||
Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
prelude | ||
import Lean.Meta.AppBuilder | ||
|
||
namespace Lean.Meta.Grind | ||
/-! | ||
A basic "equality resolution" procedure to make Kim happy. | ||
-/ | ||
|
||
private def eqResCore (prop proof : Expr) : MetaM (Option (Expr × Expr)) := withNewMCtxDepth do | ||
let (ms, _, type) ← forallMetaTelescopeReducing prop | ||
if ms.isEmpty then return none | ||
let mut progress := false | ||
for m in ms do | ||
let type ← inferType m | ||
let_expr Eq _ lhs rhs ← type | ||
| pure () | ||
if (← isDefEq lhs rhs) then | ||
unless (← m.mvarId!.checkedAssign (← mkEqRefl lhs)) do | ||
return none | ||
progress := true | ||
unless progress do | ||
return none | ||
if (← ms.anyM fun m => m.mvarId!.isDelayedAssigned) then | ||
return none | ||
let prop' ← instantiateMVars type | ||
let proof' ← instantiateMVars (mkAppN proof ms) | ||
let ms ← ms.filterM fun m => return !(← m.mvarId!.isAssigned) | ||
let prop' ← mkForallFVars ms prop' (binderInfoForMVars := .default) | ||
let proof' ← mkLambdaFVars ms proof' | ||
return some (prop', proof') | ||
|
||
/-- | ||
A basic "equality resolution" procedure: Given a proposition `prop` with a proof `proof`, it attempts to resolve equality hypotheses using `isDefEq`. For example, it reduces `∀ x y, f x = f (g y y) → g x y = y` to `∀ y, g (g y y) y = y`, and `∀ (x : Nat), f x ≠ f a` to `False`. | ||
If successful, the result is a pair `(prop', proof)`, where `prop'` is the simplified proposition, | ||
and `proof : prop → prop'` | ||
-/ | ||
def eqResolution (prop : Expr) : MetaM (Option (Expr × Expr)) := | ||
withLocalDeclD `h prop fun h => do | ||
let some (prop', proof') ← eqResCore prop h | ||
| return none | ||
let proof' ← mkLambdaFVars #[h] proof' | ||
return some (prop', proof') | ||
|
||
end Lean.Meta.Grind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters