On June 8, 1954, Alan Turing, a forty-one-year-old research scientist at Manchester University, was found dead by his housekeeper. Before getting into bed the night before, he had taken a few bites out of an apple that was, apparently, laced with cyanide. At an inquest, a few days later, his death was ruled a suicide. Turing was, by necessity rather than by inclination, a man of secrets. One of his secrets had been exposed two years before his death, when he was convicted of “gross indecency” for having a homosexual affair. Another, however, had not yet come to light. It was Turing who was chiefly responsible for breaking the German Enigma code during the Second World War, an achievement that helped save Britain from defeat in the dark days of 1941. Had this been publicly known, he would have been acclaimed a national hero. But the existence of the British code-breaking effort remained closely guarded even after the end of the war; the relevant documents weren’t declassified until the nineteen-seventies. And it wasn’t until the eighties that Turing got the credit he deserved for a second, and equally formidable, achievement: creating the blueprint for the modern computer.

It is natural to view Turing as a gay martyr, hounded to death for his sexuality despite his great service to humanity. But it is also tempting to speculate about whether he really was a suicide. The flight to Moscow, in 1951, of Guy Burgess and Donald Maclean, British diplomats and rumored lovers who had been covertly working for the Soviets, prompted one London newspaper to editorialize that Britain should adopt the American policy of “weeding out both sexual and political perverts.” Turing’s role in wartime code-breaking had left him with an intimate knowledge of British intelligence. After his conviction for homosexuality, he may have seemed out of control. He began travelling abroad in search of sex, visiting countries bordering on the Eastern bloc. The coroner at his inquest knew none of this. No one tested the apple found by his bedside for cyanide.

The possibility of clandestine assassination is hinted by the title of David Leavitt’s short biography, “The Man Who Knew Too Much: Alan Turing and the Invention of the Computer” (Norton/Atlas; $22.95), borrowed from the Hitchcock thriller. Leavitt, the author of several novels and short-story collections with gay protagonists, rings the gay-martyr theme in the book’s opening pages by invoking another film classic, “The Man in the White Suit.” In that 1951 comedy, which Leavitt reads as a gay allegory, a scientist is chased by a mob that feels threatened by a miraculous invention of his. Then a third film is mentioned, one that evidently made an impression on Turing: the 1937 Disney animation “Snow White and the Seven Dwarfs.” Those who knew him said that he was particularly fond of chanting the witch’s couplet, “Dip the apple in the brew, / Let the sleeping death seep through.” So we’re prepared for a life story that, though steeped in logic and mathematics, is part mystery, part parable of sexual politics, part fairy tale.

Alan Mathison Turing was conceived in India, where his father worked in the Indian civil service, and born in 1912 during a visit by his parents to London. Instead of taking their child back to the East, they sent him to live with a retired Army couple in a seaside English town. Alan was a good-looking boy, dreamy, rather clumsy, hopelessly untidy, and not very popular with his classmates. The loneliness of his childhood was finally dispelled when, in his early teens, he met another boy who shared his passion for science. They became inseparable friends, exploring esoterica like Einstein’s relativity theory together. When, a year later, the boy died of tuberculosis, Turing seems to have been left with an ideal of romantic love that he spent the rest of his life trying to duplicate.

In 1931, Turing entered Cambridge. His college, King’s, “had a very ‘gay’ reputation,” Leavitt notes, and was known for its links to the Bloomsbury group. Turing’s unworldliness kept him apart from the aesthetic set; he preferred the more Spartan pleasures of rowing and long-distance running. But Cambridge also had a rich scientific culture, and Turing’s talents flourished in it. With the backing of John Maynard Keynes, he was elected a Fellow of King’s College in 1935, at the age of twenty-two. When the news reached his old school, the boys celebrated with a clerihew: “Turing / Must have been alluring / To get made a don / So early on.” With a stipend, no duties, and High Table dining privileges, he was free to follow his intellectual fancy. That spring, attending lectures in the foundations of mathematics, he was introduced to a deep and unresolved matter known as the “decision problem.” A few months later, during one of his habitual runs, he lay down in a meadow and conceived a sort of abstract machine that settled it in an unexpected way.

The decision problem asks, in essence, whether reasoning can be reduced to computation. That was the dream of the seventeenth-century philosopher Gottfried von Leibniz, who imagined a calculus of reason that would permit disagreements to be resolved by taking pen in hand and saying, Calculemus—“Let us calculate.” Suppose, that is, you have a set of premises and a putative conclusion. Is there some automatic procedure for deciding whether the former entails the latter? Can you determine, in principle, whether a conjecture can be proved true or false? The decision problem calls for a mechanical set of rules for deciding whether such an inference is valid, one that is guaranteed to yield a yes-or-no answer in a finite amount of time. Such a method would be particularly useful to mathematicians, since it would allow them to resolve many of the conundrums in their field—like Fermat’s last theorem, or Goldbach’s conjecture—by brute force. That is why David Hilbert, who in 1928 challenged the mathematical community to solve the decision problem, called it “the principal problem of mathematical logic.”

Turing began by thinking about what happens when a human carries out a computation by means of a pencil, a scratch pad, and a set of mindless instructions. By ruthlessly paring away inessential details, he arrived at an idealized machine that, he was convinced, captured the essence of the process. The machine was somewhat homely in conception: it consists of an unending tape divided into squares (rather like an infinite strip of toilet paper). Over this tape a little scanner travels back and forth, one square at a time, writing and erasing 0’s and 1’s. The scanner’s action at any moment depends on the symbol in the square it is over and the state it is in—its “state of mind,” so to speak. There are only a finite number of states, and the way they link up what the scanner sees to what it does constitutes the machine’s program. (A typical line in a program would be something like “When the machine is in state A scanning 0, it will replace 0 by 1, move one square to the left, and then go into state B.”)

Turing was able to do some amazing things with his abstract devices, which soon became known as “Turing machines.” Despite their simple design, he showed, they could be made to perform all sorts of complicated mathematics. Each machine’s functioning, moreover, could be encapsulated in a single number (typically, a very long one), so that one machine could be made to operate on another by putting the number of the second machine on the tape of the first. If a machine were fed its own number, then it could operate on itself. Turing was thereby able to exploit something akin to the paradoxes of self-reference (“I am lying”) and show that certain sorts of Turing machines could not exist. For instance, there could be no Turing machine that, when fed with the program number of another machine, would decide whether that machine would eventually come to a halt in its computation or would grind on forever. (If there were such a machine, it could be tweaked into a Hamlet-like variant that would decide, in effect, “I will come to a halt if and only if I never come to a halt.”) But the halting problem, it turned out, was merely the decision problem in disguise. Turing was able to prove that no computing machine of the kind he envisaged could solve the decision problem. Reasoning could not be reduced to computation after all.

But the death of Leibniz’s dream turned out to be the birth of the computer age. The boldest idea to emerge from Turing’s analysis was that of a universal Turing machine: one that, when furnished with the number describing the mechanism of any particular Turing machine, would perfectly mimic its behavior. In effect, the “hardware” of a special-purpose computer could be translated into “software” and then entered like data into the universal machine, where it would be run as a program—the way, for example, the operating system on your laptop treats a word-processing program as data. What Turing had invented, as a by-product of his advance in logic, was the stored-program computer.

Turing was twenty-three when he dispatched the decision problem. Just as he was finishing his work, discouraging news reached Cambridge from across the Atlantic: a Princeton logician named Alonzo Church had beaten him to the punch. Unlike Turing, however, Church did not arrive at the idea of a universal computing machine; instead, he used a far more arcane construction known as the “lambda calculus.” Still, Turing decided that he might profit from studying with the more established logician. So he made his way to America, crossing the Atlantic in steerage and arriving in New York, where, he wrote to his mother, “I had to go through the ceremony of initiation to the U.S.A., consisting of being swindled by a taxi-driver.”

At Princeton, Turing took the first steps toward building a working model of his imaginary computer, pondering how to realize its logical design in a network of relay-operated switches; he even managed to get into a machine shop in the physics department and construct some of the relays himself. In addition to his studies with Church, he also had dealings with the formidable John von Neumann, who would later be credited with innovations in computer architecture that Turing himself had pioneered. On the social side, he found the straightforward manners of Americans congenial, with certain exceptions: “Whenever you thank them for anything, they say ‘You’re welcome.’ I rather liked it at first, thinking I was welcome, but now I find it comes back like a ball thrown against a wall, and become positively apprehensive. Another habit they have is to make the sound described by authors as ‘Aha.’ They use it when they have no suitable reply to a remark.”

In 1938, Turing was awarded a Ph.D. in mathematics by Princeton, and, despite the urgings of his father, who worried about imminent war with Germany, decided to return to Britain. Back at Cambridge, he became a regular at Ludwig Wittgenstein’s seminar on the foundations of mathematics. Turing and Wittgenstein were remarkably alike: solitary, ascetic, homosexual, drawn to fundamental questions. But they disagreed sharply on philosophical matters, like the relationship between logic and ordinary life. “No one has ever yet got into trouble from a contradiction in logic,” Wittgenstein insisted. To which Turing’s response was “The real harm will not come in unless there is an application, in which case a bridge may fall down.” Before long, Turing would himself demonstrate that contradictions could indeed have life-or-death consequences.

On September 1, 1939, Nazi troops invaded Poland. Three days later, Turing reported to Bletchley Park, a Victorian Tudor-Gothic estate northwest of London where the British cipher service had secretly relocated. He and the other code-breakers arrived at Bletchley under the guise of “Captain Ridley’s Shooting Party” (which had some locals grumbling about able-bodied men not doing their bit in the war). The task they faced was daunting. Since the use of radio communications in the First World War, effective cryptography—insuring that private messages could be sent via a public medium—had been critical to the military. The Nazis were convinced that their encryption system—based on a machine that looked like a souped-up typewriter, called the Enigma—would play a vital role in their expected victory.

The Enigma, invented for commercial use in 1918 and soon adopted by the German military, had an alphabetic keyboard and, next to that, a set of twenty-six little lamps, one for each letter. When a letter on the keyboard was pressed, a different letter on the lampboard would light up. If you typed the letters “d-o-g,” the letters “r-l-u” might light up on the lampboard. When “rlu” was sent out in Morse code by a radio operator, a recipient would pick it up, type it on the keyboard of his Enigma machine, and the letters “d-o-g” would light up on the lampboard—so long as the settings of the two machines were the same. And that is where things get interesting. Inside the Enigma were a number of rotating wheels that determined the match between entered and coded letters; each time a letter was typed, one of the wheels would turn, altering the wiring. (Thus, if you typed “g-g-g,” the coded version might be “q-d-a.”) The military version of the Enigma also had something called a “plugboard,” by which the connections between letters could be further scrambled. The settings of the wheels and the plugboard were changed each day at midnight. And further layers of complexity were added, increasing the number of possible keys to something like a hundred and fifty quintillion.

The most impenetrable communications were those of the German Navy, which used the Enigma machine with special cunning and discipline. By early 1941, Germany’s growing U-boat fleet was devastating British shipping, sinking around sixty ships a month. Unlike Germany, Britain was almost completely reliant on the sea-lanes for sustenance. Unless some counter-strategy could be found, the British Isles faced being starved into submission. When Turing arrived at Bletchley Park, no work was being done on the naval Enigma, which many considered to be unbreakable. Indeed, it has been said, there were only two people who thought the Enigma could be broken: Frank Birch, the head of Bletchley’s naval-intelligence division, because it had to be broken; and Alan Turing, because it was an interesting problem.

Taking on the naval Enigma, Turing soon detected a weakness. A coded naval message would frequently contain formulaic bits, like WETTER FUER DIE NACHT (“weather for the night”), that might be guessed at. Such a “crib,” he realized, could be exploited to yield logical chains, each of which corresponded to billions of possible Enigma settings. When one of these chains led to a contradiction, the billions of settings to which it corresponded could be ruled out. Now the problem was reduced to checking millions of logical chains—daunting, to be sure, but not impossible. Turing set about devising a machine that would automate the search for logical consistency, eliminating contradictory chains rapidly enough for the code-breakers to deduce that day’s Enigma settings before the intelligence became stale. The result was the size of several refrigerators, with dozens of rotating drums (which mimicked the Enigma wheels) and massive coils of colored wire suggesting a Fair Isle sweater. In operation, it sounded like thousands of knitting needles clattering away, as its relay switches checked one logical chain after another. In a nod to an earlier, Polish code-breaking machine, which made an ominous ticking sound, the people at Bletchley called the thing a Bombe.

On a good day, a Bombe could yield that day’s Enigma key in as little as an hour, and, by 1941, eighteen Bombes were up and running. With the Nazi naval communications rendered transparent, the British could pinpoint the position of the U-boats, steering convoys safely around them and, taking the offensive, sending destroyers to sink them. Even as the Battle of the Atlantic began to shift, the German High Command refused to believe that the Enigma could have been broken, suspecting instead espionage and treachery.

As the Enigma evolved, Turing continued to devise new strategies to defeat it. Known at Bletchley as the Prof, Turing was famed for his harmless eccentricities, like keeping his tea mug chained to the radiator and wearing a gas mask as he rode his bicycle to work (it helped to alleviate his hay fever). He impressed his colleagues as a friendly, approachable genius, always willing to explain his ideas, and he became especially close to a woman he worked with, playing what he called “sleepy chess” with her after their night-shift code-breaking. Having convinced himself that he was in love with her, he proposed marriage, and was eagerly accepted, even after he divulged his “homosexual tendencies” to her. But he later decided it wouldn’t work and broke off the engagement. It seems to have been the only time in his life that he contemplated a heterosexual relationship.

By 1942, Turing had mastered most of the theoretical problems posed by the Enigma. Now that the United States was ready to throw its vast resources into the code-breaking effort, he was dispatched as a liaison to Washington, where he helped the Americans get their own Bombe-making and Enigma-monitoring under way. Then he headed to New York, where he was to work on another top-secret project, involving the encryption of speech, at Bell Laboratories, which were then situated near the piers in Greenwich Village. While at Bell Labs, he became engrossed with a question that came to occupy his postwar work: was it possible to build an artificial brain? On one occasion, Turing stunned the entire executive mess at Bell Labs into silence by announcing, in a typically clarion tone, “I’m not interested in developing a powerful brain. All I’m after is just a mediocre brain, something like the president of the American Telephone and Telegraph Company.”

Turing’s early work had raised a fascinating possibility: perhaps the human brain is something like a universal Turing machine. Of course, the brain looks more like cold porridge than like a machine. But Turing suspected that what made the brain capable of thought was its logical structure, not its physical embodiment. Building a universal Turing machine might thus be the way to erase the line between the mechanical and the intelligent.

In 1945, Turing wrote up a plan for building a computer which contained everything from the abstract structure down to the circuit diagrams and a cost estimate of eleven thousand two hundred pounds. At Britain’s National Physical Laboratory, where he worked after the war, he had nothing like the resources of the Americans, and yet he rose to the challenge posed by his straitened circumstances. When it came to the computer’s memory, for example, the most obvious storage device was one in which the data took the form of vibrations in liquid mercury. But Turing reckoned that gin would be just as effective, and far cheaper. On one occasion, he noticed a drainpipe lying in a field and had a colleague help him drag it back to the laboratory for use in his computer hardware. Frustrated with the inept administration at the N.P.L., he finally accepted an offer to direct the development of a computer prototype at Manchester University. Arriving in that grim Northern industrial city at the age of thirty-six, he found it “mucky” and noted that the Mancunian male wasn’t much to look at.

Despite his immersion in engineering details, Turing’s fascination with computing was essentially philosophical. “I am more interested in the possibility of producing models of the action of the brain than in the practical applications of computing,” he wrote to a friend. Turing conjectured that, initially, at least, computers might be suited to purely symbolic tasks, those presupposing no “contact with the outside world,” like mathematics, cryptanalysis, and chess-playing (for which he himself worked out the first programs on paper). But he imagined a day when a machine could simulate human mental abilities so well as to raise the question of whether it was actually capable of thought. In a paper published in the philosophy journal Mind, he proposed the now classic “Turing test”: a computer could be said to be intelligent if it could fool an interrogator—perhaps in the course of a dialogue conducted via teletype—into thinking it was a human being. Turing argued that the only way to know that other people are conscious is by comparing their behavior to one’s own, and that there is no reason to treat machines any differently.

To Leavitt, the idea of a computer mimicking a human inevitably suggests that of a gay man “passing” as straight. Here and elsewhere, he shows a rather overdeveloped ability to detect psychosexual significance. (When, in the Mind paper, Turing writes of certain human abilities that it is hard to imagine a machine developing, like the ability to “enjoy strawberries and cream,” Leavitt sees a “code word for tastes that Turing prefers not to name.”) But the book does succeed, on the whole, in giving a poignant depiction of Turing the man. And the bar was set pretty high. Two decades ago, a mathematician named Andrew Hodges published “Alan Turing: The Enigma,” which is one of the finest scientific biographies ever written, and has remained an essential resource for all subsequent accounts of Turing’s life. In 1987, Hugh Whitemore’s superb play about Turing, “Breaking the Code,” opened on Broadway, with Derek Jacobi in the starring role. Both of these works not only captured the pathos of Turing’s life; they also gave a lucid account of his technical achievement. (Whitemore’s play miraculously compressed the decision problem and the Enigma decoding into a couple of brief speeches without any real distortion.)

It is on the technical side that Leavitt falls short. His exposition, full of the sort of excess detail that mathematicians call “hair,” is marred by confusions and errors. In trying to describe how Turing resolved the decision problem, Leavitt gets wrong the central idea of a “computable number.” Discussing the earlier logical work of Kurt Gödel, Leavitt says that it established that the axiomatic system of Bertrand Russell and Alfred North Whitehead’s “Principia Mathematica” was “inconsistent,” when Gödel proved no such thing, and a definition of something called Skewes number is precisely backward. Although Leavitt seems to have made a valiant attempt to master this material in preparation for writing the book, his explanatory efforts will leave initiates irritable and beginners perplexed.

Turing lived for the remainder of his life in Manchester. He bought a small house in a suburb and bicycled the ten miles to the university each day, donning a slightly ludicrous yellow oilskin and hat when it rained. Although nominally the deputy director of the computing laboratory (which developed the world’s first commercially available electronic computer), he also took on a fundamental mystery in biology: how is it that living things, which start out as a cluster of identical cells, eventually grow into the variety of different forms found in nature? Working out systems of equations to model this process of morphogenesis, he used the prototype computer to find solutions; seated at the console, using the machine’s manual controls, Turing looked, in the words of one colleague, as if he were “playing the organ.”

Shortly before Christmas, 1951, Turing was walking along Oxford Street in Manchester when his eye was caught by a nineteen-year-old working-class youth named Arnold Murray. The encounter turned into an affair of sorts, with Murray coming to Turing’s house on several occasions, having dinner with him, and then spending the night. A month later, Turing was invited by the BBC to take part in a radio debate on the question “Can Automatic Calculating Machines Be Said to Think?” (He had already received some rather breathless publicity on his ideas about artificial intelligence from the British papers.) On one of the days that the program aired, Turing came home to find that his house had been burglarized. The burglar, as he suspected, was an associate of Murray’s who was confident that a homosexual would never go to the police. But Turing did go to the police. After some initial dissembling about how he came by his information about the culprit’s identity, Turing volunteered the details of his affair to the startled detectives. Turing was charged, under the same 1885 act that led to the prosecution of Oscar Wilde, with “gross indecency.” This crime was punishable by up to two years’ imprisonment, but the judge, taking into account Turing’s intellectual distinction (though knowing nothing of his activities during the war), sentenced him to probation, on the condition that he “submit for treatment by a duly qualified medical practitioner.”

The treatment of choice was hormonal. Earlier, American researchers had tried to convert gay men to heterosexuality by injecting them with male hormones, on the theory that they suffered from a masculinity deficit; surprisingly, this only seemed to intensify their homosexual drive. So the opposite approach was tried. By giving homosexuals large doses of female hormones, it was found, their libido could be destroyed in as little as a month. This chemical castration had the side effect of causing temporary breast enlargement, as Turing found to his humiliation, and his lean runner’s body took on fat.

The news of Turing’s conviction received no national attention. The reaction of his mother, to whom he had grown close over the years, was one of affectionate exasperation. His lab colleagues dismissed it all as “typical Turing.” With his criminal record of “moral turpitude,” he was barred from the United States. But, once his probation ended, in April of 1953, and the effects of the hormone regimen wore off, he travelled to Europe for romantic liaisons. His position at Manchester was secure: the university created a special Readership in the Theory of Computing for him, which came with a pay raise. He was free to continue with his work on mathematical biology and artificial intelligence, and he enjoyed the growing talk among logicians of “Turing machines.”

Why, then, more than two years after the trial, and more than a year after the hormone treatment ended, would he have committed suicide? Leavitt describes Turing’s life after his arrest as “a slow, sad descent into grief and madness.” That’s overly dramatic. Turing did start seeing a Jungian analyst and developed a taste for Tolstoy, but neither is an infallible sign of madness. He also, a few months before his death, sent a friend a series of postcards containing eight “messages from the unseen world.” Some were terse aphorisms: “Science is a differential Equation. Religion is a Boundary Condition.” Others had a Blakean cast: “Hyperboloids of wondrous Light / Rolling for aye through Space and Time / Harbour those Waves which somehow might / Play out God’s wondrous pantomime.” Well, it does rhyme.

Turing’s death, as Leavitt also notes, occurred in a period of acute anxiety about spies and homosexuals and Soviet entrapment. That week, newspapers announced that the former head of Los Alamos, Robert Oppenheimer, had been judged a security risk. And, as Andrew Hodges wrote, “Had the headline been ‘ATOMIC SCIENTIST FOUND DEAD,’ the questions would have been immediate and public.”

Still, Leavitt concedes that there is no evidence that the death of the Man Who Knew Too Much was anything other than a suicide. Indeed, the only person who seems to have had doubts was Turing’s mother, who insisted that her son must have accidentally ingested something from one of the chemical experiments he conducted at home. Turing was rather sloppy, and he was known to eat an apple every night before going to bed. On the other hand, he once wrote a letter to a friend mentioning a method of suicide that “involved an apple and electric wiring.”

Was Turing’s death a kind of martyrdom? Was it the perfect suicide—one that deceived the person whose feelings he cared most about, his mother—or, more improbably, the perfect murder? Leavitt is the latest to broach these questions without resolving them. Perhaps, he imagines at the end of his book, the message Turing wanted to convey is one that has so far been overlooked: “In the fairy tale the apple into which Snow White bites doesn’t kill her; it puts her to sleep until the Prince wakes her up with a kiss.” This note of macabre camp doesn’t suit a man who eschewed all forms of egoistic fuss as he solved the most important logic problem of his time, saved countless lives by defeating a Nazi code, conceived the computer, and rethought how mind arises from matter.

Subscribe to The New Yorker