Zulip Chat Archive

Stream: general

Topic: n+


Kevin Buzzard (Aug 04 2023 at 01:48):

Is it possible to have suffix notation n+ for Nat.succ n, like we have -n for integers?

Kevin Buzzard (Aug 04 2023 at 01:49):

I've heard it's big in computer science

Adam Topaz (Aug 04 2023 at 01:50):

Really?

Adam Topaz (Aug 04 2023 at 01:50):

What is -n supposed to be?

Kevin Buzzard (Aug 04 2023 at 01:51):

or is it a++? -n is neg n, right?

Adam Topaz (Aug 04 2023 at 01:52):

Oh ok yeah n++ is a thing.

Kevin Buzzard (Aug 04 2023 at 01:52):

it's suffix notation for succ, right?

Adam Topaz (Aug 04 2023 at 01:52):

Yeah I would hope that -n is neg n,

Kevin Buzzard (Aug 04 2023 at 01:54):

And now how do you name a + d+ = (a + d)+? :-/

Kevin Buzzard (Aug 04 2023 at 01:55):

wait maybe this doesn't fly for some reason I don't understand.

Kevin Buzzard (Aug 04 2023 at 01:56):

add_succ_eq_add_succ' is not a good look

Adam Topaz (Aug 04 2023 at 01:57):

It would be notation for succ, so it should follow the standard naming convention as if it was just the function being applied

Kevin Buzzard (Aug 04 2023 at 02:18):

Maybe prefix ++a notation is less confusing for beginners.

Kevin Buzzard (Aug 04 2023 at 02:21):

Oh I'm wrong, a + d+ = (a + d)+ is just called add_plus`

Kevin Buzzard (Aug 04 2023 at 02:22):

it's fine. I'm wondering whether I could change the name of the constructor to plus and try this n+ or +n notation to see if it's easier or harder.

Adam Topaz (Aug 04 2023 at 02:26):

FWIW, I do think it would be nice to have some programmy notations like n++, n += 37,etc. (especially if/when they make sense in a do block)

Eric Rodriguez (Aug 04 2023 at 04:11):

These notations traditionally increment n, so I think using them for succ would be confusing

Mario Carneiro (Aug 04 2023 at 04:34):

Notations I have seen for the successor function include: n', S(n) or S n, suc n, succ n, n+1. n+ is a new one to me

Kevin Buzzard (Aug 04 2023 at 09:29):

Oh maybe if n++ and ++n are misleading then n+ might be worth experimenting with? Like A+ is better than an A. Or do people think this is crazy? I know succ is traditional but I've never liked it; it gets giggles in schoolrooms and so when I'm building the naturals from scratch in front of an audience I always use S now. Yesterday when experimenting with new NNG worlds I found myself writing succ this which I didn't think was a good look, this was what sent me off on this postfix idea.

Julian Berman (Aug 04 2023 at 09:33):

There is also n⁺ to just mention another existing unicode character.

Eric Wieser (Aug 04 2023 at 09:36):

I think we might already use that notation for docs#PosPart

Eric Wieser (Aug 04 2023 at 09:37):

n⁺¹ seems slightly less crazy than n+, which makes n.succ.succ.succ n⁺¹⁺¹⁺¹

Eric Wieser (Aug 04 2023 at 09:38):

Of course this is still crazy, because (1⁺¹⁻¹ : Rat) is now 0.5 if we're not careful

D. J. Bernstein (Aug 04 2023 at 09:40):

How about spelling out successor, and encapsulating all the successor n theorems as n+1 theorems as soon as addition is defined, so that about 0% of users ever have to see the successor notation?

Eric Wieser (Aug 04 2023 at 10:01):

One place the name is really hard to avoid is induction n with | succ n := sorry

Eric Wieser (Aug 04 2023 at 10:02):

I don't think notation is legal there

Eric Wieser (Aug 04 2023 at 10:02):

Oh, and of course in all the theorem names!

Eric Rodriguez (Aug 04 2023 at 10:02):

In Lean3 we could do (n+1) := ... - does this not work in Lean4?

Eric Wieser (Aug 04 2023 at 10:04):

For match, yes; but the with clause on induction and cases matches goal names not expressions

Kevin Buzzard (Aug 04 2023 at 10:42):

In NNG we have the option to hack the induction tactic so that it gives n + 1 as the successor case; it's already hacked so that it gives 0 rather than MyNat.zero as the base case.

Pedro Sánchez Terraf (Aug 04 2023 at 11:38):

Julian Berman said:

There is also n⁺ to just mention another existing unicode character.

This one is also used (in the context of Cardinal) for Order.succ in the literature, and also for other sorts of set-theoretical successors.

Eric Wieser (Aug 04 2023 at 11:39):

Kevin Buzzard said:

In NNG we have the option to hack the induction tactic so that it gives n + 1 as the successor case; it's already hacked so that it gives 0 rather than MyNat.zero as the base case.

Sure, but separate to changing what the goal state displays, we'd also need to change the syntax of

induction n with
| zero => sorry
| succ n ih => sorry

Pedro Sánchez Terraf (Aug 04 2023 at 11:41):

Eric Wieser said:

n⁺¹ seems slightly less crazy than n+, which makes n.succ.succ.succ n⁺¹⁺¹⁺¹

And I've also seen things like κ+n\kappa^{+n} in the same context.

Kevin Buzzard (Aug 04 2023 at 12:54):

In NNG I'm not going to use the pipe syntax at all. We're going to run induction n with d hd like in NNG3 and then have two goals, the first one of which is displayed and the second one of which is suppressed, and I'm not even going to ask the user to indent. I know that this is bad coding practice but I'm not teaching coding, I'm teaching proofs.

Johan Commelin (Aug 04 2023 at 17:13):

For the constructor, I would be happy to switch to S or successor. But this would require a change to core...

Adam Topaz (Aug 04 2023 at 17:25):

Eric Rodriguez said:

These notations traditionally increment n, so I think using them for succ would be confusing

It wouldn't be confusing if we could write

do
  let mut n := 30
  n++
  n += 6
  IO.println n

Eric Wieser (Aug 04 2023 at 17:30):

+= feels like slightly strange notation when assignment is := not =

Johan Commelin (Aug 04 2023 at 17:56):

All of humanity can be divided neatly into two classes: those who prefer +:= and those who prefer :+=.

Niels Voss (Aug 04 2023 at 18:25):

+:= might conflict with the proposed n+ notation, depending on how the left side of := is parsed. For this matter, n += 6 might be interpreted as a proposition.

Jireh Loreaux (Aug 04 2023 at 18:37):

In my opinion, this n+ idea is incredibly confusing. It just makes things look like they would be syntactically invalid. And regarding newcomers / students, I find that they already have a hard enough time distinguishing syntactically valid expressions from invalid ones, so there's no point adding to the confusion.

Kevin Buzzard (Aug 04 2023 at 20:39):

But -x - -x makes sense:

import Mathlib.Tactic

variable (x : Int) in
#check -x - -x -- -x - -x : ℤ

and it kind of looks confusing until you start thinking about it, and the + version is no different in terms of notation.

Eric Rodriguez (Aug 04 2023 at 21:02):

And in paper maths we get sign errors all the time! Imagine if we now get sign errors about + too...

Kevin Buzzard (Aug 04 2023 at 21:13):

I think that both prefix and suffix + should be valid syntax just to prove how arbitrary it is.

Niels Voss (Aug 05 2023 at 00:10):

Unary prefix + is valid in some languages as a "do nothing" operator (maybe used to emphasize something is positive or maybe to validate that a certain type is numeric in a macro. I think in C it can do coercions). But I don't think unary suffix + or - are valid in any language I'm aware of.

Niels Voss (Aug 05 2023 at 00:12):

What would n- mean?

Joscha Mennicken (Aug 05 2023 at 00:56):

How would x+ -x be interpreted?

Siddhartha Gadgil (Aug 05 2023 at 01:16):

A superscript looks fine. Allowing suffixes will lead to weird stuff like 3+ + 4 being valid (and 8).

Martin Dvořák (Aug 05 2023 at 08:07):

I'd vote for n⁺ if need be. I am completely fine with status quo.

Julian Berman (Aug 05 2023 at 08:22):

Niels Voss said:

Unary prefix + is valid in some languages as a "do nothing" operator (maybe used to emphasize something is positive or maybe to validate that a certain type is numeric in a macro. I think in C it can do coercions). But I don't think unary suffix + or - are valid in any language I'm aware of.

In some silly languages it's even valid as a "do something" operator:

  ptpython3                                                                                                                                                                                                                                          julian@Airm
>>> class Foo:
...     def __pos__(self):
...         return 37
>>> +Foo()
37

Niels Voss (Aug 05 2023 at 18:15):

I mean it can be a valid "do something" operator in Lean as well, as well as in many other languages with operator overloading. But it doesn't do anything in math, I think.


Last updated: Dec 20 2023 at 11:08 UTC