Skip to content

Commit 3466950

Browse files
committed
chore: cleanup grind palindrome test
1 parent 398d9a6 commit 3466950

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
set_option grind.warning false
2+
3+
def IsPalindrome (xs : Array Nat) : Prop := xs.reverse = xs
4+
5+
def checkPalin1 (xs : Array Nat) : Bool :=
6+
go 0
7+
where
8+
go (i : Nat) :=
9+
if h : i < xs.size / 2 then
10+
if xs[i] = xs[xs.size - 1 - i] then
11+
go (i + 1)
12+
else
13+
false
14+
else
15+
true
16+
17+
-- This give the more natural proof that we'd like to give in `tests/run/grind_palindrome2.lean`,
18+
-- but in which `grind` currently fails.
19+
20+
theorem checkPalin1_correct' : checkPalin1 xs = true ↔ IsPalindrome xs := by
21+
unfold checkPalin1
22+
suffices ∀ i, checkPalin1.go xs i = true ↔ ∀ j, i ≤ j → (_ : j < xs.size - i) → xs[j] = xs[xs.size - 1 - j] by
23+
grind [IsPalindrome]
24+
intro i
25+
fun_induction checkPalin1.go
26+
· grind (splits := 14)
27+
-- fails, but it would be nice to succeed! The key observations are:
28+
-- [eqc] True propositions ▼
29+
-- [prop] ∀ (a : Nat) (b : a + 1 ≤ xs.toList.length - x), a + 1 ≤ x ∨ xs[a] = xs[xs.toList.length - (a + 1)]
30+
-- [eqc] False propositions ▼
31+
-- [prop] xs[x] = xs[xs.toList.length - (x + 1)]
32+
-- Instantiating the `∀` with `a := x`, we can then easily prove `a + 1 ≤ xs.toList.length - x` and
33+
-- prove that it's not the case that `a + 1 ≤ x`, so we get `xs[x] = xs[xs.toList.length - (x + 1)]`,
34+
-- which is false.
35+
· grind
36+
-- The same argument should apply here.
37+
· grind

0 commit comments

Comments
 (0)