Series that don't have 3s

May 19, 2022

My 2019 attempt to make a series that has 00 every third element and nn otherwise.


One of the last math topics we did in 9th grade (3º de la ESO) was series. My math teacher at the time (Marta) put up the challenge of coming up with a series that is just like an=na_n = n, except every third number it has to be 00. I, of course, took the challenge. However, I couldn’t have expected how interesting this problem would end up being. Here I’ve compiled all the solutions I came up with back in 2019.


1. Sines

The function sin(n)\sin(n) is cyclic, so it makes sense to use it. We can adjust its phase to thirds by multiplying by 2π3\frac{2\pi}{3}:

an=sin(2π3n)a_n = \sin\left( \frac{2\pi}{3} n \right)

However, I used τ\tau back then and, while it certainly is a questionable choice, I will respect it today.

an=sin(nτ3)a_n = \sin\left( \frac{n \tau}{3} \right)

Thus, we have 32\frac{\sqrt{3}}{2}, 32-\frac{\sqrt{3}}{2}, 00, …

We can normalize these values by multiplying by the reciprocals, 23=233\frac{2}{\sqrt{3}} = \frac{2 \sqrt{3}}{3}:

an=sin(nτ3)233a_n = \sin\left( \frac{n \tau}{3} \right) \frac{2 \sqrt{3}}{3}

To get 11, 1-1, 00, …

And then we can square to get the correct signs:

an=(sin(nτ3)233)2a_n = \left( \sin\left( \frac{n \tau}{3} \right) \frac{2 \sqrt{3}}{3} \right)^2

So if we just multiply by the index, nn, we have our series!

an=n(sin(nτ3)233)2=4n3sin2(nτ3)\begin{equation} \begin{align*} a_n &= n \left( \sin\left( \frac{n \tau}{3} \right) \frac{2 \sqrt{3}}{3} \right)^2 \\ &= \frac{4n}{3} \sin^2\left( \frac{n \tau}{3} \right) \end{align*} \end{equation}

It’s interesting to note that this method wouldn’t work so nicely with periods other than 3. We were lucky that the magnitude of the reciprocal is the same for the two values that weren’t 0 (and we couldn’t just divide because we would have a problem with 00\frac{0}{0}).

Once I presented this solution to my teacher, she proposed to me a new challenge: sines (and any basic cyclic functions) are banned. What to do now?

2. Complex numbers

Actually, there is quite a simple workaround, but it’s kind of cheesy.

We know that complex numbers can be expressed as

z=eτθi=cos(θ)+isin(θ)z = e^{\tau \theta i} = \cos(\theta) + i \sin(\theta)

If they have an argument of 11. So, if we just take the imaginary part of zz, we have a sine:

(eτθi)=sin(θ)\Im(e^{\tau \theta i}) = \sin(\theta)

And this way we can substitute our previous result.

bn=n((eτ(nτ3)233i))2\begin{equation} b_n = n \left( \Im(e^{\tau \left( \frac{n \tau}{3} \right) \frac{2 \sqrt{3}}{3} i}) \right)^2 \end{equation}

3. Check multiples

Let’s try to solve it cleanly, with the definition of multples.

A number nn is said to be a multiple of pp if:

kZ:n=pk\exists k \in \mathbb{Z} : n = p \cdot k

So if we’re searching for positive multples of 3, we want the following condition:

kN:n=3k\exists k \in \mathbb{N} : n = 3k

The expression n=3kn = 3k implies 3kn=03k - n = 0. However, we don’t know value of kk, so what could we do?

Well, we can just try all of the values of kk. If (and only if) nn is actually a multiple of 33 the previous difference will be 00. If we take the product of all the differences, we will have a 00 when nn is a multiple of 33 and a different number otherwise.

Things are going to get messy, so let’s call this product pnp_n:

pn=k=1(3kn)p_n = \prod_{k=1}^{\infty} (3k - n)

Now we have 00 for multiples of 3 and some large product otherwise. Therefore, we have to find some way to leverage some special property that 00 has.

One such property is that 0!=10! = 1. The only other number that has 11 as its factorial is 1!=11! = 1, but if we just multiply pnp_n by 22 we will have our desired effect. We should also square it to avoid getting the gamma definition of the factorial when applied to negative numbers.

This way, not only every other number will not return 11, it will return an even number (since every factorial after 2!2! has a factor of 22). To summirize:

2pn2={1ifx=0evenifx02{p_n}^2 = \begin{cases} 1 & \textrm{if} & x = 0 \\ \textrm{even} & \textrm{if} & x \ne 0 \end{cases}

Now we can use a property of the parity of numbers. Namely, the fact that (1)2k=1(-1)^{2k} = 1 and (1)2k+1=1(-1)^{2k + 1} = -1. We can reduce to 00 the odd case by adding 11 and, since that will retun 22 on the even case, we can divide by 22. Thus we have a solution:

cn=n2((1)2pn2!+1)\begin{equation} c_n = \frac{n}{2} \left( (-1)^{2{p_n}^2!} + 1 \right) \end{equation}

It’s easy to see that the product will never have to go past nn (or even n3\frac{n}{3}). I find the infinity more mathematically aesthetic, but I used nn on the implementation. Also, we have to reduce the product because we are taking a hilariously big factorial which will never be able to compute after a certain point. We can do this because we can prove that the parity is the only important aspect and will remain the same.

This solution very easy to modify for other periods (just replace the 33!) and probably the cleanest.

4. Subtraction

Another approach is to cyclify our series, by substracting 33 every third element.

Let’s try to subtract 33 after the third element just once. We can separate values bigger and smaller than 33 by subtracting… 3.53.5. It’s quite ugly, but this way we have negative values between 11 and 33 and positive values afterwards.

We can extract the sign of a value xx if we do xx\frac{|x|}{x}, where x0x \ne 0, to avoid using less conventional notation.

We can do the same thing as for solution 33 to convert these values into 00 before and 11 after:

12(n3.5n3.5+1)\frac{1}{2}\left(\frac{|n - 3.5|}{n - 3.5} + 1 \right)

So if subtract that to nn we would have 11, 22, 33, 11, 22, 33, 44, …

We have the same series, but shifted over by 33! This means we can do the same thing but for n+3n + 3. Then we would have to do the same but for n+6n + 6, then n+9n + 9, etc…

So we have sum where the general term is (n3k)3.5)(n - 3k) - 3.5). As we only care for the sign and not the magnitude, we can de-uglify the expresion by multiplying by 22. This way, the expresion is as follows:

sn=n32k=1(2n6k72n+6k7+1)s_n = n - \frac{3}{2} \sum_{k = 1}^{\infty} \left( \frac{|2n - 6k - 7|}{2n + 6k - 7} + 1 \right)

The expression sns_n returns 11, 22, 33, 11, 22, 33, … indefinitely.

The easiest way to make it have 00 every third element is to subtract 22, offset it and do the same thing as with the sines. Back in the day for some reason I did it using factorials. The expression in question is the following:

dn=n(sn!sn31)\begin{equation} d_n = - n \left( \frac{s_n! - s_n}{3} - 1 \right) \end{equation}

There’s no justification for this last step other than “it just kinda works”.

5. Unbeknownst recursion

The previous solution was very recursive in nature. Could we just use recursion?

This is the last, and might be the most interesting. Looking back, I’m very surprised, since I hadn’t heard of recursion back then and I was kinda redescovering it myself.

Let’s take

sn=32(2n72n7+1)s_n = \frac{3}{2}\left(\frac{ |2n - 7| }{2n - 7} + 1 \right)

Which is useful, because:

cn=nsn={nn<3n3n3c_n = n - s_n = \begin{cases} n & n < 3 \\ n - 3 & n \ge 3 \end{cases}

As before, this is the start of a counter that goes 11, 22, 33, 11, 22, 33, 44, 55, … So this counter works until n=6n = 6.

One way to extend it is to “change” the nn. More precisely, if we input numbers between 11 and 66 to cnc_n, then it’s going to work. The thing is that cnc_n provides numbers between 11 and 66 until n=9n = 9!

en=ccne_n = c_{c_n}

Remember that cnc_n was defined as:

cn=n32(2n72n7+1)c_n = n - \frac{3}{2}\left(\frac{ |2n - 7| }{2n - 7} + 1 \right)

So ccnc_{c_n} is:

ccn=cn32(2cn72cn7+1)=n32(2n72n7+1)32(2cn72cn7+1)\begin{align*} c_{c_n} &= c_n &- \frac{3}{2}\left(\frac{ |2c_n - 7| }{2c_n - 7} + 1 \right) \\ &= n - \frac{3}{2}\left(\frac{ |2n - 7| }{2n - 7} + 1 \right) &- \frac{3}{2}\left(\frac{ |2c_n - 7| }{2c_n - 7} + 1 \right) \end{align*}

We can then input ccnc_{c_n} into cnc_n to get it to work until n=12n = 12:

cccn=cn32(2cn72cn7+1)32(2ccn72ccn7+1)=n32(2n72n7+1)32(2cn72cn7+1)32(2ccn72ccn7+1)\begin{align*} c_{c_{c_n}} &= c_n &- \frac{3}{2}\left(\frac{ |2c_n - 7| }{2c_n - 7} + 1 \right) - \frac{3}{2}\left(\frac{ |2c_{c_n} - 7| }{2c_{c_n} - 7} + 1 \right) \\ &= n - \frac{3}{2}\left(\frac{ |2n - 7| }{2n - 7} + 1 \right) &- \frac{3}{2}\left(\frac{ |2c_n - 7| }{2c_n - 7} + 1 \right) - \frac{3}{2}\left(\frac{ |2c_{c_n} - 7| }{2c_{c_n} - 7} + 1 \right) \end{align*}

And now the recursive nature is becoming apparent. Let’s call the recursive counter, rnr_n:

rn=n32(2rn72rn7+1)r_n = n - \frac{3}{2}\left(\frac{ |2r_n - 7| }{2r_n - 7} + 1 \right)

There is still one small problem. This recursion, as it stands, is infinte; any implementation would stack overflow. The easy solution is to define something like r0=0r_0 = 0. However, we can just prove it!


First, observe that 2rn72rn7\frac{ |2r_n - 7| }{2r_n - 7} is always either 11 or 1-1. This means that 2rn72rn7+1\frac{ |2r_n - 7| }{2r_n - 7} + 1 is always 00 or 22, which in turn implies that 32(2rn72rn7+1)-\frac{3}{2}\left(\frac{ |2r_n - 7| }{2r_n - 7} + 1 \right) is always 00 or 33.

Using this, we can deduce that n(rnn)\forall n (r_n \le n), since rn=n0r_n = n - 0 or rn=n3r_n = n - 3 and both satisy this condition.

Now, according to the definition of rnr_n, the value of r0r_0 is the following:

r0=032(2r072r07+1)r_0 = 0 - \frac{3}{2}\left(\frac{ |2r_0 - 7| }{2r_0 - 7} + 1 \right)

We know that r0r_0 can be, at most, 00. However, any value less than 33 will evaluate to 00 in 32(2r072r07+1)\frac{3}{2}\left(\frac{ |2r_0 - 7| }{2r_0 - 7} + 1 \right). This means that r0=00=0r_0 = 0 - 0 = 0


So, finally, we can make the last series using the counter, and the same approach used in solution 4:

en=n(rn!rn31)\begin{equation} e_n = -n \left( \frac{r_n! - r_n}{3} - 1 \right) \end{equation}

Isn’t it beautiful?


This is the technical part of this project, but in 2020 I also made a video (in spanish) of my journey to get to the solutions. Finally, I’ve implemented this in a Pluto notebook written in Julia.