Skip to content

Commit 88f6439

Browse files
authored
fix: case-splitting in grind (#8410)
This PR fixes a case-splitting heuristic in `grind` and simplifies the proof for test `grind_palindrome2.lean`.
1 parent fc8f290 commit 88f6439

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/Lean/Meta/Tactic/Grind/Internalize.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ private def checkAndAddSplitCandidate (e : Expr) : GoalM Unit := do
102102
if (← isProp d) then
103103
addSplitCandidate (.imp e (h ▸ rfl))
104104
else if Arith.isRelevantPred d then
105+
-- TODO: should we keep lookahead after we implement non-chronological backtracking?
105106
if (← getConfig).lookahead then
106107
addLookaheadCandidate (.imp e (h ▸ rfl))
107-
else
108-
addSplitCandidate (.imp e (h ▸ rfl))
108+
-- We used to add the `split` only if `lookahead := false`, but it was counterintuitive
109+
-- to make `grind` "stronger" by disabling a feature.
110+
addSplitCandidate (.imp e (h ▸ rfl))
109111
| _ => pure ()
110112

111113
/--

tests/lean/run/grind_palindrome2.lean

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,17 @@ example (xs : Array Nat) (w : xs.reverse = xs) (j : Nat) (hj : 0 ≤ j) (hj' : j
2121
theorem checkPalin1_correct' : checkPalin1 xs = true ↔ IsPalindrome xs := by
2222
unfold checkPalin1
2323
suffices ∀ i, checkPalin1.go xs i = true ↔ ∀ j, i ≤ j → (_ : j < xs.size / 2) → xs[j] = xs[xs.size - 1 - j] by
24-
rw [this, IsPalindrome]
25-
constructor
26-
· intro w
27-
ext i hi₁ hi₂
28-
· grind
29-
· by_cases h : i < xs.size / 2 <;> grind
30-
· intro w
31-
intro j hj hj'
32-
grind
24+
-- We need array extensionality. TODO: easy way to enable array extensionality, `extAll` enables all [ext] theorems
25+
-- TODO: `IsPalindrome` (without `.eq_1`) produces bad error message.
26+
grind +extAll [IsPalindrome.eq_1]
3327
intro i
3428
fun_induction checkPalin1.go
3529
case case1 j h₁ h₂ ih =>
36-
constructor
37-
· intro w j'
38-
by_cases j' = j <;> grind
39-
· grind
30+
-- TODO: make sure we don't need `constructor` here. This is a normalization issue.
31+
constructor <;> grind
4032
case case2 j h₁ h₂ =>
33+
-- TODO: fix normalization
4134
simp only [Bool.false_eq_true, false_iff, Classical.not_forall]
42-
refine ⟨j, by grind
35+
grind
4336
case case3 x h =>
4437
grind

0 commit comments

Comments
 (0)