# Generalisation of alternating functions

So if we want to have a function go positive negative we take $$(-1)^n$$, if we want it to take positive positive negative negative(like was on stack exchange a few days ago, we take:

# $$(-1)^\cfrac{(n-1)(n+2)}{2}$$

What about positive positive positive negative negative negative: So

f(n) = \left\{ \begin{align} 1, n= 1,2,3,7,8,9,\dots \\-1,n=4,5,6,10,11,12,\dots \end{align} \right.

How is this created. I understand that I want it the power to be even,even,even,odd,odd,odd. But I can't seem to pin down how this can be made. Any ideas?

More generally, how do set up any combination of positive and negative?

• Take simply $\lceil n/3 \rceil$. Jun 7, 2014 at 8:30
• @PeterFranek How do I do this without ceiling/floor notations?
– Tony
Jun 7, 2014 at 8:32
• Are you ok with having mods in the formula or do you really want it using powers? Jun 7, 2014 at 8:47
• @Jake Powers would be best. I understand how to do it using modulo.
– Tony
Jun 7, 2014 at 8:49
• It was I who asked the previous question. I am also interested in this, and have been taking a look at it. Jun 7, 2014 at 11:53

2-power period

For a period that is $2^k$, you can use $\large (-1)^{\binom{n}{2^k}}$ which can be easily proven to work by induction on the parity of entries in the Pascal's triangle. However for non-powers of $2$ no polynomial power of $-1$ would work, for a curious reason that has to do with the relation between Pascal's triangle and the difference sequences.

General period

There is still a formula for what you want in general, using only arithmetic operations and exponentiation, but you'll have to accept complex roots of unity or the equivalent trigonometric quantities. You basically want a sequence such that every element is the negation of the element $k$ steps earlier. That can be achieved by a recurrence such as:

$f(n+k) + f(n) = 0$

Using the forward shift operator $R$, that is equivalent to:

$(R^{k}+1)( f ) = 0$

So we need:

$f(n) = \sum_{i=1}^k a_i e^{i2π\frac{2i-1}{2k}n}$ for some constants $( a_i : i \in [1..k] )$

Now all that remains is to find those constants such that $f$ is $1$ on the first $k$ natural numbers. (Here natural numbers start at $0$ because it would be more elegant.) This is always possible because the desired sequence has such a form.

Examples

For $k = 2$:

Let $f(n) = \frac{1}{2} (1-i) i^n + \frac{1}{2} (1+i) i^{-n}$

$= \cos(\frac{π}{2}n) + \sin(\frac{π}{2}n)$

For $k = 3$:

Let $f(n) = \frac{1}{3} (-1)^n + \frac{2}{3} {ζ_6}^{n-1} + \frac{2}{3} {ζ_6}^{1-n}$ where $ζ_6 = e^{i\frac{2π}{6}}$

$= \frac{1}{3} (-1)^n + \frac{4}{3} \cos(\frac{π}{3}(n-1))$