Zulip Chat Archive
Stream: mathlib4
Topic: left and right
Aaron Liu (Oct 08 2025 at 01:31):
Sometimes I can't use mathlib without loogle and this is one of the reasons
Stuff that looks to me to be about (_ + ·)
lots
loogle only showed me the first 200 in my search so I don't have any more than this but sometimes it's left (usually it's left) and sometimes it's right so how am I supposed to tell
Kenny Lau (Oct 08 2025 at 05:29):
@Joachim Breitner maybe can we have a button in loogle to "show 200 more results"?
David Loeffler (Oct 08 2025 at 12:37):
sometimes it's left (usually it's left) and sometimes it's right so how am I supposed to tell
So your point is that the defs / lemmas involving x ↦ a + x, for a fixed a and x the argument, sometimes have names involving add_left and sometimes add_right?
I raised a very similar point for smulonly a day or two back (here: #mathlib4 > Naming discrepancy: `smulLeft` vs `smulRight`). I'm glad I'm not the only one who considers this sub-optimal.
Bryan Gin-ge Chen (Oct 08 2025 at 12:41):
I thought we had more specific guidance in our naming conventions but it does look like there's a hole there. It'd be good to settle on something here!
Kenny Lau (Oct 08 2025 at 12:45):
"left inverse" is an existing term where "y is a left inverse of x" means yx=1, and consequently we also have add_left_inj which means i + k = j + k ↔ i = j which means the function x ↦ x + k is injective, and this is clearly adding on the left
Kenny Lau (Oct 08 2025 at 12:47):
to make this point clearer, from "y is a left inverse of k" we say "k has a left inverse", where in this case to connect with the function it means that the map x ↦ x * k has 1 in its image (which is usually equivalent to the function being surjective)
Kenny Lau (Oct 08 2025 at 12:48):
oh boy by this logic the majority of aaron's linked decls are wrong
Sébastien Gouëzel (Oct 08 2025 at 13:02):
I prefer to avoid left and right precisely because of this ambiguity (are we adding something to the left of x, or is the varying variable on the left of the expression?), and to use const_add and add_const instead.
Eric Wieser (Oct 08 2025 at 13:59):
Bryan Gin-ge Chen said:
I thought we had more specific guidance in our naming conventions
We have only
An injectivity lemma that uses "left" or "right" should refer to the argument that "changes". For example, a lemma with the statement
a - b = a - c ↔ b = ccould be calledsub_right_inj.
Bhavik Mehta (Oct 08 2025 at 15:18):
Also
Predicates as suffixes can be preceded by either
_leftor_rightto signify that a binary operation is left- or right-monotone. For example,mul_left_monotone : Monotone (· * a)proves left-monotonicity of multiplication and not monotonicity of left-multiplication.
Kenny Lau (Oct 08 2025 at 15:21):
which means AddLeftMono is very much wrong
Aaron Liu (Oct 08 2025 at 15:22):
The theorem docs#add_right_mono uses the typeclass docs#AddLeftMono
Kenny Lau (Oct 08 2025 at 15:23):
note that my explanation above with left inverse is consistent with these two quoted notes, and is also consistent with the fact that AddLeftMono is wrong
Kenny Lau (Oct 08 2025 at 15:23):
Aaron Liu said:
The theorem docs#add_right_mono uses the special typeclass docs#AddLeftMono
oh no...
Weiyi Wang (Oct 08 2025 at 15:32):
That's a refactoring in motion #29396
Jovan Gerbscheid (Oct 08 2025 at 15:35):
Yes, we are in the process of fixing this, but the left/right refers to the side with the variable argument. So e.g. right monotonicity is monotonicity of c + . for a fixed c.
Aaron Liu (Oct 08 2025 at 15:35):
That's unfortunately not what I'm used to
Aaron Liu (Oct 08 2025 at 15:36):
are we really gonna swap add_left_comm and add_right_comm
Kenny Lau (Oct 08 2025 at 15:39):
that's unfortunate, i guess based on my logic i'll also have to get used to the new left_comm
Aaron Liu (Oct 08 2025 at 15:46):
Kenny Lau said:
"left inverse" is an existing term where "y is a left inverse of x" means yx=1, and consequently we also have add_left_inj which means
i + k = j + k ↔ i = jwhich means the functionx ↦ x + kis injective, and this is clearly adding on the left
I don't buy this logic how did you go from left inverse to add_left_inj
Aaron Liu (Oct 08 2025 at 15:47):
to me that says "adding on the right by k is injective"
Kenny Lau (Oct 08 2025 at 15:48):
Aaron Liu said:
Kenny Lau said:
"left inverse" is an existing term where "y is a left inverse of x" means yx=1, and consequently we also have add_left_inj which means
i + k = j + k ↔ i = jwhich means the functionx ↦ x + kis injective, and this is clearly adding on the leftI don't buy this logic how did you go from left inverse to
add_left_inj
the logic is that everything with "left" in the name is referring to the function x ↦ x op k where op is + or *
Aaron Liu (Oct 08 2025 at 15:48):
I don't see how that applies to left inverse
Kenny Lau (Oct 08 2025 at 15:49):
has left inverse says that this function has 1 in the range
Aaron Liu (Oct 08 2025 at 15:49):
"has left inverse" and "is right inverse" are the same thing
Aaron Liu (Oct 08 2025 at 15:49):
so I could just as well say this is right
Kenny Lau (Oct 08 2025 at 15:51):
:thinking:
Kenny Lau (Oct 08 2025 at 15:51):
i retract my statement
Johan Commelin (Oct 09 2025 at 06:41):
Sébastien Gouëzel said:
I prefer to avoid
leftandrightprecisely because of this ambiguity (are we adding something to the left ofx, or is the varying variable on the left of the expression?), and to useconst_addandadd_constinstead.
I like this. What do others in this thread think of this suggestion?
Johan Commelin (Oct 09 2025 at 06:42):
cc @Yaël Dillies
Kenny Lau (Oct 09 2025 at 09:00):
ConstAddMono is fine and unambiguous, but what's mul_left_comm?
Kenny Lau (Oct 09 2025 at 09:00):
I suppose that can be mul_const_comm?
Eric Wieser (Oct 09 2025 at 09:01):
left_comm is its own atom there, it means op a (op b c) = op b (op a c)
Eric Wieser (Oct 09 2025 at 09:02):
I supposed you could argue for leftComm, I don't remember what we decided the rule was there
Eric Wieser (Oct 09 2025 at 09:31):
I'd argue the const terminology only makes sense when there's a lambda involved, to refer to the variable not bound by the lambda
Kenny Lau (Oct 09 2025 at 09:33):
well AddConstMono can have a lambda
Eric Wieser (Oct 09 2025 at 09:36):
I guess you could phrase op a (op b c) = op b (op a c) as (fun a b => op a (op b c)) a b = (fun a b => op a (op b c)) b a to justify a const, though then it would be op_op_const_comm
Yaël Dillies (Oct 09 2025 at 19:26):
I think _leftComm is good, and we are not using it now merely because this is a name coming from mathlib3
Yaël Dillies (Oct 09 2025 at 19:27):
Johan Commelin said:
Sébastien Gouëzel said:
I prefer to avoid
leftandrightprecisely because of this ambiguity (are we adding something to the left ofx, or is the varying variable on the left of the expression?), and to useconst_addandadd_constinstead.I like this. What do others in this thread think of this suggestion?
I am not a big fan, mostly because the location of the const modifier changes between the two lemmas in a pair, and I still believe I can iron out the _left/_right table cloth.
Aaron Liu (Oct 09 2025 at 19:41):
Eric Wieser said:
left_commis its own atom there, it meansop a (op b c) = op b (op a c)
I thought it was because it's saying (a + ·) ∘ (b + ·) = (b + ·) ∘ (a + ·)
Sébastien Gouëzel (Oct 10 2025 at 12:43):
Yaël Dillies said:
I am not a big fan, mostly because the location of the
constmodifier changes between the two lemmas in a pair, and I still believe I can iron out the_left/_righttable cloth.
The fact that the location of the const changes is precisely the point, right? The main advantage I see compared to left / right is precisely that there is no ambiguity because the position of the keyword tells everything. With left or right, there is an ambiguity. We could probably choose a convention for left / right once and for all and try to enforce it all over mathlib, but since this would be an arbitrary convention newcomers who are not aware of it will always be confused / make mistakes that we will have to fix. In fact, we have already chosen such a convention (use the side of the varying variable) but it's obscure enough that it's not respected. IMHO, using a phrasing without built-in ambiguity is a clear win here.
Kenny Lau (Oct 16 2025 at 08:58):
Kevin Buzzard (Oct 16 2025 at 09:17):
We can't even be consistent with primed and nonprimed versions of lemmas!
Yaël Dillies (Oct 16 2025 at 11:20):
The latter is correct: left here refers to a in a * b
Aaron Liu (Oct 16 2025 at 11:22):
can it be mul_lt_left_iff_lt_one and mul_lt_right_iff_lt_one that's how I would name it
Yury G. Kudryashov (Oct 16 2025 at 13:35):
@Yaël Dillies I understand that you have a clear idea of what _left/_right at the end of a name means. Many people (incl. myself and most of the new contributors) don't have it and/or don't think that it's important enough to memorize it. If a lemma can be named without _left/_right at the end (e.g., by using const_mul or mul_eq_left_...), I would definitely prefer this name. I'm not sure about lemmas like add_le_add_left (I see that you're swapping left/right for some of these lemmas in a pending PR).
Kenny Lau (Oct 16 2025 at 13:38):
is a or b the constant in the photo i posted?
Yaël Dillies (Oct 16 2025 at 13:41):
I don't disagree with you, Yury. I think here Aaron's suggestion is best.
Yaël Dillies (Oct 16 2025 at 13:41):
I should have said that the second one was more correct
Yury G. Kudryashov (Oct 16 2025 at 13:43):
I'm sorry if my message did sound offensive. This was not my intention.
Yaël Dillies (Oct 16 2025 at 13:44):
Nono, it didn't feel offensive at all. I'm just annoyed at myself for having written my above remark in 10s during a lecture and thus forgetting to mention the better alternative :sweat_smile:
Last updated: Dec 20 2025 at 21:32 UTC