# How to find the exponent $z$ of $(-1)^z$ for a patterned series of signed ones?

A question in Larson "Calculus" asks for the Taylor series centered at $\frac{\pi}{4}$ of $\cos(x)$.

This expands to:

$a_n = \frac{\sqrt{2}}{2} - \frac{\sqrt{2}}{2}(x - \frac{\pi}{4}) - \frac{\sqrt{2}}{2}(x - \frac{\pi}{4})^2(\frac{1}{2!}) + \frac{\sqrt{2}}{2}(x - \frac{\pi}{4})^3(\frac{1}{3!}) + \dots$

Which is:

$a_n = \frac{\sqrt{2}}{2}\sum_{n=0}^{\infty}\frac{(-1)^z}{n!}\left(x - \frac{\pi}{4}\right)^n$

But $z$ is unknown...because of the way the derivative of $cos(x)$ oscillates in sign, to get a serial summation I need to find a way to represent the following series:

$\{+1, -1, -1, +1, +1, \dots\} = (-1)^z$ where $z$ is an unknown function of $n$.

The textbook gives $z = n(n+1)/2$. However, it provides no explanation of how it arrived at this value. Is there a technique I can use to find the function of $z$ I need given any particular sign pattern?

The signs of the derivatives of $\cos$ at $\pi/4$ follow the pattern $(+,-,-,+)$. This means a pattern of "even,odd,odd,even" in the parity of $z$. Note that even+even=even, even+odd=odd, and odd+odd=even. So one way to get the desired sign pattern is to start at $0$, add an odd number, then an even, then an odd, then an even, etc. It is clear that this will happen if $z=\sum_{j=0}^n j$, and it is a standard exercise to show that $\sum_{j=0}^n j = \frac{n(n+1)}{2}$.
I unfortunately can't really come up with a general solution to this problem that is within the scope of a calculus course. If I couldn't come up with a simple formula, I would probably just define the function based on remainders. For example in your situation you would have $f(n)=1$ if $n=4k$ or $n=4k+3$, $-1$ otherwise.
The pattern of signs should be obvious: you repeat $1,-1,-1,1$.
Since $(-1)^{\text{even}}=1$ and $(-1)^{\text{odd}}=-1$, you want any sequence that follows the pattern "even, odd, odd, even". This should be enough to check that your textbook's solution works.
To see this (relatively) intuitively, write the sequence of $1$s and $-1$s as:
$$(1), (1\times -1), (1 \times-1 \times 1), (1\times -1 \times 1 \times -1) \ldots$$ And therefore, $$(-1)^{0}, (-1)^{0}\times(-1)^{1},(-1)^{0}\times(-1)^{1}\times(-1)^{2}\ldots$$ Now, we know this can be written as $$(-1)^{0}, (-1)^{0+1}, (-1)^{0+1+2}, (-1)^{0+1+2+3}\ldots$$ Of which the general term is $(-1)^{n(n+1)/2}$