Zulip Chat Archive
Stream: mathlib4
Topic: Coding style: `Π i, X i` vs `∀ i, X i` vs `(i : ι) -> X i`
Yury G. Kudryashov (Apr 07 2024 at 20:34):
Lean accepts all 3 of Π i, X i
, ∀ i, X i
, and (i : ι) -> X i
. Do we have any official preference in Mathlib?
Kyle Miller (Apr 07 2024 at 20:52):
My preference:
- If it's a proposition, use
∀ i, X i
- If it's thought of as a product of types (like say you're working with the product of a family of groups), you can use
Π i, X i
- If you're writing a dependent function, use
(i : ι) -> X i
, it's more convenient, it's more clearly a function type, and it makes it easy to switch to and from being dependent.
There's also sigma types, with (i : ι) × X i
and Σ i : ι, X i
. I think the first is clearer, making it much more obvious that it's a pair, and it also is easy to switch it between a non-dependent product and a dependent product.
Yury G. Kudryashov (Apr 07 2024 at 23:15):
What about [∀ i, TopologicalSpace (X i)]
vs [Π i, TopologicalSpace (X i)]
?
Yury G. Kudryashov (Apr 07 2024 at 23:18):
Should we change it everywhere?
Anatole Dedecker (Apr 07 2024 at 23:20):
I agree that this one is trickier. Technically speaking it’s data, on the other hand I think using forall makes it closer to what one could say on paper.
Jireh Loreaux (Apr 08 2024 at 01:23):
Kyle's list also fits my exact preferences.
Yury G. Kudryashov (Apr 08 2024 at 04:38):
Should we add it to #style?
Andrew Yang (Apr 08 2024 at 13:39):
I thought Π i, X i
was disallowed in lean4?
Anatole Dedecker (Apr 08 2024 at 13:45):
We added it back in Mathlib (I think ? Maybe earlier)
Yaël Dillies (Apr 09 2024 at 21:28):
(i : ι) -> X i
is a weird non-mathematical notation, so I would be in favour of using it only when a type-ascription is necessary. It's otherwise unnecessarily wordy
Yury G. Kudryashov (Apr 09 2024 at 22:00):
@Kyle Miller What do you mean by "if you're writing a dependent function"? What's a good example?
Yury G. Kudryashov (Apr 09 2024 at 22:02):
@Yaël Dillies We use notation that isn't natural for mathematicians here and there (e.g., a linear algebra book would talk about , not )
Yaël Dillies (Apr 11 2024 at 08:29):
Regardless of mathematicality, it forces you to write out the type of the binder even when it can be inferred from context, which makes it a deal-breaker to me
Eric Wieser (Apr 11 2024 at 08:46):
(not with (i : _) -> X i
, but obviously that's still uglier than either of the other two spellings)
Kyle Miller (Apr 11 2024 at 09:03):
Yury G. Kudryashov said:
What do you mean by "if you're writing a dependent function"?
I'm thinking about families of elements vs functions. They're the same thing, but mathematically we write the first as but the second as .
Kyle Miller (Apr 11 2024 at 09:04):
@Eric Wieser That made me think about whether (i :) -> X i
would make sense to have. We already have (i :)
is a typeless type ascription.
Eric Wieser (Apr 11 2024 at 09:23):
I don't think we want that; binders are not type ascriptions so there's no obligation to be consistent, and the notation itself seems pretty ugly anyway.
Edward van de Meent (Apr 11 2024 at 14:14):
The fact that they use the same symbol (:
) suggests that they are similar, which (imho) should imply that they are consistent
Edward van de Meent (Apr 11 2024 at 14:16):
i suppose the notation being ugly suggests that (i :)
shouldn't be used as a type ascription either...
Notification Bot (Apr 14 2024 at 06:20):
Sebastian Ullrich has marked this topic as resolved.
Sebastian Ullrich (Apr 14 2024 at 06:21):
What... I don't even know how I did that in the app
Notification Bot (Apr 14 2024 at 06:37):
Kyle Miller has marked this topic as unresolved.
Last updated: May 02 2025 at 03:31 UTC