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.

  • 1
    $\begingroup$ so it goes $0,1,3,4,4,3,1,0,0,1,\dots $? $\endgroup$
    – Asinomás
    Jan 20, 2017 at 18:52
  • 2
    $\begingroup$ The pragmatic approach would be to find it in OEIS :). $\endgroup$
    – miradulo
    Jan 20, 2017 at 18:54
  • 2
    $\begingroup$ 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. $\endgroup$
    – The Count
    Jan 20, 2017 at 18:57
  • $\begingroup$ Start by graphing it $\endgroup$ Jan 20, 2017 at 19:05
  • $\begingroup$ And note the maximum would be in-between 4 and 4. $\endgroup$ Jan 20, 2017 at 19:06

3 Answers 3


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\\ $$


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

  • $\begingroup$ Indeed, you don't need multiplication or division, just addition and scalar multiplication is enough (this is essentially Fourier series). $\endgroup$
    – Erick Wong
    Jan 20, 2017 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$


Not the answer you're looking for? Browse other questions tagged or ask your own question.