What would Lewis Carroll's Alice's Adventures in Wonderland be without the Cheshire Cat, the trial, the Duchess's baby or the Mad Hatter's tea party? Look at the original story that the author told Alice Liddell and her two sisters one day during a boat trip near Oxford, though, and you'll find that these famous characters and scenes are missing from the text.

As I embarked on my DPhil investigating Victorian literature, I wanted to know what inspired these later additions. The critical literature focused mainly on Freudian interpretations of the book as a wild descent into the dark world of the subconscious. There was no detailed analysis of the added scenes, but from the mass of literary papers, one stood out: in 1984 Helena Pycior of the University of Wisconsin-Milwaukee had linked the trial of the Knave of Hearts with a Victorian book on algebra. Given the author's day job, it was somewhat surprising to find few other reviews of his work from a mathematical perspective. Carroll was a pseudonym: his real name was Charles Dodgson, and he was a mathematician at Christ Church College, Oxford.

The 19th century was a turbulent time for mathematics, with many new and controversial concepts, like imaginary numbers, becoming widely accepted in the mathematical community. Putting Alice's Adventures in Wonderland in this context, it becomes clear that Dodgson, a stubbornly conservative mathematician, used some of the missing scenes to satirise these radical new ideas.

Even Dodgson's keenest admirers would admit he was a cautious mathematician who produced little original work. He was, however, a conscientious tutor, and, above everything, he valued the ancient Greek textbook Euclid's Elements as the epitome of mathematical thinking. Broadly speaking, it covered the geometry of circles, quadrilaterals, parallel lines and some basic trigonometry. But what's really striking about Elements is its rigorous reasoning: it starts with a few incontrovertible truths, or axioms, and builds up complex arguments through simple, logical steps. Each proposition is stated, proved and finally signed off with QED.

For centuries, this approach had been seen as the pinnacle of mathematical and logical reasoning. Yet to Dodgson's dismay, contemporary mathematicians weren't always as rigorous as Euclid. He dismissed their writing as “semi-colloquial” and even “semi-logical”. Worse still for Dodgson, this new mathematics departed from the physical reality that had grounded Euclid's works.

By now, scholars had started routinely using seemingly nonsensical concepts such as imaginary numbers - the square root of a negative number - which don't represent physical quantities in the same way that whole numbers or fractions do. No Victorian embraced these new concepts wholeheartedly, and all struggled to find a philosophical framework that would accommodate them. But they gave mathematicians a freedom to explore new ideas, and some were prepared to go along with these strange concepts as long as they were manipulated using a consistent framework of operations. To Dodgson, though, the new mathematics was absurd, and while he accepted it might be interesting to an advanced mathematician, he believed it would be impossible to teach to an undergraduate.

Outgunned in the specialist press, Dodgson took his mathematics to his fiction. Using a technique familiar from Euclid's proofs, reductio ad absurdum, he picked apart the “semi-logic” of the new abstract mathematics, mocking its weakness by taking these premises to their logical conclusions, with mad results. The outcome is Alice's Adventures in Wonderland. Algebra and hookahs

Take the chapter “Advice from a caterpillar”, for example. By this point, Alice has fallen down a rabbit hole and eaten a cake that has shrunk her to a height of just 3 inches. Enter the Caterpillar, smoking a hookah pipe, who shows Alice a mushroom that can restore her to her proper size. The snag, of course, is that one side of the mushroom stretches her neck, while another shrinks her torso. She must eat exactly the right balance to regain her proper size and proportions.

While some have argued that this scene, with its hookah and “magic mushroom”, is about drugs, I believe it's actually about what Dodgson saw as the absurdity of symbolic algebra, which severed the link between algebra, arithmetic and his beloved geometry. Whereas the book's later chapters contain more specific mathematical analogies, this scene is subtle and playful, setting the tone for the madness that will follow.

The first clue may be in the pipe itself: the word “hookah” is, after all, of Arabic origin, like “algebra”, and it is perhaps striking that Augustus De Morgan, the first British mathematician to lay out a consistent set of rules for symbolic algebra, uses the original Arabic translation in Trigonometry and Double Algebra, which was published in 1849. He calls it “al jebr e al mokabala” or “restoration and reduction” - which almost exactly describes Alice's experience. Restoration was what brought Alice to the mushroom: she was looking for something to eat or drink to “grow to my right size again”, and reduction was what actually happened when she ate some: she shrank so rapidly that her chin hit her foot.

De Morgan's work explained the departure from universal arithmetic - where algebraic symbols stand for specific numbers rooted in a physical quantity - to that of symbolic algebra, where any “absurd” operations involving negative and impossible solutions are allowed, provided they follow an internal logic. Symbolic algebra is essentially what we use today as a finely honed language for communicating the relations between mathematical objects, but Victorians viewed algebra very differently. Even the early attempts at symbolic algebra retained an indirect relation to physical quantities.

De Morgan wanted to lose even this loose association with measurement, and proposed instead that symbolic algebra should be considered as a system of grammar. “Reduce” algebra from a universal arithmetic to a series of logical but purely symbolic operations, he said, and you will eventually be able to “restore” a more profound meaning to the system - though at this point he was unable to say exactly how. When Alice loses her temper

The madness of Wonderland, I believe, reflects Dodgson's views on the dangers of this new symbolic algebra. Alice has moved from a rational world to a land where even numbers behave erratically. In the hallway, she tried to remember her multiplication tables, but they had slipped out of the base-10 number system we are used to. In the caterpillar scene, Dodgson's qualms are reflected in the way Alice's height fluctuates between 9 feet and 3 inches. Alice, bound by conventional arithmetic where a quantity such as size should be constant, finds this troubling: “Being so many different sizes in a day is very confusing,” she complains. “It isn't,” replies the Caterpillar, who lives in this absurd world. Wonderland's madness reflects Carroll's views on the dangers of the new symbolic algebra

The Caterpillar's warning, at the end of this scene, is perhaps one of the most telling clues to Dodgson's conservative mathematics. “Keep your temper,” he announces. Alice presumes he's telling her not to get angry, but although he has been abrupt he has not been particularly irritable at this point, so it's a somewhat puzzling thing to announce. To intellectuals at the time, though, the word “temper” also retained its original sense of “the proportion in which qualities are mingled”, a meaning that lives on today in phrases such as “justice tempered with mercy”. So the Caterpillar could well be telling Alice to keep her body in proportion - no matter what her size.

This may again reflect Dodgson's love of Euclidean geometry, where absolute magnitude doesn't matter: what's important is the ratio of one length to another when considering the properties of a triangle, for example. To survive in Wonderland, Alice must act like a Euclidean geometer, keeping her ratios constant, even if her size changes.

Of course, she doesn't. She swallows a piece of mushroom and her neck grows like a serpent with predictably chaotic results - until she balances her shape with a piece from the other side of the mushroom. It's an important precursor to the next chapter, “Pig and pepper”, where Dodgson parodies another type of geometry.

By this point, Alice has returned to her proper size and shape, but she shrinks herself down to enter a small house. There she finds the Duchess in her kitchen nursing her baby, while her Cook adds too much pepper to the soup, making everyone sneeze except the Cheshire Cat. But when the Duchess gives the baby to Alice, it somehow turns into a pig.

The target of this scene is projective geometry, which examines the properties of figures that stay the same even when the figure is projected onto another surface - imagine shining an image onto a moving screen and then tilting the screen through different angles to give a family of shapes. The field involved various notions that Dodgson would have found ridiculous, not least of which is the “principle of continuity”.

Jean-Victor Poncelet, the French mathematician who set out the principle, describes it as follows: “Let a figure be conceived to undergo a certain continuous variation, and let some general property concerning it be granted as true, so long as the variation is confined within certain limits; then the same property will belong to all the successive states of the figure.”

The case of two intersecting circles is perhaps the simplest example to consider. Solve their equations, and you will find that they intersect at two distinct points. According to the principle of continuity, any continuous transformation to these circles - moving their centres away from one another, for example - will preserve the basic property that they intersect at two points. It's just that when their centres are far enough apart the solution will involve an imaginary number that can't be understood physically (see diagram).

Of course, when Poncelet talks of “figures”, he means geometric figures, but Dodgson playfully subjects Poncelet's “semi-colloquial” argument to strict logical analysis and takes it to its most extreme conclusion. What works for a triangle should also work for a baby; if not, something is wrong with the principle, QED. So Dodgson turns a baby into a pig through the principle of continuity. Importantly, the baby retains most of its original features, as any object going through a continuous transformation must. His limbs are still held out like a starfish, and he has a queer shape, turned-up nose and small eyes. Alice only realises he has changed when his sneezes turn to grunts.

The baby's discomfort with the whole process, and the Duchess's unconcealed violence, signpost Dodgson's virulent mistrust of “modern” projective geometry. Everyone in the pig and pepper scene is bad at doing their job. The Duchess is a bad aristocrat and an appallingly bad mother; the Cook is a bad cook who lets the kitchen fill with smoke, over-seasons the soup and eventually throws out her fire irons, pots and plates.

Alice, angry now at the strange turn of events, leaves the Duchess's house and wanders into the Mad Hatter's tea party, which explores the work of the Irish mathematician William Rowan Hamilton. Hamilton died in 1865, just after Alice was published, but by this time his discovery of quaternions in 1843 was being hailed as an important milestone in abstract algebra, since they allowed rotations to be calculated algebraically.

Just as complex numbers work with two terms, quaternions belong to a number system based on four terms (see “Imaginary mathematics”). Hamilton spent years working with three terms - one for each dimension of space - but could only make them rotate in a plane. When he added the fourth, he got the three-dimensional rotation he was looking for, but he had trouble conceptualising what this extra term meant. Like most Victorians, he assumed this term had to mean something, so in the preface to his Lectures on Quaternions of 1853 he added a footnote: “It seemed (and still seems) to me natural to connect this extra-spatial unit with the conception of time.”

Where geometry allowed the exploration of space, Hamilton believed, algebra allowed the investigation of “pure time”, a rather esoteric concept he had derived from Immanuel Kant that was meant to be a kind of Platonic ideal of time, distinct from the real time we humans experience. Other mathematicians were polite but cautious about this notion, believing pure time was a step too far.

The parallels between Hamilton's maths and the Hatter's tea party - or perhaps it should read “t-party” - are uncanny. Alice is now at a table with three strange characters: the Hatter, the March Hare and the Dormouse. The character Time, who has fallen out with the Hatter, is absent, and out of pique he won't let the Hatter move the clocks past six.

Reading this scene with Hamilton's maths in mind, the members of the Hatter's tea party represent three terms of a quaternion, in which the all-important fourth term, time, is missing. Without Time, we are told, the characters are stuck at the tea table, constantly moving round to find clean cups and saucers.

Their movement around the table is reminiscent of Hamilton's early attempts to calculate motion, which was limited to rotatations in a plane before he added time to the mix. Even when Alice joins the party, she can't stop the Hatter, the Hare and the Dormouse shuffling round the table, because she's not an extra-spatial unit like Time.

The Hatter's nonsensical riddle in this scene - “Why is a raven like a writing desk?” - may more specifically target the theory of pure time. In the realm of pure time, Hamilton claimed, cause and effect are no longer linked, and the madness of the Hatter's unanswerable question may reflect this.

Alice's ensuing attempt to solve the riddle pokes fun at another aspect of quaternions: their multiplication is non-commutative, meaning that x × y is not the same as y × x. Alice's answers are equally non-commutative. When the Hare tells her to “say what she means”, she replies that she does, “at least I mean what I say - that's the same thing”. “Not the same thing a bit!” says the Hatter. “Why, you might just as well say that 'I see what I eat' is the same thing as 'I eat what I see'!”

It's an idea that must have grated on a conservative mathematician like Dodgson, since non-commutative algebras contradicted the basic laws of arithmetic and opened up a strange new world of mathematics, even more abstract than that of the symbolic algebraists.

When the scene ends, the Hatter and the Hare are trying to put the Dormouse into the teapot. This could be their route to freedom. If they could only lose him, they could exist independently, as a complex number with two terms. Still mad, according to Dodgson, but free from an endless rotation around the table.

And there Dodgson's satire of his contemporary mathematicians seems to end. What, then, would remain of Alice's Adventures in Wonderland without these analogies? Nothing but Dodgson's original nursery tale, Alice's Adventures Under Ground, charming but short on characteristic nonsense. Dodgson was most witty when he was poking fun at something, and only then when the subject matter got him truly riled. He wrote two uproariously funny pamphlets, fashioned in the style of mathematical proofs, which ridiculed changes at the University of Oxford. In comparison, other stories he wrote besides the Alice books were dull and moralistic.

I would venture that without Dodgson's fierce satire aimed at his colleagues, Alice's Adventures in Wonderland would never have become famous, and Lewis Carroll would not be remembered as the unrivalled master of nonsense fiction. Imaginary mathematics

The real numbers, which include fractions and irrational numbers like π that can nevertheless be represented as a point on a number line, are only one of many number systems.

Complex numbers, for example, consist of two terms - a real component and an “imaginary” component formed of some multiple of the square root of -1, now represented by the symbol i. They are written in the form a + bi.

The Victorian mathematician William Rowan Hamilton took this one step further, adding two more terms to make quaternions, which take the form a + bi + cj + dk and have their own strange rules of arithmetic.

Melanie Bayley is a DPhil candidate at the University of Oxford. Her work was supported by the UK's Arts and Humanities Research Council