lean4-htt/tests/lean/run/grind_option.lean
Kim Morrison 3dd12f85f0
feat: further @[grind] annotations for Option (#8460)
This PR adds further `@[grind]` annotations for `Option`, as follow-up
to the recent additions to the `Option` API in #8379 and #8298.

**However**, I am concurrently investigating adding `attribute [grind
cases] Option`, which will result in many (most?) of the annotations for
`Option` being removed again. In any case, I'm going to merge this
first, as if that is viable I would like to test that most/all the
lemmas now marked with `@[grind]` are still provable by `grind`.
2025-05-24 04:25:00 +00:00

59 lines
1.9 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.

-- This file uses `#guard_msgs` to check which lemmas `grind` is using.
-- This may prove fragile, so remember it is okay to update the expected output if appropriate!
-- Hopefully these will act as regression tests against `grind` activating irrelevant lemmas.
set_option grind.warning false
section
variable [BEq α] {o₁ o₂ o₃ o₄ o₅ : Option α}
/--
info: Try this: grind only [Option.or_some, Option.some_or, Option.or_assoc, Option.some_beq_none]
-/
#guard_msgs in
example : ((o₁.or (o₂.or (some x))).or (o₄.or o₅) == none) = false := by grind?
/-- info: Try this: grind only [Option.max_none_right, = Nat.min_def, Option.min_some_some] -/
#guard_msgs in
example : max (some 7) none = min (some 13) (some 7) := by grind?
/-- info: Try this: grind only [Option.guard_def] -/
#guard_msgs in
example : Option.guard (· ≤ 7) 3 = some 3 := by grind?
/-- info: Try this: grind only [Option.mem_bind_iff] -/
#guard_msgs in
example {x : β} {o : Option α} {f : α → Option β} (h : a ∈ o) (h' : x ∈ f a) : x ∈ o.bind f := by grind?
end
open Option
theorem toList_toArray {o : Option α} : o.toArray.toList = o.toList := by
grind
theorem toArray_toList {o : Option α} : o.toList.toArray = o.toArray := by
grind
theorem size_toArray_eq_one_iff {o : Option α} :
o.toArray.size = 1 ↔ o.isSome := by
grind
theorem size_toArray_choice_eq_one [Nonempty α] : (choice α).toArray.size = 1 := by
grind
theorem length_toList_eq_one_iff {o : Option α} :
o.toList.length = 1 ↔ o.isSome := by
grind
theorem length_toList_choice_eq_one [Nonempty α] : (choice α).toList.length = 1 := by
grind
example : (default : Option α) = none := by grind
example (a : α) : Option.all q (guard p a) = (!p a || q a) := by grind
example (a : α) : Option.any q (guard p a) = (p a && q a) := by grind
example : (guard p a).or (guard q a) = guard (fun x => p x || q x) a := by grind