Zulip Chat Archive
Stream: Is there code for X?
Topic: Is there List.Forall₂, but for one list? (In library Std)
Lessness (Oct 19 2023 at 17:32):
I'm searching in https://leanprover-community.github.io/mathlib4_docs/Std/Data and can't find such definition.
For now I have found only List.Forall₂
(for two lists and binary relation) and List.all
(for one list and function that returns Bool), and List.All₂
...
Lessness (Oct 19 2023 at 17:34):
Of course, I can do forall x, List.Mem x L -> P x
. I just want to find out if I'm bad at search or there's no such definition actually.
Ruben Van de Velde (Oct 19 2023 at 17:41):
There's docs#List.all in core
Lessness (Oct 19 2023 at 17:43):
Yes, that's the second definition I found and mentioned. It's almost what I wanted but not exactly (Bool
instead of Prop
).
Eric Wieser (Oct 19 2023 at 17:44):
I think the ∀
version is idiomatic here, though it's possible the one you want also exists
Lessness (Oct 19 2023 at 17:44):
Ok, thank you both
Eric Wieser (Oct 19 2023 at 17:45):
docs#List.All₂
Eric Wieser (Oct 19 2023 at 17:45):
What a confusing pair of names
Eric Wieser (Oct 19 2023 at 17:48):
https://leanprover-community.github.io/mathlib4_docs/Mathlib/Data/List/Defs.html#List.All%E2%82%82
Lessness (Oct 19 2023 at 17:50):
Oh, right, somehow I found List.All₂ but got some brain fog and didn't understand that it is what I was searching for.
Thank you.
Joachim Breitner (Oct 19 2023 at 18:55):
That's indeed a very unhelpful name, I expect most associate the subscript 2 with ”Two lists”. Worth renaming to All or Forall?
Eric Wieser (Oct 19 2023 at 19:25):
Yes, I think the previous name was dealing with a name clash that was only a problem with the lean3 naming
Joachim Breitner (Oct 19 2023 at 20:16):
I also wonder how useful it is to avoid the final And True
, I expect this makes some proofs harder, because it needs more case analyses in the inductive case. Maybe I'll see what breaks if one uses the normal recursive definition.
Eric Wieser (Oct 19 2023 at 20:57):
It's pretty handy to have nice defeqs for things like this
Eric Wieser (Oct 19 2023 at 20:57):
If we didn't have the defeq we could just use ∀
Joachim Breitner (Oct 20 2023 at 06:58):
Yes! But I'd expect the simpler function that doesn't special case the singleton list to have even nicer defeqs (in particular All p (x :: xs) = p x /\ All p xs
). But I'll first have to try to see what Chesterson has to say about that.
Joachim Breitner (Oct 20 2023 at 07:20):
I just notice that List.Forall₂
isn't recursive with nice defeq either, but rather an inductive predicate. I understand that that’s useful for proofs by induction, but I wouldn’t you get the best of all if List.Forall₂
is defined recursively (using /\, for nice defeqs), and an inductive principle is then proved for it?
Is it possible to register such a recursor for List.Forall₂
after the fact, so that induction h
still works as before?
(But probably not; that would be the “custom recusor” feature we talked about here a few days ago.)
Eric Wieser (Oct 20 2023 at 07:26):
Custom recursors via induction
are already a feature
Joachim Breitner (Oct 20 2023 at 07:32):
But they won’t be picked up by match
, will they?
Joachim Breitner (Oct 20 2023 at 07:41):
Too bad, then it’s not a refactoring that’s “for free” (unless nobody uses pattern matching on Forall_2
).
@David Thrane Christiansen , is there already a tracking issue for “custom pattern matching” where we could collect usecases?
Eric Wieser (Oct 20 2023 at 07:49):
In my view the use-case of All₂
is to use change
to go from p ∧ q ∧ r
to All₂ [p, q, r]
, and then use a lemma to get to ∀ pi ∈ [p, q, r], pi
Eric Wieser (Oct 20 2023 at 07:50):
In the same spirit as docs#FinVec.Forall
Joachim Breitner (Oct 20 2023 at 08:16):
Somehow this special-casing of the singleton list feels wrong to me, but if you are dealing mostly dealing with concrete finite lists, rather than arbitrary lists with induction, I see the benefit of avoiding the ∧ True
that corresponds to :: []
.
I have https://github.com/leanprover-community/mathlib4/pull/7797 so far. I could back out the change to the definition and only keep the renaming.
David Thrane Christiansen (Oct 20 2023 at 08:21):
Joachim Breitner said:
Too bad, then it’s not a refactoring that’s “for free” (unless nobody uses pattern matching on
Forall_2
).
David Thrane Christiansen , is there already a tracking issue for “custom pattern matching” where we could collect usecases?
We don't yet have one - do you want to make it or should I?
Joachim Breitner (Oct 20 2023 at 08:45):
Started one at https://github.com/leanprover/lean4/issues/2716, feel free to expand, I sense you might have some concrete surface syntax suggestions.
Last updated: Dec 20 2023 at 11:08 UTC