Can you work out how to draw a perfect square with only a straight edge and compass. That is the sort of challenge the Ancient Greek Mathematician Euclid set himself. You need to devise an algorithm to do it – a sequence of steps that guarantee you end up with a square.
Try it before you read on. It is a fairly simple algorithm but one where, as we will see, decomposition can help – break it up into two simpler tasks and so algorithms.
Here for starters is my full algorithm for drawing a square. It does give you a square, but it is hard to follow and it was just as hard to work out. I kept getting confused with which circle was which, and being sure what we did really was what I intended…what a nightmare.
- Draw a circle with radius AB centred on A, a point on a line to give a point B where line and circle cross.
- Draw a circle with radius AB centred on point B. This gives two points C and D where the circles cross.
- Draw a line through C and D. This is now at right angles to the original line. This gives a new point E where the two lines cross.
- Draw a circle with radius EC, centred on E. This gives a new point F where the circle crosses the original line in the circle.
- Draw a circle radius EF centred on F.
- Draw a circle radius EF centred on C, to make a new point G where this circle crosses the previous circle.
- Draw a line FG
- Draw a line GC
- You have a perfect square CEFG.
Phew! Hope I didn’t make a mistake.
Here is a much simpler version, that makes it clearer what is going on. It uses exactly the same steps ultimately.
- Draw a right-angled triangle
- Draw an identical right-angled triangle on the original’s longest side.
It works because a square is just two right angled triangles back to back. To solve the problem this way you have to just work out algorithms for those two simpler problems. If you rub out all the working lines and circles in between the steps then it will also be much easier to see what you are doing and that it is correct.
See if you can work out these two algorithms yourself. (Our versions are to coming soon)
Decomposing a complicated task in to clear, smaller tasks like this and then devising algorithms for them is the basis of how we now write complex software. It is a way of managing the complexity so that solving complex problems is no harder than solving the simpler problems.