lean4-htt/tests/lean/grind/experiments/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

44 lines
1.5 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.

open Option
set_option grind.warning false
-- TODO: the following lemmas currently fail, but could be solved with some subset of the following attributes:
-- I haven't added them yet, because the nuclear option of `[grind cases]` is tempting, but a bit scary.
attribute [grind] Option.eq_none_of_isNone
attribute [grind] Option.toArray_eq_empty_iff
attribute [grind] Option.toList_eq_nil_iff
attribute [grind cases] Option
theorem toArray_eq_empty_iff {o : Option α} : o.toArray = #[] ↔ o = none := by
grind
theorem toArray_eq_singleton_iff {o : Option α} : o.toArray = #[a] ↔ o = some a := by
grind
theorem size_toArray_eq_zero_iff {o : Option α} :
o.toArray.size = 0 ↔ o = none := by
grind
theorem toList_eq_nil_iff {o : Option α} : o.toList = [] ↔ o = none := by
grind
theorem toList_eq_singleton_iff {o : Option α} : o.toList = [a] ↔ o = some a := by
grind
theorem length_toList_eq_zero_iff {o : Option α} :
o.toList.length = 0 ↔ o = none := by
grind
attribute [grind] Std.IdempotentOp -- Lots more of these!
example [Max α] [Std.IdempotentOp (α := α) max] {p : α → Bool} {o : Option α} :
max (o.filter p) o = o := by grind
example [Max α] [Std.IdempotentOp (α := α) max] {o : Option α} {p : (a : α) → o = some a → Bool} :
max (o.pfilter p) o = o := by grind
example [Max α] {o o' : Option α} : (max o o').isSome = (o.isSome || o'.isSome) := by grind
example [Max α] {o o' : Option (Option α)} : (max o o').join = max o.join o'.join := by grind