# The Gauss Trick The Gauss trick is a **shortcut for calculating the sum of all [[Integer Numbers]] in a certain range**, or for calculating the sum of first n numbers. $\sum_{n=a}^b n = (a+b)\frac{b-a+1}{2}$ ^iaisqa Or, when $a=1$, the formula can be simplified into $\sum_{n=1}^b n = \frac{b(b+1)}{2}$ ^rygyu3 You can reason with this by thinking about pairs of numbers (last + first) and the count of such pairs which is $\frac{b}{2}$. ![[XGyhXtn9T3-group-20.svg.png|250]] The sequence of numbers formed with the simplified formula is known as the Triangle Number Sequence (1, 3, 6, 10, 15,...). The Gauss trick is a simplified version of the sum of terms formula of an arithmetic sequence. See [[Arithmetic Series]]. For more info see the following two Brilliant quizzes: - [The Gauss Trick](https://brilliant.org/practice/the-gauss-trick) - [Pentagonal and Hexagonal Numbers](https://brilliant.org/practice/pentagonal-and-hexagonal-numbers) ## Proof by Binomial Expansion Start with binomial expansion of $(n-1)^2$: $ \begin{gather} (n-1)^2=n^2-2n+1 \\ n^2-(n-1)^2 = 2n - 1 \end{gather} $ We can take the sum of both sides from $n=1$ to $b$ to get: $\sum_{n=1}^b\left[n^2-(n-1)^2\right] = \sum_{n=1}^b\left[2n - 1\right]$ Lets look at the two sides one by one. The left sum can be expanded like: $ \begin{gather} \sum_{n=1}^b\left[n^2-(n-1)^2\right] = \\ 1 + \\ 2^2-1+ \\ 3^2-2^2+ \\ 4^2 - 3^2 \\ +\ldots+ \\ b^2-(b-1)^2 \\ =b^2 \end{gather} $ It is said that this series telescopes: all terms cancel out until the last $b^2$. The right sum can be simplified as: $\sum_{n=1}^b\left[2n - 1\right] = 2 \sum_{n=1}^b [n] - b$ When we put the left and right sides together we get: $ \begin{gather} 2 \sum_{n=1}^b [n] - b = b^2 \\ \sum_{n=1}^b n = \frac {b^2+b} {2} = \frac {b(b+1)} {2} \end{gather} $