# The general term of the sequence : 1, 1, -1, -1, 1, 1, …? [duplicate]

Suppose we have the following sequence:

{$a_n$} such as:
$a_0 = 1, \\ a_1 = 1, \\ a_2 = -1, \\ a_3 = -1, \\ a_4 = 1, \\ a_5 = 1, \\ ...$

How can we find the general term of this sequence? I tried using a trigonometric function e.g. $\alpha \sin(x+\phi)$, then we impose some constraints on $\alpha$ and $\phi$ to get that sequence, but I get lost, is there any clever way to find the general term?

EDIT: The question is identified as duplicate, but that answer does not solve the question, because I am looking for a solution that does not involve floor function.

## marked as duplicate by Matthew Towers, user296602, Claude Leibovici, Did, ArsenBerkJan 20 '18 at 23:47

• Lets be clear , you are not looking for general term, this is actually asking what can generate this repeating sequence. From finite terms general terms can no be found as there are infinitely many solutions that will have coinciding terms as the finitely given term. General terms can be only given not deduced. – Arjang Jan 14 '18 at 3:06
• DFT is always the most powerful tool at hand for finding "general terms" of a periodic sequence. – Henricus V. Jan 14 '18 at 4:04
• @Peter Discrete Fourier Transform – Henricus V. Jan 14 '18 at 12:09
• What's your goal? If you just want to describe the sequence, something like $$a_i=\begin{cases}\phantom{-}1&\text{if }i\bmod4\in\{0,1\}\\-1&\text{otherwise}\end{cases}$$ is much clearer than messing around with trigonometric functions. – David Richerby Jan 14 '18 at 17:36
• @Freshman42 OK. If you can really calculate $\sqrt{2}\sin(n\pi/2 + \pi/4)$ or even $n(n-1)/2$ faster than you can calculate $n\bmod 4$ then I can't argue... But you really oughta practice your basic arithmetic. ;-) – David Richerby Jan 15 '18 at 21:04

You could use $\cos(n\pi/2)+\sin(n\pi/2)$. I see this working by thinking about the unit circle. A needle pointing East, North, West, or South always contributes a $0$ from among $\cos(n\pi/2),\sin(n\pi/2)$ and also either $1$ or $-1$. And it just works out.

Trig identities show this is equal to to $\sqrt{2}\sin(n\pi/2+\pi/4)$

Or from a different perspective, $(-1)^{n(n-1)/2}$. The expression $n(n-1)$ is always even, so always divisible by $2$. Sometimes, one of $n,n-1$ is also divisible by $4$, so that you still have an even number after dividing by $2$. As $n$ iterates, first $n$ will be divisible by $4$, then $n-1$ will be divisible by $4$, then $n$ will be divisible only by $2$, then $n-1$ will be divisible only by $2$. And then it all repeats. So the exponent on $(-1)$ is even, even, odd, odd, repeat.

• @Freshman42 I added some alternative expressions to the answer. – alex.jordan Jan 13 '18 at 23:59
• @Freshman42 Try values $n = 0 .. 8$ to verify it. – Todd Sewell Jan 14 '18 at 13:33
• @Freshman42 Because the parity of $n(n-1)/2$ depends on the value of $n$ modulo $4$ (it is divisible by $2$ if and only if either $n$ or $n-1$ is divisible by $4$). – user202729 Jan 14 '18 at 14:08
• @user202729: Thank you – Freshman42 Jan 14 '18 at 20:23
• @Freshman42 $n(n-1)$ is always even, so always divisible by $2$. Sometimes, one of $n,n-1$ is also divisible by $4$, so that you still have an even number after dividing by $2$. As $n$ iterates, first $n$ will be divisible by $4$, then $n-1$ will be divisible by $4$, then $n$ will be divisible only by $2$, then $n-1$ will be divisible only by $2$. And then it all repeats. So the exponent on $(-1)$ is even, even, odd, odd, repeat. – alex.jordan Jan 14 '18 at 21:49

The general solution of the recurrence $\ a_n=a_{n-4}\$ is $$a_n=Ai^n+B(-1)^n+C(-i)^n+D$$ where $A,B,C,D$ are arbitrary constants.

The particular solution for your initial values $\ a_0=a_1=1,\ a_2=a_3=-1\$ is $$a_n=\frac{(1-i)i^n+(1+i)(-i)^n}2.$$ Using the identities $i^n=e^{n\pi i/2}=\cos\frac{n\pi}2+i\sin\frac{n\pi}2$ and $(-i)^n=e^{-n\pi i/2}=\cos\frac{n\pi}2-i\sin\frac{n\pi}2$
we can rewrite this as $$a_n=\cos\frac{n\pi}2+\sin\frac{n\pi}2.$$

• bof. Nice, the start from something tangible, a_n=a_(n-4). – Peter Szilas Jan 14 '18 at 7:44

$$(-1)^{\lfloor{n/2}\rfloor},$$ where $\lfloor{\cdot}\rfloor$ is the floor function, or as requested in the comment, $$\sqrt{2}\cdot\sin\big((2n+1)\pi/4\big).$$

• I think there is a solution that does not involve floor function – Freshman42 Jan 13 '18 at 23:53