# Formula for $n^{th}$ term in sequence [closed]

How do I find a formula $a_n$ for the following periodic sequence: $$0,1,3,4,4,3,1,0,0,1,3,4,4,3,1,0,...$$

The period of the above sequence is 8 with sub-sequence $\{0,1,3,4,4,3,1,0\}$ repeating.

• so it goes $0,1,3,4,4,3,1,0,0,1,\dots$? Jan 20 '17 at 18:52
• The pragmatic approach would be to find it in OEIS :). Jan 20 '17 at 18:54
• Why do you need a formula? If you have this information, then given any natural number $n$, you can quickly find the $n$-th term. Jan 20 '17 at 18:57
• Start by graphing it Jan 20 '17 at 19:05
• And note the maximum would be in-between 4 and 4. Jan 20 '17 at 19:06

Any periodic sequence can be constructed by element-wise addition, subtraction, multiplication and division of periodic sequences consisting of zeros and ones. Periodic zero and one sequences can be expressed as sums of trigonometric functions:

$$\sum_{k=1}^{k=1} \cos (-2\pi\frac{n(k-1)}{1})/1 = 1,1,1,1,1,1,1,1,1...\\ \sum_{k=1}^{k=2} \cos (-2\pi\frac{n(k-1)}{2})/2 = 0,1,0,1,0,1,0,1,0...\\ \sum_{k=1}^{k=3} \cos (-2\pi\frac{n(k-1)}{3})/3 = 0,0,1,0,0,1,0,0,1,0,0,1,0,0,1...\\ …\\ \sum_{k=1}^{k=N} \cos (-2\pi\frac{n(k-1)}{N})/N = 0,0,0...,1 \text{ sequence with period } N\\$$

https://en.wikipedia.org/wiki/Periodic_sequence#Periodic_0.2C_1_sequences

You need to add up a linear combination of 8 of these sequences, and you're done.

• Indeed, you don't need multiplication or division, just addition and scalar multiplication is enough (this is essentially Fourier series). Jan 20 '17 at 19:28

Following @RobertFrost's observation, probably one of the more compact expressions for this sequence is $$\big\lfloor 4.5 \sin^2(\frac{\pi}{8}(n-0.5))\big\rfloor.$$

I got the discrete function $a(n)$ as

$$a_n=3-\lfloor|3.5-((n-1)\ mod\ 8)|\rfloor+\lfloor\frac{3-\lfloor|3.5-((n-1)\ mod\ 8)|\rfloor}{2}\rfloor$$

Though it looks very sophisticated it can be very easily obtained.

My approach:

I have tried to approach the problem logically.

First try finding $a(x)$ for $x=1,2,...,8$. Later we can replace $x$ with $((n-1)\ mod\ 8) +1$

Since it is symmetric around $4.5$, the function has some component of form $\pm|4.5-x|$ (i.e. $\pm\{3.5,2.5,1.5,0.5,0.5,1.5,2.5,3.5\}$).

We can manipulate the above form to obtain $3-\lfloor|4.5-x|\rfloor$ (i.e $\{0,1,2,3,3,2,1,0\}$).

To obtain the desired sequence $$\displaystyle\{0,1,3,4,4,3,1,0\}=\{0,1,2,3,3,2,1,0\}+\lfloor\frac{\{0,1,2,3,3,2,1,0\}}{2}\rfloor$$ just add $\displaystyle \lfloor\frac{3-\lfloor|4.5-x|\rfloor}{2}\rfloor$.

So we have $$a(x)=3-\lfloor|4.5-x|\rfloor+\lfloor\frac{3-\lfloor|4.5-x|\rfloor}{2}\rfloor$$

To get $a(n)$ for all natural numbers n put $x\rightarrow((n-1)\ mod\ 8) +1$