(nothing to do with Al Gore’s Rhythm)
Maths is all about following instructions to the tee and that set of rules (or instructions or actions or recipe) is called an algorithm. Action computer games or apps are all about learning how to progress along a scrolling screen, jumping over obstacles, collecting rewards etc. I am always amazed at how easily kids learn to play them and how enjoyable they find them. The steps are a mathematical algorithm which allows you to get to the end of the screen. We normally learn the algorithm by brute force, or in other words trial and error. If we make a mistake we learn not to do it again and try a different method. Kids will play with these, learning many thousands of steps that they repeat essentially without thinking – wow! Perhaps maths needs to be “taught” in this way.
And yet what happens if children are asked to complete a maths work sheet which only has a few steps to remember? Instant rewards of flashing lights, colourful characters and sounds make all the difference. So we probably need to review the way we approach maths with kids. Kids and adult people generally love algorthims until we make them boring. It’s a bit like learning music by memorising a long string of notes without hearing the result. Perhaps maths needs to be a spectator sport first and if you start to enjoy it then you may want to be a participant.
Cooking – using a basic algorithm
Following a recipe is possibly the most common personal use of an algorithm. We have a set of ingredients and we perform a series of operations on these ingredients. While there may not be a correct solution there are obviously optimal outcomes depending on your taste.
We could write an algorithm for making cheese toast in a mathematical type notation.
(bread + spread + cheese) x heat.
Here we have a number of operations performed on various items. We could have different styles of bread which we might summarise as b etc giving us a simpler notation.
(b+s+c) x h where b might stand for any sort of bread.
We can make the algorithm into an equation (or formula) by giving it a result.
(b+s+c) x h = CT (cheese toast)
We can then substitute our favourite items into the equation to make it specific.
(Sourdough slice + butter + edam) x grill = Grilled edam cheese sourdough toast.
And that’s about all there is to maths! How can this be hard?
Other real and virtual algorithms
There are many other processes (physical, chemical, biological and geological) that we can observe and describe as algorithms. There are also many that we have invented and use regularly (steel making, refining oil, making smart phones). Some processes depend on the order of operations and some don’t. In our cheese toast example we need the right order – put butter on bread, then cheese then heat the whole lot. You might get a different useful result by following a different order – heat bread, add cheese and butter.
In maths then, the order of operations is critical and it’s best to put brackets around things to specify this. Other than that, we work from higher order to lower and left to right for equal order (Powers and roots) then (multiplication and division) then (addition and subtraction). This old rule was called BODMAS (bracket, of, division, multiplication, addition, subtraction), or more likely these days as PEMDAS (with parentheses and exponents substituted).
Maths is like an abstract version of the algorithm we looked at. Our things are numbers (or perhaps letters substituting for “any number”) and our operators can be as varied as the real world (or even more so with no physical constraints).
Another operator which we touched on previously was the derivative. We saw that the rate of change of velocity with time is called the derivative of velocity and it is the same as acceleration. dV/dt = a. In reverse we say that velocity is the integral of acceleration with time v = ∫ a dt. Again don’t get too concerned about these concepts, just accept for now.
With the advent of digital computers, the internet and social media algorithms are taking over. Computers run on algorithms. They are the instructions we give to computers and are often called code. An example is given below.
The code often contains loops where the same instruction is performed over and over (iterated) until some conclusion is reached and then a new instruction commenced. These loops eventually produce a desired result and may become a sub routine which can be incorporated into a larger routine. When these are strung together they become a program or application (app). The first computer program ever written (as far as is known) was in the 1840s by Ada Lovelace.
Today we run apps on a very regular basis including for social media. It has become our way of communicating with others, possibly more so than by phone. The social media companies now run complex algorithms to determine the big picture of how we communicate, the things we like and the best way to advertise to us. Each time you like or share or copy on these apps your moves are reviewed, at least statistically, with these data being very valuable to advertisers and others. If you share a page FB can keep tabs on the sharing and prevent scams and overboard advertising to some degree. If you copy and paste they do not – hence the proliferation of “if you love me then copy and paste this article” scams.
There are lots of apps these days that will help to teach you to code for fun. These are becoming more and more popular with kids. BBC have recently launched a cheap mini computer especially for this called the BBC Micro Bit. Look these up on the internet and have a play – and encourage your kids to do it.
We have had a quick look at the “beautiful equation”, but now it’s time for “the algorithm which runs the world” (at least according to New Scientist in 2012). The Simplex Algorithm was discovered as an optimisation routine for linear programming in 1947. It essentially draws straight lines as boundaries on a 2D (or multi dimensional) graph to show limits to various inputs and where these intersect is the optimal position. It can be used to determine maximum profit for least input of cash, staff and time for example. It can also determine the best route for trucks to take when delivering parcels or best profits within defined risks on the share market. It is estimated that the routine is run many thousands of times a minute all over the world’s computers!
Other very useful algorithms are the Sorting algorithm and the Fast Fourier Transform (FFT). The first sorts data into whatever order you would like (look up sorting algorithm animation to see some in action) and the second is of great value in signal processing. Like the Euler equation it can be used to break down a complex waveform into its component parts and allows it to be transformed from a space domain to a frequency domain (for example) so it can be filtered and manipulated digitally.
You may remember the quadratic equation from school. This equation takes the form
This algorithm (or formula) solution to the quadratic was discovered in 820 AD by Al-Kharizmi, the man that gave us the word algorithm. The parabola shape is of this form and the solution (or roots) of the equation are the spots where the quadratic crosses the zero on the y axis (vertical) – the two values in red. This graphical solution can also be used to solve quadratics.
Don’t sweat the detail. We will come back to this next time.
The oldest and possibly most well known is the Euclidean algorithm, written up by Euclid in is book, the Elements in about 300BC. This algorithm shows the way to find the largest number that divides into any two given numbers. To this day it is still the best algorithm we have for doing this!
Amazing what those old mathematicians could come up with. Today the various branches of mathematics and computing that look for algorithmic solutions to problems are called numerical methods or numerical analysis. They are all about step by step methods to allow solutions to various equations to be determined. In the Hidden Figures example, numerical analysis methods were devised to allow computers to calculate flight paths. These early computers had severe memory issues and were often not as accurate as doing the calculations by hand. Today’s smartphones have no such problem with many apps regularly solving complex equations using numerical analysis to give very accurate results.
As a tool for mathematics algorithms do us a great service. As a manipulation tool for advertisers and marketers they need to be controlled! New fangled genetic algorithms (self learning optimisation routines) are the face of modern Artificial Intelligence (AI) and will be dealt with later. We will also look at neural networks, which are fancy routines based on how our brain works.