-
Notifications
You must be signed in to change notification settings - Fork 135
feat: add Fin.any and Fin.all
#1435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,7 @@ theorem find?_succ {p : Fin (n+1) → Bool} : | |
| theorem find?_eq_some_iff {p : Fin n → Bool} : | ||
| find? p = some i ↔ p i ∧ ∀ j, j < i → p j = false := by simp [find?, and_assoc] | ||
|
|
||
| @[simp] | ||
| theorem isSome_find?_iff {p : Fin n → Bool} : | ||
| (find? p).isSome ↔ ∃ i, p i := by simp [find?] | ||
|
|
||
|
|
@@ -203,6 +204,33 @@ theorem exists_iff_exists_minimal (p : Fin n → Prop) [DecidablePred p] : | |
| simpa only [decide_eq_true_iff, decide_eq_false_iff_not] using | ||
| exists_eq_true_iff_exists_minimal_eq_true (p ·) | ||
|
|
||
| /-! ### any/all -/ | ||
|
|
||
| theorem any_eq_true_iff {p : Fin n → Bool} : Fin.any p = true ↔ ∃ i, p i = true := by simp | ||
|
|
||
| theorem any_eq_false_iff {p : Fin n → Bool} : Fin.any p = false ↔ ∀ i, p i = false := by simp | ||
|
|
||
| theorem any_eq_any_finRange {p : Fin n → Bool} : Fin.any p = (List.finRange n).any p := by | ||
| rw [Bool.eq_iff_iff] | ||
| simp only [Fin.any, find?_eq_find?_finRange, List.find?_isSome, List.any_eq, decide_eq_true_eq] | ||
|
|
||
| theorem all_eq_true_iff {p : Fin n → Bool} : Fin.all p = true ↔ ∀ i, p i = true := by simp | ||
|
|
||
| theorem all_eq_false_iff {p : Fin n → Bool} : Fin.all p = false ↔ ∃ i, p i = false := by simp | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So arguably we are missing some lemmas but you could argue they are covered by the fact this is just an abbrev. I would expect I also think you want something like
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about going a step further and have classes to standardize the basic API for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is an interesting idea. Arguably could do the same for things like |
||
| theorem all_eq_all_finRange {p : Fin n → Bool} : Fin.all p = (List.finRange n).all p := by | ||
| rw [Bool.eq_iff_iff] | ||
| simp only [Fin.all, find?_eq_find?_finRange, Option.isNone_iff_eq_none, List.find?_eq_none, | ||
| Bool.not_eq_eq_eq_not, Bool.not_true, Bool.not_eq_false, List.all_eq, decide_eq_true_eq] | ||
|
|
||
| -- The instance in Lean is not tail recursive and leads to stack overflow. | ||
| instance (p : Fin n → Prop) [DecidablePred p] : Decidable (∃ i, p i) := | ||
| decidable_of_iff (Fin.any (p ·) = true) (by simp) | ||
|
|
||
| -- The instance in Lean is not tail recursive and leads to stack overflow. | ||
| instance (p : Fin n → Prop) [DecidablePred p] : Decidable (∀ i, p i) := | ||
| decidable_of_iff (Fin.all (p ·) = true) (by simp) | ||
|
Comment on lines
+226
to
+232
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't these form instance diamonds with instances in mathlib? |
||
|
|
||
| /-! ### divNat / modNat / mkDivMod -/ | ||
|
|
||
| @[simp] theorem coe_divNat (i : Fin (m * n)) : (i.divNat : Nat) = i / n := rfl | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also consider simply
! any (! p ·).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potatoes/Tomatoes? I don't have a preference either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer using
all.