Proof attempt to show that the following function is one to one but not onto I was wondering if my proof attempt is logically correct.

Given a function $g: \mathbb{N} \to \mathbb{N}$ is defined by $g(x) = \frac{x(x+1)}{2}$. Show that $g$ is one-to-one but not onto.

So, first, to show that $g$ is indeed one-to-one, I used the definition of injectivity, as follows:

Suppose that there exist arbitrary $a, b \in \mathbb{N}$ such that $g(a) = g(b)$. This means that we get $$\frac{a(a+1)}{2} = \frac{b(b+1)}{2}$$
$$a^2-b^2 = b-a$$
$$-(a-b)(a+b) = a-b$$
$$a+b = -1$$
This is impossible since we know that both $a$ and $b$ are natural numbers. Which means that it must be the case that $a = b$ (not sure if this makes complete sense). 
For showing that this function is not onto, I simply claimed that this function will never produce the value $8$ to show that not all the elements in the co-domain are getting mapped to. But I was curious to know if there is a better way to show it (perhaps using the discriminant somehow?)
Thanks a bunch.
 A: Yes, your proof/the idea is fine, but you could write it down a bit more clearly by assuming that there exists $a, b \in \mathbb{N}$ with $a \neq b$ and $g(a) = g(b)$ and then continue the way you have to get the wanted contradiction. 
For the "onto"-part: I think it it always quite nice to simply find some element which is not in the image. Otherwise you could also "compute the image". The image consists of all numbers of the form $0 + 1 + 2 + \dotsc + m$ for some natural number $m$ (or without the zero depending on your convention of the natural numbers), which is just a reformulation of the function $g$ actually. Both like this or by really considering $g$ in the form you have given one easily sees that also $2,4,5$ and many others are not in the image.
A: Concerning the proof that $g$ is injective, what you wrote is fine until you get$$-(a-b)(a+b)=a-b.$$But then you jump from here to $a+b=-1$. In other words, you divided both sides by $-a+b$. You can only do that if $-a+b\ne0$, which means that $a\ne b$. So, this proves that, if $a\ne b$, then $g(a)\ne g(b)$ (which is what you needed).
Concerning surjectivity, you stated that $g(a)$ is never $8$. Indeed, but you have to prove it.
A: If $y$ is in a range then we have $$x^2+x =2y\implies (2x+1)^2=8y+1$$
So if say $y=8$ we get $65$ which is clearly not a square. So Range$(f) \ne \mathbb{N}$. 
Also clearly $f$ is increasing so it is injective.
