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.
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.