1

How would you make a function for this Input/Output:

For example, 3:

  • You multiply x (3) by itself

  • Then you multiply x - 1 (2) by itself and add it to 9 (3 squared) And so on.....

You could say it's x squared + x - 1 squared and so on, but I'm looking for a way to write this as an arithmetic equation.

EDIT: The formula for this is 1/6x (x + 1) x (2x + 1). Thank you to yurnero and sranthrop.

TigerGold
  • 339
  • You don't have to add answers you like to your question. You can just "Accept" one of them by giving it the tickmark, located to the left, below the arrows. – yurnero Dec 25 '16 at 02:51

2 Answers2

1

Edit: From the comments, I take that your function is $$ x\mapsto\sum_{j=0}^{x-1}(x-j)^2=x^2+(x-1)^2+\cdots+1. $$ An explicit formula for the RHS above exists: \begin{aligned} \sum_{j=0}^{x-1}(x-j)^2&=1^2+2^2+\cdots+x^2\\ &=\frac{1}{6}x(1+x)(1+2x). \end{aligned} You can prove $1^2+2^2+\cdots+x^2=\frac{1}{6}x(1+x)(1+2x)$ by induction on $x$. For an answer on MSE, see here.

yurnero
  • 10,505
1

If your sequence is $1\mapsto 1^2, 2\mapsto 1^2+2^2, 3\mapsto1^2+2^2+3^3,...$, then this can be shortly written as \begin{align*} n\mapsto \sum_{k=1}^nk^2=\frac{1}{6} n (1 + n) (1 + 2 n). \end{align*} For example, if you want to know what 5 is mapped to, just plug in $n=5$ and obtain $\frac{1}{6}\cdot 5\cdot(1+5)\cdot(1+2\cdot 5)=55.$

sranthrop
  • 8,497