lean4-htt/tests/lean/grind/grind_palindrome.lean
Kim Morrison eccc472e8d
chore: remove set_option grind.warning false (#8714)
This PR removes the now unnecessary `set_option grind.warning false`
statements, now that the warning is disabled by default.
2025-06-11 05:09:19 +00:00

35 lines
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def IsPalindrome (xs : Array Nat) : Prop := xs.reverse = xs
def checkPalin1 (xs : Array Nat) : Bool :=
go 0
where
go (i : Nat) :=
if h : i < xs.size / 2 then
if xs[i] = xs[xs.size - 1 - i] then
go (i + 1)
else
false
else
true
-- This give the more natural proof that we'd like to give in `tests/run/grind_palindrome2.lean`,
-- but in which `grind` currently fails.
theorem checkPalin1_correct' : checkPalin1 xs = true ↔ IsPalindrome xs := by
unfold checkPalin1
suffices ∀ i, checkPalin1.go xs i = true ↔ ∀ j, i ≤ j → (_ : j < xs.size - i) → xs[j] = xs[xs.size - 1 - j] by
grind [IsPalindrome]
intro i
fun_induction checkPalin1.go
· grind (splits := 14)
-- fails, but it would be nice to succeed! The key observations are:
-- [eqc] True propositions ▼
-- [prop] ∀ (a : Nat) (b : a + 1 ≤ xs.toList.length - x), a + 1 ≤ x xs[a] = xs[xs.toList.length - (a + 1)]
-- [eqc] False propositions ▼
-- [prop] xs[x] = xs[xs.toList.length - (x + 1)]
-- Instantiating the `∀` with `a := x`, we can then easily prove `a + 1 ≤ xs.toList.length - x` and
-- prove that it's not the case that `a + 1 ≤ x`, so we get `xs[x] = xs[xs.toList.length - (x + 1)]`,
-- which is false.
· grind
-- The same argument should apply here.
· grind