While trying to come up with simple ways to do pattern recognition and prediction, I figured that I might as well start at the very basic concept of the fact that multiplication of natural numbers are the equivalent of adding the same number multiple times. So when you say 3 * 5, you’re also saying 5 + 5 + 5.
Similarly, but slightly more involved, is that you can for example figure out the square of 5 by rewriting it to multiplication and subsequently rewriting the multiplications by addition. So when you’re saying 5², you’re also saying 5 * 5, and thus also 5 + 5 + 5 + 5 + 5.
You can repeat these processes with all natural number powers as well. Say 3³, which would be 3 * 3 * 3, which is the same as (3 + 3 + 3) * 3, etcetera.
This concept gives you the freedom to zoom in to parts of a certain sequence of numbers and spot patterns by only knowing about addition. Basically reversing the process.
Take a linear sequence like f(x)=x*3, where the answers would be [3,6,9,12,15,…]. By splitting up every 2 numbers, you can see (by subtracting the numbers) that every next number is calculated by adding 3 to the current number. This would reasonably lead you to be able to predict that the number after 15 will be 18.
Since these numbers have a linear relation to their predecessors, a really simple way to program a prediction for this would be to check the difference between all numbers next to each other, and if the difference is always the same, add that number to the last number.
Take a sequence of numbers for f(x)=x³, for example the first range where x goes from 1 to 5 are [1, 8, 27, 64, 125], and the 6th number in that sequence will be 216, because 6³=216.
This sequence doesn’t have any numbers that are linearly related to each other. But by going back to the concept of zooming in and reverse engineering the numbers to basic additions, you can find the lowest common additions and patterns in this sequence of numbers.
In short; what you do is calculate the differences between two adjacent numbers of the sequence and repeat the process to calculate the differences between the previous differences you got, until you can no longer do so. (You can stop earlier when you spot linear patterns)
What you get with this iterative process is a sort of pyramid that you can use to duplicate the additions to calculate the next number in the sequence.
So the pyramid for the sequence [1,8,27,64,125] would be
L0 1 8 27 64 125 L1 7 19 37 61 L2 12 18 24 L3 6 6 L4 0
You can see that on the lower level (L3) of the pyramid eventually you’ll be able to spot a linear pattern. The less numbers you have, the less chance you’ll be able to see it, but with this sequence of numbers, we can.
If we had only 4 of the numbers, we would predict correctly (though it would probably be more of a guess), but 3 numbers would not be enough. With just 3 numbers we wouldn’t be able to spot a linear correlation between the numbers at all.
Depending on the pattern there are limits to what this method can do, but if your sample-size isn’t big enough, no other method would work either.
Extending the pyramid
To calculate our 6th number, what we do is use addition to climb from our L4 of the pyramid back to our original level L0. Just like when we would try to calculate 4 * 5 from the first example by taking what we know, namely 3 * 5, and adding 5 to it.
We only need the last numbers of every pyramid layer in this case (so [0,6,24,61,125), and add the number that we calculated on the previous level of the pyramid.
L4: 0 + 0 = 0 L3: 6 + 0 = 6 L2: 24 + 6 = 30 L1: 61 + 30 = 91 L0: 125 + 91 = 216
And there we have our answer.