Today we’re going to take a step back from programming and discuss the person who formulated many of the theoretical concepts that underlie modern computation - the father of computer science himself: Alan Turing. Now normally we try to avoid “Great Man" history in Crash Course because truthfully all milestones in humanity are much more complex than just an individual or through a single lens - but for Turing we are going to make an exception. From his theoretical Turing Machine and work on the Bombe to break Nazi Enigma codes during World War II, to his contributions in the field of Artificial Intelligence (before it was even called that), Alan Turing helped inspire the first generation of computer scientists - despite a life tragically cut short. Special thanks to Contributing Writer Robert Xiao whom we should have (and forgot) to include in the credits. His help with this episode was invaluable.
Hi, I'm Carrie Anne and welcome to Crash Course Computer Science.
Over the past few episodes we've been building up our understanding of computer science fundamentals,
such as functions, algorithms and data structures. Today we're going to take a step back and look
at the person who formulated many of the theoretical concepts that underline modern
computation. The father of computer science and not quite Benedict Cumberbatch lookalike, Alan Turing.
Alan Matheson Turing was born in London in 1912 and showed an incredible aptitude for
maths and science throughout his early education. His first brush with what we now call computer
science came in 1935, while he was a master's student at King's College in Cambridge.
He set out to solve a problem posed by German mathematician David Hilbert,
known as the Entscheidungsproblem, or decision problem, which asked the following.
Is there an algorithm that takes as input a statement written in formal logic
and produces a yes or no answer that's always accurate?
If such an algorithm existed, we could use it to answer questions like,
Is there a number bigger than all numbers? No there's not, we know the answer to that one,
but there are many other questions in mathematics that we'd like to know the answer to.
So if this algorithm existed, we'd want to know it.
The American mathematician Alonzo Church first presented a solution to this problem in 1935.
He developed a system of mathematical expressions called lambda calculus,
and demonstrated that no such universal algorithm could exist.
Although lambda calculus was capable of representing any computation,
the mathematical technique was difficult to apply and understand.
At pretty much the same time on the other side of the Atlantic,
Alan Turing came up with his own approach to solve the decision problem.
He proposed a hypothetical computing machine, which we now call a Turing machine.
Turing machines provided a simple yet powerful mathematical model of computation.
Although using totally different mathematics,
they were functionally equivalent to lambda calculus in terms of their computational power.
However, their relative simplicity made them much more popular
in the burgeoning field of computer science.
In fact, they're simple enough that I'm going to explain it right now.
A Turing machine is a theoretical computing device,
equipped with an infinitely long memory tape, which stores symbols,
and a device called a read-write head, which can read and write, or modify, symbols on that tape.
There's also a state variable, in which we can hold a piece of information
about the current state of the machine,
and a set of rules that describes what the machine does,
given a state and the current symbol the head is reading.
The rule can be to write a symbol on the tape, change the state of the machine,
move the read-write head to the left or right by one spot, or any combination of these actions.
To make this concrete, let's work through a simple example.
A Turing machine that reads a string of 1s ending in a 0,
and computes whether there is an even number of 1s.
If that's true, the machine will write a 1 to the tape, and if it's false, it'll write a 0.
First, we need to define our Turing machine rules.
If the state is even, and the current symbol on the tape is 1,
then we update the machine's state to odd, and move the head to the right.
On the other hand, if the state is even, and the current symbol is 0,
which means we've reached the end of the string of 1s,
then we write 1 to the tape and change the state to halt,
as in we're finished, and the Turing machine has completed the computation.
We also need rules for when the Turing machine is in an odd state.
One rule for when the symbol on the tape is a 0, and another for when it is 1.
Lastly, we need to define a starting state, which we'll set to be even.
Now that we've defined the rules and the starting state of our Turing machine,
which is comparable to a computer program, we can run it on some example input.
Let's say we store 110 onto tape.
That's two 1s, which means there is an even number of 1s.
And if that's news to you, we should probably get working on Crash Course Math.
Notice that our rules only ever move the head to the right,
so the rest of the tape is irrelevant. We'll leave it blank for simplicity.
Our Turing machine is all ready to go, so let's start it.
Our state is even, and the first number we see is a 1.
That matches our topmost rule, and so we execute the effect,
which is to update the state to odd, and move the read-write head to the right by one spot.
Okay, now we see another 1 on the tape, but this time our state is odd,
and so we execute our third rule, which sets the state back to even,
and moves the head to the right.
Now we see a 0, and our current state is even, so we execute our second rule,
which is to write a 1 to the tape, signifying that yes, it's true,
there is an even number of 1s. And finally, the machine halts.
That's how Turing machines work. Pretty simple, right?
So you might be wondering why they're such a big deal.
Well, Turing showed that this simple hypothetical machine can perform any computation,
if given enough time and memory. It's a general-purpose computer.
Our program was a simple example, but with enough rules, states, and tape,
you could build anything. A web browser, World of Warcraft, whatever.
Of course, it would be ridiculously inefficient, but it is theoretically possible.
And that's why, as a model of computing, it's such a powerful idea.
In fact, in terms of what it can and cannot compute,
there's no computer more powerful than a Turing machine.
A computer that is as powerful is called Turing Complete.
Every modern computing system, your laptop, your smartphone,
and even the little computer inside your microwave and thermostat, are all Turing Complete.
To answer Hilbert's decision problem, Turing applied his new Turing machines
to an intriguing computational puzzle, the halting problem.
Put simply, this asks, is there an algorithm that can determine,
given a description of a Turing machine and the input from its tape,
whether the machine will run forever or halt?
For example, we know our Turing machine will halt when given the input 110,
because we literally walked through the example until it halted.
But what about a more complex problem?
Is there a way to figure out if a program will halt without executing it?
Some programs might take years to run, so it would be useful to know before we run it,
and wait, and wait, and wait, and then start getting worried and wonder,
and then decades later, when you're old and grey, CTRL-ALT-DELETE with so much sadness.
Unfortunately, Turing came up with a proof that shows the halting problem was, in fact,
unsolvable, through a clever logical contradiction.
Let's follow his reasoning.
Imagine we have a hypothetical Turing machine that takes a description of a program
and some input for its tape, and always outputs either yes, it halts, or no, it doesn't.
I'm going to give this machine a fun name, H for HALT.
Don't worry about how it works, let's just assume such a machine exists.
We're talking theory here.
Turing reasoned that if there existed a program whose halting behavior was not
decidable by H, it would mean the halting problem is unsolvable.
To find one, Turing designed another Turing machine that built on top of H.
If H says the program halts, then we'll make our new machine loop forever.
If the answer is no, it doesn't halt, we'll have the new machine output a no and halt.
In essence, we're building a machine that does the opposite of what H says,
halt if the program doesn't halt, and run forever if the program halts.
For this argument, we'll also need to add a splitter to the front of our new machine,
so that it accepts only one input, and passes that as both the program and input into H.
Let's call this new machine Bizarro.
So far, this seems like a plausible machine, right?
Now, it's going to get pretty complicated, but bear with me for a second.
Look what happens when you pass Bizarro a description of itself as the input.
This means we're asking H what Bizarro will do when asked to evaluate itself.
But if H says Bizarro halts, then Bizarro enters its infinite loop, and thus doesn't halt.
And if H says Bizarro doesn't halt, then Bizarro outputs a no and halts.
So H can't possibly decide the halting problem correctly, because there is no answer.
It's a paradox.
And this paradox means that the halting problem cannot be solved with Turing machines.
Remember, Turing proved that Turing machines could implement any computation.
So this solution to the halting problem proves that not all problems can be solved by computation.
Wow, that's some heavy stuff.
I might have to watch that again myself.
Long story short, Church and Turing showed that there were limits to the ability of computers.
No matter how much time or memory you have,
there are just some problems that cannot be solved.
Ever.
The concurrent efforts by Church and Turing to determine the limits of computation,
and in general, formalize computability, are now called the Church-Turing thesis.
At this point in 1936, Turing was only 24 years old.
And really, only just beginning his career.
From 1936 through 1938, he completed a PhD at Princeton University, under the guidance of Church.
Then after graduating, he returned to Cambridge.
Shortly after, in 1939, Britain became embroiled in World War II.
Turing's genius was quickly applied to the war effort.
In fact, a year before the war started, he was already working part-time
at the UK's Government Code and Cipher School,
which was the British code-breaking group based out of Bletchley Park.
One of his main efforts was figuring out how to decrypt German communications,
especially those that used the Enigma machine.
In short, these machines scrambled text, like you'd type the letters H-E-L-L-O,
and the letters X-W-D-B-J would come out.
This process is called encryption.
The scrambling wasn't random.
The behavior was defined by a series of reordable rotors on the top of the Enigma machine,
each with 26 possible rotational positions.
There was also a plugboard at the front of the machine that allowed pairs of letters to be swapped.
In total, there were billions of possible settings.
If you had your own Enigma machine, and you knew the correct rotor and plugboard settings,
you could type in X-W-D-B-J, and Hello would come out.
In other words, you decrypted the message.
Of course, the German military wasn't sharing their Enigma settings on social media,
so the Allies had to break the code.
With billions of rotor and plugboard combinations, there was no way to check them all by hand.
Fortunately for Turing, Enigma machines and the people who operated them were not perfect.
Like, one key flaw was that a letter would never be encoded as itself.
As in, an H was never encrypted as an H.
Turing, building on earlier work by Polish codebreakers,
designed a special-purpose electromechanical computer called the BOM,
that took advantage of this flaw.
It tried lots and lots of combinations of Enigma settings for a given encrypted message.
If the BOM found a setting that led to a letter being encoded as itself,
which we know the real Enigma machine couldn't do, that combination was discarded.
Then the machine moved on to try another combination.
So, BOMs were used to greatly narrow the number of possible Enigma settings.
This allowed human codebreakers to hone their efforts on the most probable solutions,
looking for things like common German words in fragments of decoded text.
Periodically, the Germans would suspect someone was decoding their communications,
and upgrade the Enigma machine.
Like, they'd add another rotor, creating many more combinations.
They even built in tiny new encryption machines.
Throughout the war, Turing and his colleagues at Bletchley Park
worked tirelessly to defeat these mechanisms.
And overall, the intelligence gained from decrypted German communications
gave the Allies an edge in many theatres.
With some historians arguing it shortened the war by years.
After the war, Turing returned to academia,
and contributed to many early electronic computing efforts,
like the Manchester Mark I, which was an early and influential stored-program computer.
But his most famous post-war contribution was to artificial intelligence,
a field so new that it didn't even get that name until 1956.
It's a huge topic, so we'll get to it again in future episodes.
In 1950, Turing could envision a future where computers were powerful enough
to exhibit intelligence equivalent to, or at least indistinguishable from, that of a human.
Turing postulated that a computer would deserve to be called intelligent
if it could deceive a human into believing that it was human.
This became the basis of a simple test, now called the Turing Test.
Imagine that you are having a conversation with two different people,
not by voice or in person, but by sending type notes back and forth.
You can ask any questions you want, and you get replies.
But one of those two people is actually a computer.
If you can't tell which one is human and which one is a computer,
then the computer passes the test.
There's a modern version of this test, called a Completely Automated Public Turing Test,
to tell computers and humans apart, or CAPTCHA for short.
These are frequently used on the internet to prevent automated systems
from doing things like posting spam on websites.
I'll admit, sometimes I can't read what those squiggly things say.
Does that mean I'm a computer?
Normally in this series, we don't delve into the personal lives of these historical figures.
But in Turing's case, his name has been inextricably tied to tragedy,
so his story is worth mentioning.
Turing was gay in a time when homosexuality was illegal in the United Kingdom,
and much of the world.
An investigation into a 1952 burglary at his home revealed his sexual orientation
to the authorities, who charged him with gross indecency.
Turing was convicted and given a choice between imprisonment
or probation with hormonal treatment to suppress his sexuality.
He chose the latter, in part to continue his academic work,
but it altered his mood and personality.
Although the exact circumstances will never be known,
it's most widely accepted that Alan Turing took his own life, by poison, in 1954.
He was only 41.
Many things have been named in recognition of Turing's contributions
to theoretical computer science,
but perhaps the most prestigious among them is the Turing Award,
the highest distinction in the field of computer science,
equivalent to a Nobel Prize in physics, chemistry, or other sciences.
Despite a life cut short, Alan inspired the first generation of computer scientists,
and laid key groundwork that enabled the digital era we get to enjoy today.
I'll see you next week.