# How I realized, as an adult, that i’ve been studying Number Theory since I was a kid

Since I was a kid, i used to read a lot. I was amazed by the fact that there’s a lot of different things to do. My problem as a kid was that i wanted to do everything at the same time. Ask my mother. I wanted to be, in order of appearance:

- A fireman
- A medic
- An inventor
- A pianist
- An astronaut
- A football player

Luckily for my family i had a “keep moving” attitude, and once i realized something was “further than 3 steps from where I’m now”, i resigned my “dream” looking for something more (easy) interesting to do.

That, until something happened.

On the next lines i’m going to cover the story of how fascinated about numbers i was as a child, and how that fascination led me to develop an interesting formula to generate pseudo-random numbers.

# My first approach to numbers kingdom

I can clearly remember the day my mother gave me a CD of multiplication tables. I was 7 to 9 years old.

At first i was like meh, more homework.

I started repeating all the multiplications from 1 to 10, with this song i still got recorded on my mind. Once i completed listening the CD for the 20th time, i took a look at the back cover of the CD case.

This, I recognize, is my blowmind moment number one.

In all its splendor, all the tables available for me, in front of my eyes. I just took a leap to the first dive in the beautiful path of Numbers Theory.

Once i saw them, i immediately recognized the “9” pattern.

The “9” pattern is one of the most basic tricks we can show kids to teach them about patterns.

“Write all the multiples of 9, from 1 to 10. All the tens are going to increase 1 on every step, and all the units are going to decrease 1 step with every step:

09, 18, 27, 36, 45, 54, 63, 72, 81, 90”

BOOM! There was me. Astonished. Completely amazed of what i was sure was going to change the history of human kind (trust me, i used to daydream like this).

How was it possible? Is there any kind of magic behind the numbers? Some kind of pattern which governs the numbers? Ok, not this exact words, but kind of but told by a 9 years old kid.

I know, there’s no magic in this. Adding 9 to any number is literally adding 10–1, which increase tens by 1 and decrease units by 1.

Immediately after, i jumped to the other numbers of the decimal base.

I started to see what was the pattern present in the unit numbers, to see how they behave.

The number 2 and it powers have a pretty plane pattern :

- 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30…

Multiples of 3 were a little bit funnier to analize:

- 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36 …

Multiples of 5 were kind of binary:

- 5, 10, 15, 20, 25, 30 …

But among all them, the 7 was the one who looked pretty messy with it behavior:

- 7, 14, 21, 28, 35, 42, 49, 56, 63, 70

Can you see it? If we take just the last digit of every multiple:

- 7,4,1,8,2,9,6,3,0,7…..

Well, maybe is not clear enough, but for me was a total discover.

Since that day, I began to love this number.

# The magic and beautiful 7

As a Chilean, the best grade I could have at the school was a 7. It was pretty tricky to calculate a performance in base or that number. I mean, if instead of 7 the base was a 10, it would be straight forward; a 3 means a 30%, a 6 means a 60% and a 9 means a 90%. Same case with 2, 4, 5, or 8. 1/2 = 50%, 3/4 = 75%, 3/5 = 60%, 7/8 =87,5%.

When i obtained a 4 over 7, for instance, the result wasn’t a «closed number», it was a 4/7=0,571428 = 57,1428….%, and the same with the other results. I asked a lot of people why we use 7 as the highest grade, no body knows.

I started to look up for an explanation for this «weird behavior». Was there when i started this game of comparing the behavior of the first 9 decimals below any power of 10.

Yes, i swear I have this kind of games when I was a child, I already told that my mind was thirsty of responses.

How many numbers can «reach» a power of 10? Ever standing on the natural numbers kingdom.

1,2,4,5,8 where the candidates to achieve this :

- 1 x 10 = 10
- 2 x 5 = 10
- 4 x 25 = 100
- 5 x 2 = 10
- 8 x 125 = 1000

What about 3,6,7,9?

- 3 x 3 = 9
- 3 x 33 = 99
- 3 x 333 = 999

The 3 was doomed to never achieve it. Same case with 9, poor numbers :(.

The 6 case:

- 6 x 1 = 6
- 6 x 16 = 96
- 6 x 166 = 996
- 6 x 1666 = 9996

But the 7, OH BOY,the 7 was a case itself:

- 7 x 1 = 7
- 7 x 14 = 98
- 7 x 142 = 994
- 7 x 1428 = 9996
- 7 x 14285 = 99995
- 7 x 142857 = 999999
- 7 x 1428571 = 9999997

The difference between a power of 10 and a multiple of 7, differently from the other numbers, followed a strange sequence:

- 10–7=3
- 100–98=2
- 1000–994=6
- 10000–9996=4
- 100000–99995=5
- 1000000–999999=1
- 10000000–9999997=3 …

This differences followed the sequence: 326451326451…., i.e. a sequence with a PERIOD OF 6.

This was happening while i was like 12 years old, and what my innocent mind was unconscious that i was studying the period of the number 7, or the period of it inverse to be precise, and the sequence i was marveled about was the rest of a power of 10 and the multiple of 7.

This is 1/7=0.1428571…, which have a period of 6, and is exactly the same sequence as getting the “closest multiple of 7 to 10^7, 7 x 142857 = 999999”.

The number had me fascinated. I thought something magic was happening in front of me. At that young age, i wasn’t capable of realize that wasn’t magic, just mathematics in it most pure expression.

I started to look up for other patterns of the number 7, which led me to be really fast at calculating it multiples. I asked my classmates to challenge me: tell a number between 1 and 10000 and instantly I’ll tell you what’s the result of multiplying it by 7.

# The moment the planets lined up

Years later, 12/09/2016 to be exact and with 28 years, i was recalling how obsessed I was about the number 7.

To that date i already realized what i mentioned lines above; inverse of 7 have a period of 6, and the numeric sequence was the list of rest between a multiply of 7 and it closest power of 10.

I was wondering “what kind of characteristic i already haven’t tried to test about the number 7?”

Then it came to my mind as a meteorite:

7 is 3 numbers away to 10, what if it start looking up for the other numbers with a difference of 3 to it next power of 10?, e.g. 97, 997, 9997, 99997, 999997, 9999997.

## Checking the period

Naturally, i analyzed the period of them inverses, with the hypothesis that this numbers where the ones with the “highest period of every group”. I arranged them in groups of power of 10, or logarithmic scale.

At this point i was coursing my 6th university year of Electronic Civil Engineering, Universidad Técnica Federico Santa María, Chile. Mathematics was part of my routine.

For the first group:

1–10: 1/7 have a period of 6, which accomplish the hypothesis.

10–100: 1/97 was the one with the highest period, 96 to be exact.

100–1000: 1/997 wasn’t the one with the highest period. It period was 166 and, for instance, 1/983 has a period of 982.

This way, the test was fatally taken down.

I was a little disappointed, but then saw something that was really impressive, as much as when I discovered ‘the sequence of the number 9’.

## First approach to my discover

After realizing that my first hypothesis wasn’t correct, I tried another tests which failed too. It wasn’t too late that September 12th, but i was tired. Anyway, I kept lookin the rest of the candidates to check if something interesting happens with them. I used WolframAlpha to get as much information as I can from that numbers. I passed from 1/997 to 1/9997, and then to 1/9997, but periods weren’t following any pattern.

Was then that I realized something «tricky» about the result of this divisions:

No doubt, there’s a sequence on the field «Decimal approximation». For those who still don’t see it, let’s take the result of 1/9997, and separate every part of the sequence:

0.0001–0003–0009–0027–0081–0243–0729–2187…… and so on. There’s a power of 3^n in every n digits of the decimal number.

So, there i was, astonished as is was when i discovered «the 9 sequence». First thing i tried to do was to translate what i discovered into a formula.

This was the first version:

YES! There is it, a beautiful formula to express what i identified as a sequence.

## Final version of the formula

After watching it for a while and try different «lengths» (1/99997, 1/999997, 1/9999997), the brick hit my head.

“Divisor can be written as 1/(10^n-3), and the result can be divided in «chunks» of n digits with 3^n values.

What if i do 1/(10^n-X), being X whatever number i want?”

I remember that i honored my love for number 7, replacing the 3 in the formula for a 7, so:

YES!!!! Exactly as with number 3, 7^n for every n digits.

Which formula is indeed:

It was working like a charm!. Only thing i needed to do, was to parameterize it. Of course I probe with every number that occurred to me, and they all worked.

In an action guided in one half by the emotion and in another half by knowing that what i was discovering could be important, i decided to baptize this formula from my initials; M(b,n,mu). (M)atías (B)arrios (N)úñez, mu is because is greek M. The final form for my formula:

YES, there was, a beautiful formula of my work.

I could barely sleep, excited for what i thought was something particularly useful, but still don’t know why.

First thing i did next day was to go to my university and start asking teachers about what i discovered. Most of them were amazed but it was kind of something interesting or anecdotal instead of useful. I remember that one of them told me:

” What you have there is an interesting work of Number Theory. Congratulations, but unfortunately it is not my field.” -Werner Creixell, UTFSM Teacher.

That was the first time i heard of “Number Theory”, and after reading about it later, i realized that my “games of looking up for sequences and patterns” was nothing but a very basic level of it.

# About my work today

Today, (September 12, 2018) i’m celebrating two years since the day i stated this formula. I tweeted about it to remember what is for me one of the most significant discoveries of my life:

Since then i started to develop some interesting stuff with what today i understand is a *Pseudo-Random Number Generator, PRNG.*

Fortunately, my specialty on distributed systems and IoT and my passion about Cybersecurity and Number Theory led me to start studying about Cryptography.

Nowaday, i already developed a symmetric encryption method of low computational cost, a *2 Factor Authentication Method* and a *Message Authentication Code* *Method*. I applied them all to my thesis, which is a work of *Design and implementation of a bike parking network operated through cellphone.*

This is the first time published something about this invention, mainly because I was afraid someone would “steal my idea”.

Today, i’m convinced it can help to develop some marvelous things, and what I really fear is that this invention never sees the light.

Please feel free to share, to give me some claps, to tell me your opinions and to use my PRNG. You can continue reading about it on it paper.

Thanks for reading my history. I hope this is just the first step of something greater.

I can’t finish this article without mentioning the IoT Manifesto. Is a good and inspiring design guide to develop sustainable IoT solutions, exactly what the world needs now, and what i’m going to follow from now on.

If you’re going to use my PRNG, please have it in mind.