# What is the inverse of $f(n)=\frac{n^2+n}{2}$?

I'm building an algorithm to determine whether a value is inside a series. To speed it up, I need the inverse function of the following series:

$$1 + 2 + 3+\cdots +n$$

What is the inverse function of $f(n) = \frac{n(n + 1)}{2}$?

-

I don't understand much of your question, but if $$f(n)={n(n+1)\over2}$$ then $$8f(n)+1=(2n+1)^2$$ so $$n={\sqrt{8f(n)+1}-1\over2}$$

-
 I'm trying to get the inverse function of $[n(n+1)]/2$ I'm testing your solution right now, thanks for posting! – Guy David Jun 29 '12 at 5:46 Also, can you explain a bit more about the second step? Thank you – Guy David Jun 29 '12 at 5:48 @Guy: That's exactly what Gerry gave. Try plugging in a specific $n$: letting $n=3$, then we have that $f(3)=\frac{3^2+3}{2}=6$, and $$\frac{\sqrt{8f(n)+1}-1}{2}=\frac{\sqrt{8\cdot 6+1}-1}{2}=\frac{\sqrt{49}-1}{2}=\frac{6}{2}=3$$ – Zev Chonoles Jun 29 '12 at 5:48 First you multiply both sides by 8 and add 1, noting the resulting right side factors. Then you take the square root, subtract 1, and divide by 2. – Gerry Myerson Jun 29 '12 at 5:57 Thank you for clarifying! I really appreciate it. – Guy David Jun 29 '12 at 6:33

$$f(n)={n(n+1)\over2}$$ $$\implies 2 f(n) = n^2+n$$ $$\implies 2f(n) +\frac 14 = (n)^2 + 2\times n\times \frac 1 2 +\left(\frac 12\right)^2$$

$$\implies 2f(n)+\frac 1 4 = \left(n+\frac 12 \right)^2$$ $$\implies n = \sqrt{2 f(n)+\frac{1}{4}} -\frac{1}{2}$$

$$\implies n = \frac{\sqrt{8 f(n)+1}}{2} -\frac{1}{2}$$

which gives the expression @Gerry Myerson posted.

-

Inverse of given function is $\frac{\sqrt{8f(n)+1}-1}2$(as solved by @Gerry Myerson),but this function is helpful only if the series you are considering is first $n$ natural numbers(in that case, every integer $\geq 1$ and $\leq$ number provided by this inverse function is in the series).

-