Why does Ian Stewart find it impossible to ignore the legs of an animal if he spots one walking down the road? It's all down to his mathematical mind, he says

What is it like to be a mathematician? Images spring to mind, ranging from a super-accountant in a tweed jacket who does big sums to Ian Malcolm, the rock-star chaos theorist in the film Jurassic Park. But it is not the lifestyle I am concerned with but more what it is like to inhabit a mathematical mind. I am pretty sure that in most respects my mind is like everybody else's. Somewhere inside my head, though, there is a module, organ, circuit, program, zombic simulacrum, noumenon - choose your philosophy of the mind - that can think mathematical thoughts. Even a cursory awareness of my fellow citizens suggests most of them lack such a module, just as I lack modules for playing the piano or fishing.

Being a mathematician is like wandering through a maze, looking for twists and turns that lead in useful directions, trying to avoid dead-ends or going round in circles. Most of the time you have no idea where you are going, and the only thing you can be sure of is that any direction that is "obviously" right is almost certainly wrong. To make matters worse, the mathematical maze is a virtual one, composed of ideas, not things. Yet, just as a simple virtual reality headset can turn a shopping mall into the surface of Mars, the mathematical maze seems astonishingly realistic to those who tread its paths. For about 2,000 years, for instance, it seemed evident to everyone that Euclid's geometry was the only one possible. Even today, non-euclidean geometry is a happy hunting ground for crackpots who are convinced that only Euclid's tidy world of unique parallels can possibly be true. This is bizarre, given that we inhabit an approximate sphere, whose geodesics can never be parallel. It shows that the ideal world of inner thoughts can seem more real than the world in which we live.

Because mathematics leads a virtual existence, it bears an uneasy relation to the outside world. You cannot pick up a piece of mathematics and look at it. But you can abstract it from reality. A mathematician's circle, for instance, is infinitely thin and perfectly round. No dent mars its elegant curves, not even by a billionth of a nanometre. There are no such circles in nature. But there are many things in nature that look pretty much like circles - ripples on a pond when you drop a stone in it, the arc of the rainbow, the apparent shape of the moon. Some features of these real objects are much more easily understood if you replace them by that hopelessly unrealistic idealisation, the perfect circle. For example, why are the ripples circular, anyway? Because they spread out at uniform speed from the stone. If you think of the stone as a point and the pond as a plane, then at any instant of time the ripples all lie at the same distance from that point - and this is the definition of a circle. All neat and tidy. But it becomes considerably less so if you work with a realistic stone, with non-zero size and irregular shape - let alone taking into account the three-dimensional nature of the real problem. So, once a mathematician has decided on an abstract ideal, all subsequent argument must be logically watertight. The game may not mimic messy reality, but once you have chosen your rules, you have to stick to them, or else you cannot play the game at all.

Some mathematicians work entirely within the virtual maze of ideas, ignoring any associations with the physical world. Others take inspiration from some real context - physics, biology, finance. In practice, most mathematicians combine. I would place myself somewhere in the middle. As Marty Golubitsky, an American with whom I do a lot of research, once said: "My pure colleagues think I'm applied and my applied colleagues think I'm pure. I don't think of myself as either."

A topical instance of the archetypal pure mathematician is Andrew Wiles of Princeton University, famous for cracking Fermat's Last Theorem. About 350 years ago Pierre de Fermat wondered whether two cubes could add up to a cube, or two fourth powers to a fourth power, or two higher powers to the same higher power, and he convinced himself that the answer was "no". In the margin of a copy of Diophantos's Arithmetica he wrote: "I have found a remarkable proof," adding enigmatically, "the margin is too small to contain it." Wiles's proof, announced in 1993 and corrected in 1995, is a "machinery" proof. That is, he cleverly massages the problem until it can be attacked with a battery of powerful, general methods. Then he batters the problem to death by bombarding it with everything he can throw at it.

If I make this sound easy, I apologise - it took Wiles seven years of relentless effort, and nobody else came even close. During that period his mind was living in a world that hardly anyone else could understand - a world of strange connections between abstract forms, a world of analogy informed by massive calculations, a world of intuition refined by experience. When you are living in a world like that, you are not so much threading a maze as burrowing your way through its walls to create a new one. You come to sense the weaknesses in what look like insuperable obstacles, you work out where to insert levers, and dynamite if need be, and you hack your way past them or blow them away in clouds of smoke. It is heady stuff, though few of us operate at Wiles's level.

My own research is into the patterns with which animals move their legs - known in the trade as gaits. You might expect such work to originate in a fascination with animals, but I started by a different route. I had been working with Golubitsky on the effects of symmetry on dynamics. We had used some general ideas from abstract algebra to classify oscillation patterns in symmetric systems, and applied them to fluids and some simple electronic circuits. So I was sensitised to patterns of that particular type. By chance, I'd been sent a book to review, called Natural Computation. It was a collection of articles about how engineers should take tips from nature. For example, designers of legged robots should understand how animal legs work. There was a table of gait patterns, and the more I looked at it, the more I became convinced that I had seen it before. It was our list of patterns for oscillator circuits. I mentioned this in the review, adding "anyone out there want to fund an electronic cat?" Two days later I got a phone call from Jim Collins, a young American physiologist, saying that he knew people who might. We met, and quickly realised that the neural circuits that control locomotion should follow the same basic patterns that we had found in electronic circuits, which would explain the apparent coincidence.

We applied this idea to two-legged, four-legged and six-legged animals - insects - interpreting their gaits as natural patterns for circuits with two, four or six oscillators. Then, just when we thought we had it all wrapped up, Golubitsky pointed out a snag. In our model, any animal that could walk and trot should also pace, but real animals are not like that. Those that trot seldom pace, and vice versa. Another difficulty was that three common gaits did not fit into our scheme: the rotary gallop of a cheetah and the transverse gallop and canter of a horse.

We threw everything we could think of at these difficulties, but to no avail. Worse, we proved that no four-oscillator network can model the standard four-legged gaits in a satisfactory way. Disaster! But all was not lost. According to the 19th-century mathematician Henri Poincare, the way to solve a mathematical problem is to work at it until you get hopelessly stuck. Then your subconscious, duly stirred up, gets to work behind the scenes. When - if - it blunders into an answer, it taps you on the metaphorical shoulder. Something along those lines happened to me: I woke one morning convinced that although four oscillators would not do the job, eight would. It took us half an hour to check this idea. The problem fell apart before our eyes. Every observed gait was predicted by our methods. We could extend the circuit to animals with six legs, eight - even centipedes. We had a lovely "modular" design for walking robots. Best of all, we could now fit those three baffling gaits into our scheme too; rotary gallop, transverse gallop, canter. They were just "mixtures" of the standard gaits we already understood.

I do not always work like that. Sometimes my thoughts are more like Wiles's, imaginary jaunts along virtual pathways in a maze of pure ideas. Sometimes the only thing that matters is solving a practical problem, and I do not even care whether I understand what is going on as long as it works. But I am happiest somewhere in the twilight world between imagination and reality.

I like living in a mathematical mind. It makes me think new thoughts. Whenever I walk along a road and see an animal wandering along, I find it impossible not to work out what its legs are doing. As far as I can tell, this robs me of none of the rich mystery of human existence. It just sharpens it in directions I would otherwise never have noticed.

Ian Stewart is professor of maths at the University of Warwick. He will be presenting this year's Royal Institution Christmas lectures from December 18. Inquiries: 0171-409 2992. The Magical Maze, the companion volume to the lectures, is published by Weidenfeld and Nicolson at Pounds 17.99.

## Have your say