0
$\begingroup$

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}$?

3 Answers 3

4

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}$$

  • 0
    I'm trying to get the inverse function of $[n(n+1)]/2$ I'm testing your solution right now, thanks for posting!2012-06-29
  • 0
    Also, can you explain a bit more about the second step? Thank you2012-06-29
  • 0
    @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$$2012-06-29
  • 0
    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.2012-06-29
  • 0
    Thank you for clarifying! I really appreciate it.2012-06-29
2

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

0

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