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
feat: List.forall_get_iff_forall_mem
#682
base: main
Are you sure you want to change the base?
feat: List.forall_get_iff_forall_mem
#682
Conversation
awaiting-review |
I usually obtain the headline theorem using |
5d6ae00
to
7db45bd
Compare
Sorry I didn't find this theorem. Now other stuff has been removed. |
7db45bd
to
1cc3c1f
Compare
1cc3c1f
to
a343175
Compare
e01530a
to
1c3f2b1
Compare
Std/Data/List/Lemmas.lean
Outdated
theorem forall_mem_iff_forall_index {p : α → Prop} {l : List α} : | ||
(∀ x ∈ l, p x) ↔ (∀ i : Fin (l.length), p (l.get i)) := | ||
⟨fun h i => h _ (get_mem l i.1 i.2), | ||
fun h _ hx => by have ⟨_, hi⟩ := mem_iff_get.mp hx; simp only [← hi, h]⟩ | ||
|
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.
theorem forall_mem_iff_forall_index {p : α → Prop} {l : List α} : | |
(∀ x ∈ l, p x) ↔ (∀ i : Fin (l.length), p (l.get i)) := | |
⟨fun h i => h _ (get_mem l i.1 i.2), | |
fun h _ hx => by have ⟨_, hi⟩ := mem_iff_get.mp hx; simp only [← hi, h]⟩ | |
theorem forall_mem_iff_forall_index {p : α → Prop} {l : List α} : | |
(∀ x ∈ l, p x) ↔ (∀ i : Fin (l.length), p (l.get i)) := by | |
simp [List.mem_iff_get] | |
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.
What is the use case of this theorem?
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.
What is the use case of this theorem?
Sometimes some propositions of List
are expressed in indexed form, especially when translating algorithm proof from CS books.
I struggled with it for hours and it's until this issue then I know the existence of List.mem_iff_get
which derives this theorem. Without it there may be someone else facing the same trouble again.
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.
Sorry about the slow reply here. Let's reverse the iff
, rename to forall_get_iff_forall_mem
, and maybe even mark this as @[simp]
.
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.
Done.
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 it shouldn't be @[simp]
; this will not fire reliably anyway (only the RTL direction looks like it would match), and whether it is better to use indexing or membership in a given context is very dependent on other factors.
74b07fe
to
84fb7eb
Compare
84fb7eb
to
ddbfca4
Compare
List.forall_mem_iff_forall_index
List.forall_get_iff_forall_mem
is trivial but sometimes useful.