Zulip Chat Archive

Stream: mathlib4

Topic: Induction argument order


Violeta Hernández (Sep 07 2024 at 16:02):

Do we have some sort of convention for the argument order in induction principles?

Violeta Hernández (Sep 07 2024 at 16:03):

I notice in some induction principles proving P a, the argument a is at the end of the argument list, like in docs#Nat.recOnMul, while in others like docs#Ordinal.induction it goes at the beginning, before any of the hypotheses.

Violeta Hernández (Sep 07 2024 at 16:03):

Is either form preferred?

Yaël Dillies (Sep 07 2024 at 16:05):

The rule is that if you have On in the name, then a is at the start, else it's at the end. Looks like both your examples are going against that rule...

Edward van de Meent (Sep 07 2024 at 17:23):

Is this a rule (i.e. explicitly stated somewhere) or merely unspoken convention?

Edward van de Meent (Sep 07 2024 at 17:24):

If it is the latter, but should be the former, perhaps the place to write this down is the style guide?

Yaël Dillies (Sep 07 2024 at 17:25):

Probably #naming is the right place for such information

Kyle Miller (Sep 07 2024 at 17:29):

I'm not sure there's any hard-and-fast rule for induction, but On definitely signifies the major premise comes first. (A rule that major premises come last if there's no On makes sense to me though.)

Edward van de Meent (Sep 08 2024 at 09:48):

let me see if i can make a PR adding this to the naming guide...

Edward van de Meent (Sep 08 2024 at 10:13):

while i am writing this, would i be correct in saying that if the declaration is for Prop-typed motives, it should be called like induction (i.e. inductionOn rather than recOn)?

Yaël Dillies (Sep 08 2024 at 10:25):

and induction_on rather than inductionOn

Edward van de Meent (Sep 08 2024 at 10:26):

Quot.inductionOn
ZFSet.inductionOn
:face_with_peeking_eye:

Edward van de Meent (Sep 08 2024 at 11:52):

for now, i've made a preliminary PR. Please do suggest improvements to phrasing, i'm not quite sure about it yet. Also, i'd apreciate it if a maintainer could comment on this. (seeing the current state of mathlib, the proposed convention is not quite as commonplace as i expected it to be...)

Edward van de Meent (Sep 08 2024 at 11:54):

Edward van de Meent said:

(seeing the current state of mathlib, the proposed convention is not quite as commonplace as i expected it to be...)

as evidenced by searching the docs for .ind and inductionOn, as well as the earlier-mentioned counterexamples mentioned by Violeta...

Kevin Buzzard (Sep 08 2024 at 11:54):

Don't forget recOn ;-)

Edward van de Meent (Sep 08 2024 at 11:58):

recOn is an allowed name according to the naming convention though?

Kevin Buzzard (Sep 08 2024 at 13:37):

Sure! I just meant "make sure that you check that the order of the variables is OK in this case too :-)"

Edward van de Meent (Sep 08 2024 at 13:53):

My point was that they are both bad names: inductionOn is bad because the case suggests it can be Type-valued, which would mean it is rather a recursion principle, while ind is an unnecessary shortening of induction, decreasing readability.

Yuyang Zhao (Sep 08 2024 at 14:05):

I think the .rec .recOn rule comes from the names of automatically generated recursors of inductive types.

Eric Wieser (Sep 19 2024 at 11:35):

Do we have buy-in from core here? There seem to be Sort-valued recursors that use the Induction name.

#check Nat.div2Induction
#check Nat.strongInductionOn
#check Nat.strongRecOn -- identical to the above

Eric Wieser (Sep 19 2024 at 11:36):

cc @Kim Morrison, would a PR to rename / deprecate those names be accepted?

Mario Carneiro (Sep 19 2024 at 14:08):

IIRC there was a very similar case that was deprecated in lean 4, so I think the answer is yes

Mario Carneiro (Sep 19 2024 at 14:10):

lean4#5179 <- by "very similar" I mean "identical"

Edward van de Meent (Sep 19 2024 at 16:17):

there is another question from the discussion of this PR (which is about adding a naming convention for inductive/recursive principles) about what to name the "motive" argument, and it was rightly suggested by @Eric Wieser that this should be discussed on zulip. I argued that we should try to give these more understandable names, because an undergrad might not have heard of the term, which can make using an inductive or recursive principle daunting. As an alternative in the case of induction principles, i suggested calling the motive argument simply P for proposition. as such, are some polls:

Edward van de Meent (Sep 19 2024 at 16:22):

/poll What should Prop-eliminating motives be called
P
motive
decide on a case-by-case basis

Edward van de Meent (Sep 19 2024 at 16:25):

/poll What should Sort-eliminating motives be called
P
motive

Edward van de Meent (Sep 19 2024 at 16:26):

/poll What should Type-eliminating motives be called
P
motive

Eric Wieser (Sep 19 2024 at 16:27):

(for some history, in Lean 3 the nat.rec_on auto-generated recursors used C for the motive name)

Mario Carneiro (Sep 19 2024 at 16:28):

isn't the point of calling it motive instead of C exactly to "give it a more understandable name"?

Eric Wieser (Sep 19 2024 at 16:28):

Yes, I guess the question is whether "more understandable" applies to P too

Edward van de Meent (Sep 19 2024 at 16:28):

(and there are still some recursors with that as motive name, see for example WellFounded.induction)

Mario Carneiro (Sep 19 2024 at 16:28):

single letter names don't really convey anything

Eric Wieser (Sep 19 2024 at 16:29):

Eric Wieser said:

cc Kim Morrison, would a PR to rename / deprecate those names be accepted?

docs#Quot.inductionOn also has the Sort-capitalized name.

Edward van de Meent (Sep 19 2024 at 16:29):

Mario Carneiro said:

single letter names don't really convey anything

indeed, but they are less intimidating than [insert term you've never heard of] when looking at a function/lemma which should do something simple

Mario Carneiro (Sep 19 2024 at 16:31):

it is true that we don't have def Nat.sub (minuend subtrahend : Nat) : Nat

Violeta Hernández (Sep 21 2024 at 05:20):

It took me quite a while to understand what motive was doing, I initially thought it was some sort of reserved keyword.

Violeta Hernández (Sep 21 2024 at 05:21):

P and C are what I've most often come across with custom induction/recursion principles

Edward van de Meent (Sep 25 2024 at 09:55):

i suppose i'll call it now and note that there is a majority for using motive in all cases.

Edward van de Meent (Oct 22 2024 at 17:06):

the PR to the website adding this as naming convention has been merged, see here

Edward van de Meent (Oct 22 2024 at 17:07):

this may mean there is some tech debt to clean up

Kyle Miller (Oct 22 2024 at 18:34):

Why is it induction_on and not inductionOn? Wouldn't this be like insisting that in theorems we should see strict_mono rather than strictMono? To me, inductionOn is the name of the principle; the on isn't separate.

Eric Wieser (Oct 22 2024 at 18:34):

I think this is the congrArg vs congr_arg discussion again, which I don't remember if we resolved.

Eric Wieser (Oct 22 2024 at 18:36):

A weak argument in favor of _on is that it is a bit like _of

Kyle Miller (Oct 22 2024 at 18:36):

_on being like _of_nameOfThisType seems reasonable

Kyle Miller (Oct 22 2024 at 18:38):

I think that one's a bit different from congr though. I think congr_position makes sense in general as a naming convention, and it's just like the _left/_right naming convention. For function application, there just happen to be better names than Function.congr_left and Function.congr_right, namely referring to fun and arg. (We shouldn't expect core to change on this, but I do think congr_fun and congr_arg are more principled names.)

Eric Wieser (Oct 22 2024 at 18:38):

But also, this is me making up a justification for something that we inherited without thought from lean 3.

Kyle Miller (Oct 22 2024 at 18:43):

There's a big proviso with that _on justification, which is that specifically it's saying what the first explicit argument is, vs _of which doesn't have that restriction.

Edward van de Meent (Oct 22 2024 at 18:52):

according to the docs, terms of prop are in snake_case.

Edward van de Meent (Oct 22 2024 at 18:52):

and since inductionOn isn't a word...

Edward van de Meent (Oct 22 2024 at 18:55):

other than that, i'd like to point out that the added naming convention doesn't specify that it should be induction_on. it merely says that the name has to contain both induction and on when it eliminates only into prop and has the value argument before the constructions.

Kyle Miller (Oct 22 2024 at 18:56):

strictMono isn't a word either though, right?

Edward van de Meent (Oct 22 2024 at 18:58):

right

Edward van de Meent (Oct 22 2024 at 19:00):

in that case, it's the lowercase-ing of StrictMono, which produces a term of type Prop. However, there is no Prop (or Type) named InductionOn...

Kyle Miller (Oct 22 2024 at 19:03):

I'm just saying that "the docs say terms of prop are snake_case" doesn't imply inductionOn shouldn't be inductionOn

Mario Carneiro (Oct 25 2024 at 18:10):

My understanding of the rule here is what Edward says: strictMono is named that because there is actually a definition called StrictMono which is involved in the statement. If it was just about monotonicity as a general concept it would be spelled strict_mono in theorems

Mario Carneiro (Oct 25 2024 at 18:10):

(and yes, this is the congr_arg discussion again)

Mario Carneiro (Oct 25 2024 at 18:11):

which was never really resolved; core and mathlib simply have different conventions on this point


Last updated: May 02 2025 at 03:31 UTC