The TARDIS begins to drift off course, and the Doctor begins humming a distracted, tuneless melody while he investigates. He eventually lets his ship go where it wants to, and it takes him and Ace to a number of minor, self-correcting time disruptions; Edgar Allen Poeís death, the eruption of Vesuvius, and the spelling of I.M. Foremanís name on the junkyard in Totters Lane are all slightly different, but the changes have no lasting effect on the course of history. The Doctor charts the time distortions and determines that they centre on a reclusive young mathematician named Ethan Amberglass. Ethan suffers from headaches and hallucinations, and when the Doctor and Ace show up in his flat, he assumes that heís hallucinating them as well; however, he is startled when the Doctor comments insightfully on the Reimann hypothesis, the theory that there is an as-yet-undiscovered pattern to the distribution of primes along the number line. Ethan storms out of his flat, and the Doctor sends Ace to keep an eye on him while he reads Ethanís e-mail. Frightened and bewildered by Aceís continued existence, Ethan loses his temper when she asks him who cares about maths; as far as heís concerned, math is beautiful in its own right, and anyone who canít see that is an idiot. Irritated, Ace nevertheless accompanies Ethan back to his flat, where they find that the Doctor has popped out to continue his investigations elsewhere.
The Doctor is still unsure why Ethan is the source of the time disruptions; perhaps heís arrived too early, before Ethan becomes a problem. He visits UNIT to ask for help, and finds that Lethbridge-Stewart has been called out of retirement to consult on the sudden appearance of odd crop patterns in a field in Kent -- not circles, but strange geometric shapes marked out with ice. The Doctor determines that the pattern is incomplete, and theorises that whoever created it may try to finish the job later. The incident was reported by Adrian Molecross, the webmaster of a site devoted to the odd and uncanny; Lethbridge-Stewart considers him a crank, and has not involved him in the investigation. Molecross, rather hurt by the snub, decides not to give Lethbridge-Stewart the licence plate number of a Jaguar he saw leaving the field. That night, he visits the field again -- and turns up at UNIT HQ the next day in a state of shock, his left hand frostbitten and necrotic. The pattern appeared again, but this time in a slightly different position, and Molecross was caught on the edge. Delirious from shock and painkillers, he seems transcendent with joy when the Doctor questions him; this is just what heís been looking for all his life: proof of the paranormal, evidence that the Universe is larger and more inexplicable than the petty realities of life.
The Doctor returns to Ethanís apartment, sends Ace to an INXS concert and questions Ethan about certain e-mails from a person who refers to himself only as ďUĒ. Ethan dismisses U as a crank with wild ideas about using pure mathematics to stop the process of entropy. The Doctor asks Ethan his opinion of the crop patterns, and Ethan suggests that the lack of circles implies that the pattern cannot contain irrational numbers, such as pi. The Doctor also asks about Ethanís headaches, and seems to form some unpleasant conclusions which he does not share. Instead, he visits Ethanís employer, Clisby, and learns that ďUĒ may be Patrick Unwin, an even more eccentric mathematician who disappeared after turning up to work drunk and tampering with his co-workersí files, insisting that they were rubbish. Still unsure what the connection is between Ethan and the time disruptions, the Doctor decides to investigate the crop patterns instead.
Ace eventually gets tired of clubbing alone and returns to Ethanís flat, as she has nowhere else to go. Trying to start a conversation, she asks him about the nature of entropy, and he explains that itís fundamental to understanding the laws of physics; trying to stop it would completely alter the nature of the Universe. Ethan then turns the conversation to the Doctor, trying to learn more about the frightening little man, but is unaware that the Doctor hadnít told Ace about the crop patterns. Irritated to learn that the Doctor is leaving her out of something, Ace convinces Ethan to visit the field in person with her. A brief internet search turns up Molecrossí site and the location of the field, where they find the Doctor digging a circle in the middle of the frozen pattern. By the time he notices them, itís too late for them to leave, and he urges them to step into the circle with him. Soon after they do so, Ethan collapses with a splitting migraine, the field turns dark and cold, and something seems to draw the Doctor out of himself, pulling him in a direction that doesnít conform to ordinary three-dimensional space. Ace and Ethan manage to hang onto him, anchoring him to the earth until the darkness passes. When it does so, they see that the pattern has once again appeared on the field -- but this time, the Doctorís circle turned it aside, as if whatever is laying down the patterns canít tolerate the irrational numbers delineated by the circle.
Ethan is still suffering from a terrible migraine, and the Doctor and Ace take him to UNIT HQ for treatment. While there, the Doctor tries to question Molecross, but Molecross realises who the Doctor is and insists upon trying to interview the legendary figure. The Doctor asks the Brigadier to discourage Molecross from investigating him, but before leaving, he and Ace visit Ethan to apologise for involving him in this bizarre situation, and Molecross catches a glimpse of them leaving Ethanís room. Ethan leaves before Molecross can speak to him, but Molecross gets his name by flirting with UNITís receptionist. As he comes down from his state of transcendent joy, he begins to look for a rational explanation for his experience, and comes to suspect that the Doctor is helping to cover up the test of a government super-weapon. While he is at UNIT HQ, having his hand seen to, Ace breaks into his house at the Doctorís request, but finds little of interest apart from the Jaguarís licence plate number.
Though the Doctor had promised to leave Ethan alone, he finds that he needs Ethanís help with Unwinís equations; he could easily complete them himself, but he needs to know how far a human could get. He is forced to admit that heís not human, and Ethan, shaken, looks at the Doctor from this new angle and sees what Ace canít; sheís too close to the Doctor to realise how scarred he is by the terrible things he has done in the past. Ethan admits that he saw strange shapes in the field when the migraine hit, and the Doctor explains that the human eye takes in a series of still images, like frames of a film; for some reason, Ethanís ďfilmĒ occasionally slips, and he can catch glimpses of what lies between the gaps.
Molecross tracks down Ethan and tries to question him about the Doctor, but when the Doctor and Ace show up in person, Molecross panics and flees, fearing that they intend to abduct him. The Doctor returns to the TARDIS and sends a computer worm into Molecrossí systems, sabotaging his website so he canít expose the Doctor or Ethan to the scrutiny of his paranoid readers. While heís gone, Ace and Ethan trade further insults before abruptly and irrationally falling into each otherís arms. Meanwhile, the Doctor visits a number of important historic events, but can find no pattern to the distribution of temporal distortions along the timeline. Since the force creating the crop patterns seems to depend on rationality and order, the Doctor suspects that there is a connection between them and the anti-entropic equations that Unwin has been working on; and, since the equations make no sense in this Universe, the Doctor suspects that theyíre meant to create a bridge to another Universe.
Elsewhere, Pat Unwin is being forced to work for a vicious man named Sheridan Brett, who needs Unwin to solve two sets of equations provided by their alien allies. Unwin has already developed a means of communicating with the aliens, but Brett doesnít understand what theyíre trying to tell him; they seem to be having trouble getting enough power on their end, but when they speak of the man who made the circle in the field, it isnít clear whether they want him destroyed or kept alive to provide them with more power. Brett determines that UNIT is investigating the crop patterns, and when Unwin hacks into UNITís secure server, he finds a strange, empty personnel file on a man known only as ďthe Doctor.Ē
Molecross returns home, disgusted with himself for missing a golden opportunity to interview the Doctor, only to find that his website has been shut down and his files deleted. Determined to find the truth, he follows up his only remaining lead, tracing Brett via the licence plate number and telephoning him for an interview. Brett claims to be an innocent passer-by, and Molecross, still disoriented by the painkillers heís been taking for the infection in the stump of his left arm, inadvertently lets Brett know that Ethan Amberglass is working with the Doctor. Brett has Unwin hack into Ethanís computer, and when Unwin learns that Ethan has made extraordinary progress on the anti-entropic equations, Brett decides to speak to Ethan in person.
Unwin reluctantly lures Ethan out of the flat on the pretext of wishing to discuss his equations and delivers him into Brettís hands. Brett takes Ethan to his home, ties him up in the cellar for a night and then tortures him with a lit cigarette, demanding to know who the Doctor is. Satisfied that the Doctor will try to contact Ethan again, Brett orders him to help Unwin with his equations. Unwin wishes to put an end to entropy to save the Universe from its otherwise inevitable heat death, and only Brett, who wants to see the whole world destroyed, is willing to help him. Ethanís scepticism melts away as he argues with Unwin; his recent experiences have opened his mind to the possibility that pure mathematics could change the nature of reality. He refuses to help Unwin stop everything cold in its tracks, but Unwin, knowing that Brett will kill Ethan otherwise, tells Brett that Ethan has agreed to help them. Brett decides to tie up Ethan in the cellar for another night, just to ensure that he will co-operate.
The Doctor and Ace find Ethan missing, and the Doctor recovers Unwinís message from Ethanís answerphone. Worried, the Doctor returns to UNIT HQ to ask for their help, but Brett then calls Ethanís flat and leaves a message implying that he will torture Ethan to death unless the Doctor meets him in the field. Ace hears the message, and, furious, tracks him down via the licence plate number she took from Molecross. Meanwhile, Molecross realises that he let slip more than he should to Brett, and when he visits Ethanís flat to warn him, he hears the message from Brett on the answering machine. Horrified, he travels to Brettís house himself to make amends, and runs into Ace as she breaks in. They find Ethan in the cellar, weakened by Brettís torture, and although Ace wants to sort Brett out, she realises that itís more important to get Ethan to safety. She does so, leaving Molecross to find his own way home.
Molecrossí stitches have split open, and he returns to UNIT to have them seen to. While there, he reports the kidnapping incident to Sgt Ramsay, and the Brigadier visits the Doctorís house on Allen Road, where Ace has taken Ethan to recover. Brett and Unwin have fled, but the Brigadier promises to have them found and arrested. This is all UNIT can do for now; the solution to this invasion, like the invasion itself, must be purely mathematical and not military. Until Brett and Unwin are taken into custody, Ethan must remain at Allen Road, out of danger. He and Ace sleep together again, and while cuddling, they both experience another time distortion; only the Doctor and Ace are sensitive to the distortions, due to their frequent time travel, but it seems that anyone in direct contact with them when a disruption occurs will experience it as well.
The Doctor, believing that the invaders were taking advantage of a natural weakness in the space-time continuum, sets the TARDIS to monitor the field and is relieved when the weakness closes of its own accord. Since the time disruptions were presumably caused by the aliensí attempts to penetrate the barrier between the two Universes, the problem should be over. But when he and Ace experience another time distortion, he realises that the aliens must be trying again through another weak point in the continuum. He traces the weakness to Switzerland, but when he announces that theyíre going to investigate, Ethan suffers another splitting migraine. He is thus forced to remain in the TARDIS with the worried Ace while the Doctor sets off to explore, convinced that Brett and Unwin will be lurking nearby, trying to make contact.
While waiting for the Doctor to return, Ace unexpectedly bumps into Molecross in the TARDIS corridors; heíd followed the Brigadier to Allen Road, and slipped into the TARDIS while nobody was looking. He insists that he knows just how dangerous and terrible the world can be, which is why he is always on the lookout for the transcendent and miraculous. Ace eventually gets fed up waiting for the Doctor to return, and when Ethan tries to discourage her from storming off in search of him, she admits that she had nothing in her life until the Doctor showed up; heís shown her wonders, and sheíll do anything for him. Ethan reluctantly accompanies her outside, and they leave Molecross in the TARDIS with instructions to touch nothing.
The TARDIS has materialised in a picturesque Alpine village complete with a skating pond and a stunning view of the mountains. Brett and Unwin are indeed here, waiting for the aliens to make contact. They need a flat surface on which to lay down their patterns, but may not have enough power to break through completely; nevertheless, Brett visits the nearby glacier to wait for a sign. The Doctor gets there first and uses a penlight laser to melt circles in the ice. He then hides nearby and waits for the aliens, and while musing on the nature of entropy, realises that the aliens must need to draw extra energy from outside their Universe to keep everything in perfect stasis. Theyíre not here to invade Earth, but to draw its energy away. Brett arrives, and the aliens make their attempt to break through -- and the pressure of their presence causes the Doctorís circles to melt away from the surface of the glacier. He is forced to break cover and throws a perfectly circular soup tin lid out onto the glacier, and the furious Brett grabs hold of the Doctor, inadvertently anchoring him to the Earth when the alien presence again tries to draw him out of himself.
The alien presence withdraws, its pattern incomplete, and Brett realises heíll never be able to find the soup tin lid on the glacier in time to remove it. Infuriated, he beats the Doctor senseless and takes him back to his chateau, where he handcuffs the Doctor to the bed and questions him. His allies claim that the Doctor has destroyed worlds in the past, but Brett believes that the Doctor can help him complete his work. As far as Brett is concerned, all of human culture, its art, accomplishments and complexity, is based on selfishness and built on the suffering of others, and Brett wants to sweep it all away, leaving nothing behind. He forces the Doctor to look at Unwinís equations, but while heís holding on to the Doctor, another time disruption occurs, briefly placing them both in an alternative history in which Unwin has completed his work. Brett realises whatís happening, and orders Unwin to save his work to disc; he then holds onto the disc and the Doctor as history corrects itself, carrying the completed work back over into the proper timeline.
Satisfied, Brett handcuffs the Doctor to the bed again, transmits the completed equations to the aliens and departs, apparently intending to check the glacier again. By this time, however, Unwin has had enough of Brettís vicious ways, and, thoroughly drunk, he frees the Doctor. However, he then passes out on the bed, leaving the Doctor with a moral dilemma; he canít possibly carry Unwin to safety before Brett returns, and in any case, itís still possible that Unwin could complete the second set of equations. Though the Doctor doesnít know what the equations are for, and isnít sure whether Unwin can solve them on his own, he leaves Unwin behind and flees to safety. When Brett returns to find that Unwin has betrayed him, he decides that he doesnít need Unwin any more as long as Ethan is out there. He thus carries the sleeping Unwin outside and buries him in the snow.
The Doctor returns to the TARDIS, only to find Molecross waiting for Ethan and Ace. Molecross begs the Doctor for an interview, promising not to attribute any quotes to him, and the Doctor eventually takes pity on him and takes him to the TARDIS medical bay to have his infected stump seen to. While Molecross is receiving treatment, the Doctor answers his questions, admitting that heís extremely long-lived, has the ability to regenerate his body and travel through space and time, and has saved the world on numerous occasions. Molecross breaks down in tears, having finally found something miraculous. Touched despite himself, the Doctor takes Molecross down to the village to recuperate, and while there he catches up with Ace and Ethan -- just as Ethan collapses with another migraine, seeing shapes form over the frozen pond. Too late, the Doctor realises that the aliens can sketch their patterns on the flat surface of the pond as well as the glacier.
Ace sees Brett watching nearby and attacks him, but the Doctor and Ethan manage to pull her off him before Brett can respond to the attack and kill her. Brett flees, and fortunately, the alien presence withdraws, its work incomplete. Relieved, the Doctor takes Ace, Ethan and Molecross back to Allen Road, explaining that, even though the equations are incomplete, the aliens still donít have enough power in their own Universe to break through and start draining energy from this one. The attack cannot proceed, and the Doctor has plenty of time to find a permanent solution. Unfortunately, this means that he let Unwin die for nothing, since there was nothing more that he could have done to help the aliens.
Ace asks Ethan to tell her what he finds so fascinating about maths, and he explains the relationship between math and music and plays her a piece heís been composing based on the distribution of prime numbers. She recognises the tune instantly; itís the same tuneless melody the Doctor has been humming for the past few weeks. The Doctor realises that the second set of equations was part of a formula that would have enabled them to hack into the TARDIS and draw from it the power they need to break through into the Universe; the Doctor subconsciously registered the hacking attempt due to his symbiotic link with the TARDIS, and expressed it as music. And now that Unwin is dead, only Ethan can solve the equations. Ethan realises that the Doctor intends to kill him and lie to Ace about it, and although the Doctor insists that this would be for the greater good, Ethan refuses to make it easy on him. When Ace arrives, interrupting their argument, the Doctor canít bring himself to admit what theyíve been talking about, and promises Ethan that he will find another way. However, Ethan now knows just how far the Doctor will go for the ďgreater goodĒ -- and heís just as sure that Ace has no idea.
With no other options, the Doctor returns to the field where the aliens first tried to break through, hoping to find some clue that will help him to fight the aliens. Ethan searches the other side of the field, as far from the Doctor as he can get -- and, as a result, Brett is able to catch him alone. Brett overpowers Ethan and drags him to the home of the fieldís owner, where he threatens to torture Ethan by pressing his body against a red-hot stove until Ethan agrees to solve the TARDIS-hacking equations. Brettís skin is now icy to the touch, and Ethan can see strange geometric shapes moving about his body; something did get through in Switzerland after all, and it attached itself to Brett. When Brett tries to pass the equation into Ethanís body, it rejects him, and Ethan collapses with a migraine -- but, realising that Brett doesnít see him as a threat, Ethan manages to kick him face-first into the stove. Molecross arrives, having deduced what had happened, to find that Brett is dead, his body freeze-dried.
Shaken by his experiences, Ethan realises that he would have given in eventually to save himself from further torture; perhaps the Doctor was right to consider killing him. However, the Doctor instead puts him to work on the first stage of Unwinís hacking equations, and once Ethan is finished his work, the Doctor shoos him away. Ace sends Molecross to the TARDIS library so she and Ethan can have some time alone together, but hours later, she realises that the Doctor is nowhere to be seen. When they check on him, they find a 3-D graph on the computer screens, but no sign of the Doctor -- and Ethan realises that heís charted the hacking equations into a three-dimensional, mathematical landscape and has used the power of the TARDIS to create a bridge into the mathscape, a middle ground where he can confront the equation creatures on his own. Furious, Ace uses her nitro-nine to blow a hole in the screen and leaps through into the mathscape, but the hole seals itself up before Ethan or Molecross can follow her. Brett then appears in the room, and Ethan realises too late that the screen was meant not just to keep them out, but to keep something else in. The equation that entered Brettís body in Switzerland returned to its own Universe when Brett died, and it took a bit of Brett with it -- and now it has broken into the TARDIS. Now the equations can finish Unwinís work and use the power of the TARDIS to break through to Earth.
The Doctor negotiates the peaks and troughs of the mathscape, and finds his way to a cavern where he speaks with the spokesman for the alien equations. He claims that heís come to reason with them, but the aliens know the truth; he has programmed the TARDIS to fire a bolt of artron energy through his body, intending to sacrifice himself rather than Ethan to destroy the alien race before they can destroy the Earth. But they were able to draw enough energy out of Brettís body to penetrate the Doctorís firewall when he entered the mathscape, and the Brett-equation has disabled the Doctorís trap. The aliens now reveal that the Doctor was drawn to them, not because they were pulling him, but because some deep part of his personality -- the part that destroys planets and civilisations, left Unwin to his death and was willing to kill Ethan -- is attracted to the pure mathematical order they represent. The Doctor tries to deny this, but the aliens begin changing the equation that make up his body in the mathscape, removing the impossible and irrational numbers and rationalising the Doctor so he can exist in their Universe.
Ethan and Molecross try to run an anti-virus scan through the remarkably user-friendly TARDIS console, and learn of the Doctorís plan to fire an artron energy burst into the mathscape. They also find a map to the emergency generator room, and decide to activate the generators in order to ensure that Brett wonít be able to shut off the TARDIS life support systems as he drains power from the TARDIS. However, Brett follows them in and steps into the TARDISí artron energy reserve capacitor, intending to act as a conduit to transfer the power through into the aliensí universe. However, Molecross has now seen the wonders heíd always hoped to find, and he never wants to return to the mundane life of the everyday again. Before Ethan can stop him, Molecross enters the capacitor and steps between Brett and the artron energy ray, which blows them both apart.
Ace finds her way to the cavern, where the Doctor is building an enormous clockwork sculpture out of ice. He seems happy, even though the clockwork isnít moving, and when the appalled Ace tries to pull him away from the sculpture, he hits her. The alien claims that they have simply rationalised the Doctor; deep down, this is his true nature, without the extra, irrational bits. However, Ace continues trying to get through to the Doctor she knows, and her sheer passion awakens something within him. Realising what heís been doing, he accompanies her back out of the cave, hoping to use her nitro-nine to blast another hole back through the firewall. The alien equation pursues them into the mathscape, but the Doctor is now ready for its attack, and, telling Ace to look away, he engages with the enemy on a mathematical level. When the alien tries to alter his equations again, he reshapes himself into an equation that requires irrational and imaginary numbers to exist -- and before the alien can respond, he goes on the offensive, restructuring the alienís equations and resolving the entire gestalt entity to zero.
Back on Earth, the Doctor reports success to the Brigadier and arranges for Molecrossí sacrifice to be remembered. Unwinís body is found by villagers in the spring and buried in an unmarked grave. Ethan and Ace remain close, but Ace chooses to continue travelling with the Doctor. Years later, Ethan falls into a coma, and the Doctor arranges for him to be cared for at UNIT. He speaks to Ethan telepathically, and admits that he knew all along that Ethanís headaches and hallucinations were caused by a brain tumour, which is why the alien equation was unable to possess him. However, he also admits that if heíd followed his first instincts and killed Ethan, he wouldnít have realised that the invaders had hacked the TARDIS until it was too late to stop them. Ethan in turn admits that heíd been hiding from the disorder and randomness of the real world in the certainty of maths; it was Ace who brought him out of that world, just as she did for the Doctor. Ethan will remain in a coma for a year before dying, but the Doctor gives him a parting gift, telepathically transporting Ethan into an endless, beautiful mathematical landscape where his mind can wander for the last year of his life: the proof of the Reimann hypothesis.