Compare commits

...

5 Commits

Author SHA1 Message Date
Leonardo de Moura
4229f23ac8 chore: fix test 2025-05-15 11:12:55 -07:00
Kim Morrison
3641f09223 Update tests/lean/run/grind_eta.lean 2025-05-15 10:47:20 -07:00
Kim Morrison
d141606e82 fix tests 2025-05-15 10:47:18 -07:00
Leonardo de Moura
6a2c956ea5 test: eta 2025-05-15 10:46:28 -07:00
Leonardo de Moura
760a80ee6c feat: eta reduction in grind 2025-05-15 10:46:25 -07:00
4 changed files with 33 additions and 4 deletions

View File

@@ -283,6 +283,17 @@ private def addSplitCandidatesForFunext (arg : Expr) (generation : Nat) (parent?
unless ( getConfig).funext do return ()
addSplitCandidatesForExt arg generation parent?
/--
Tries to eta-reduce the given expression.
If successful, pushes a new equality between the two terms.
-/
private def tryEta (e : Expr) (generation : Nat) : GoalM Unit := do
let e' := e.eta
if e != e' then
let e' shareCommon e'
internalize e' generation
pushEq e e' ( mkEqRefl e)
@[export lean_grind_internalize]
private partial def internalizeImpl (e : Expr) (generation : Nat) (parent? : Option Expr := none) : GoalM Unit := withIncRecDepth do
if ( alreadyInternalized e) then
@@ -313,6 +324,7 @@ where
| .lam .. =>
addSplitCandidatesForFunext e generation parent?
mkENode' e generation
tryEta e generation
| .forallE _ d b _ =>
mkENode' e generation
internalizeImpl d generation e

View File

@@ -30,8 +30,8 @@ example (f : Nat → Nat → Nat) : f 2 3 ≠ 5 → f = (fun x y : Nat => x + y)
opaque bla : Nat Nat Nat Nat
/--
trace: [grind.beta] f 2 3 = bla 2 3 2, using fun x y => bla x y x
[grind.beta] f 2 3 = 2 + 3, using fun x y => x + y
trace: [grind.beta] f 2 3 = 2 + 3, using fun x y => x + y
[grind.beta] f 2 3 = bla 2 3 2, using fun x y => bla x y x
-/
#guard_msgs (trace) in
set_option trace.grind.beta true in

View File

@@ -0,0 +1,15 @@
reset_grind_attrs%
set_option grind.warning false
example {l : List α} {f : β α β} {b : β} :
l.foldl f b = l.reverse.foldr (fun x y => f y x) b := by
grind [List.foldr_reverse]
/-
The following example doesn't work yet. `grind` doesn't have a mechanism
for inferring that `fun x y => g y x` is equal to `f` given
the equality `g = (f x y => f y x)`
-/
-- example {l : List α} {f : β → α → β} {b : β} :
-- g = (fun x y => f y x) → l.foldl f b = l.reverse.foldr g b := by
-- grind [List.foldr_reverse]

View File

@@ -4,8 +4,10 @@ example (f : (Nat → Nat) → Nat → Nat → Nat) : a = b → f (fun x => a +
grind
example (f : (Nat Nat) Nat) : a = b f (fun x => a + x) = f (fun x => b + x) := by
fail_if_success grind -funext
sorry
-- This test used to check `fail_if_success grind -funext`,
-- but now it succeeds even without funext
-- due to adding the eta rule in https://github.com/leanprover/lean4/pull/7977.
grind
example (g : Nat Nat Nat) (f : (Nat Nat) Nat (Nat Nat) Nat) :
a = b f (fun x => a + x) 1 (fun x => g x a) = f (fun x => x + b) 1 (fun x => g x b) := by