Prove $(x, y) \mapsto \frac{(x+y)(x+y+1)}{2}+y$ is surjective 
$f$ is defined  by:$$f: \mathbb{N^2} \to \mathbb{N}$$
$$(x, y) \mapsto \frac{(x+y)(x+y+1)}{2}+y$$
  Prove that $f$ is surjective.

What I have about $f$:


*

*$\forall (x,y)\in\mathbb{N^*×N} : f(x-1, y+1)-f(x,y) = 1$

*$\forall y\in\mathbb{N}: f(y+1, 0)-f(0,y) = 1$

*$f$ is injective.


And if possible how can I find a solution to an equation like this:
$$f(x,y)=2018$$
 A: Consider $z \in \mathbb N$. The sequence $u_n =\frac{n(n+1)}{2}$ is strictly increasing and $u_0=0$. Therefore, it exists a unique $n\in \mathbb N$ such that
$$u_n \le z < u_{n+1}$$
You’ll verify that $f(n-z+u_n,z-u_n) =z$. As $0\le z-u_n <n+1$ we have $n-z+u_n \ge 0$. Consequently, $n-z+u_n$ and $z-u_n$ are both non negative proving that $f$ is surjective.
Apply that to $2018$. You have
$$u_{63} = 2016 \le 2018 < u_{64} =2080$$
And $f(61, 2)=2018$.
A: Just to be clear:  What you want to prove is that for any integer $k \ge 0$ there are integers $x,y \ge 0$ so that $\frac {(x+y)(x+y+1)}2 + y = k$.  
(This assumes $0\in \mathbb N$.  Now some text have $0\not \in \mathbb N$.  I actually prefer that and think it is more ...er... natural.  But if $x \ge 1$ and $x \ge 1$ then $\frac {(x+y)(x+y+1)}2 + y \ge 2$ and we can't ever have $f(x,y) = 1$.))
So... to the problem...
Trick is (maybe) to realize that $\frac {(x+y)(x+y+1)}2 = \sum_{j=0}^{x+y} j$.
Now $0\le 0 < 0+1$ and $0+1 \le 1,2 < 0+1+2$ and $0+1+2 \le 3,4,5 < 0+1+2+3$ and so on. 
For any $k$ there is a (unique) $M\in \mathbb N$ so that $\sum_{j=0}^{M} j \le k < \sum_{j=0}^{M+1} j$
If we let $y = k - \sum_{j=0}^{M} j = k-\frac {M(M+1)}2\ge 0$ we know that $\sum_{j=0}^{M} j \le k < \sum_{j=0}^{M+1} j$ so $0 \le y =k - \sum_{j=0}^{M} j < M+1$.  So if we let $x = M-y\ge 0$ we have
$f(x,y) = \frac {(x+y)(x+y+1)}2 + y$ =
$\frac {M(M+1)}2 + (k- \sum_{j=0}^{M} j) =$
$\sum_{j=0}^{M} j + (k- \sum_{j=0}^{M} j)=k$.
Furthermore we have proven that $x,y$ are unique so $f$ is a bijection.
This is basically the "diagonal" bijection.
$(0,0)\to 0\ \ \ \color{blue}{(0,1)\to 2}\ \ \ \color{green}{(0,2)\to 5}\ \ \ \color{red}{(0,3)\to 9}\ \ \ .....$
$\color{blue}{(1,0)\to 1}\ \ \ \ \color{green}{(1,1)\to 4}\ \ \ \color{red}{(1,2)\to 8}....$
$\color{green}{(2,0)\to 3}\ \ \ \color{red}{(2,1)\to 7}...$
$\color{red}{(3,0)\to 6}\ \ \ ....$
$....$
P.S. 1: If you don't have the insight that $\frac {(x+y)(x+y+1)}2 = \sum^{x+y} j$ you can reason that for every $k$ there is a unique $M$ so that $\frac {M(M+1)}2 \le k < \frac {M(M+1)}2 + (M+1)=\frac {(M+1)(M+2)}2$ but that's not so obvious.
However it is clear if $M = x+y$ the $\frac {M(M+1)}2$ is strictly increasing so that for all $k$ there is a unique $M$ so that $\frac {M(M+1)}2 \le k \le \frac {(M+1)(M+2)}2$ si this is surjective.  But without noting that $\frac {(M+1)(M+2)}2 = \frac {M(M+1)}2 + M+1$ exactly it's not so clear this is injective.
And there is no intuition that this is the "diagonal" mapping (which is geometrically obvious... but algebraicly nerve wracking.)
Although to be fair you didn't ask about proving it was injective.
P.S. 2:  If you require that $0\not \in N$ we can modify $f((x,y)) = [\frac {((x-1)+(y-1))((x-1)+(y-1)-1)}2 + (y-1)] + 1 = \frac {(x+y-2)(x+y-1)}2 + y$ to get the proper offset for the proper diagonal argument to be a bijection between $\mathbb N^2 \to \mathbb N$.
A: Using what you have already showed it can by done by induction.
Indcution hypothesis: for $n$ there exists a pair $(x,y)$ such that $f(x,y) = n$.
Induction start:
$f(0,0) = 0$.
Induction step: Let $n$ and $(x,y)$ be according to the induction hypothesis. Then there two cases:


*

*$x\neq 0$: So by item 1. of what you have already showed
$$f(x-1,y+1) = f(x,y) +1 = n+1.$$

*$x=0$: Then by item 2. of what you have already showed
$$f(y+1,0) = f(0,y) + 1 = n+1.$$
So in any case the induction hypothesis also holds for $n+1$.
A: Solving an equation like $f(x,y) = 2018$ wouldn't be too hard using your first two results. Start with $x = y = 1$ so $f(x,y) = 4$. Then, you know $f(0,2) = 5$ (through 1.), then use your 2nd result to obtain $f(3,0) = 6$ and, by using 1 again, $f(0,3) = 9$ and $f(4,0) = 10$. Via induction, prove that $f(n,0) = \sum_{k=1}^n k = \frac{n(n+1)}{2}$ and then deduct that $f(n-l,l) = l+\sum_{k=1}^n k$ for $0 \leq l \leq n$. Since every natural number $n$ can be expressed as $n = l + \sum_{k=1}^m k$ for $0 \leq l \leq m$ and some natural $m$ (you might want to prove this too), this proves surjectivity.
