There’s a lovely function in mathematics called the factorial function, which involves multiplying the input number by every number smaller than it. For example: $\operatorname{factorial}(5) = 5 \times 4 \times 3 \times 2 \times 1 = 120$. The values of factorials get alarmingly big so, conveniently, the function is written in shorthand as an exclamation mark. So when a mathematician writes things like $5! = 120$ and $13! = 6,\!227,\!020,\!800$ the exclamation mark represents both factorial and pure excitement. Factorials are mathematically interesting for several reasons, possibly the most common being that they represent the ways objects can be shuffled. If you have thirteen cards to shuffle, then there are thirteen possible cards you could put down first. You then have the remaining twelve cards as options for the second one, eleven for the next, and so on – giving just over 6 billion possibilities for arranging a mere thirteen cards.

For a full deck of fifty-two cards, the number is much bigger. Calculating $52!$ manually would take a long time, so it’s a perfect thing to get a computer to do for us. But in order to ask a computer to do something, you need to state it as an algorithm for the computer to follow. So here’s a set of instructions I’ve written to take an input number and progressively multiply it by every smaller number:

Step 1:Remember the starting value of $n$ as your running total.

Step 2:Subtract $1$ from $n$.

Step 3:Multiply the running total by this new $n$.

Step 4:Repeat steps 2 and 3 until $n$ reaches $1$.

Step 5:Return the running total.

We can try running this for the first few laps of calculating $52!$:

We’re only six laps in, and the running total has already gone past 14 billion! (No that’s not a factorial, I just wanted to emphasize how quickly these numbers grow.) This is definitely the sort of long calculation we want a computer to do for us. The last step is to translate our algorithm steps into a language a computer can understand. So what does an algorithm look like to a computer? Well, much as humans can speak different languages, computers can understand different programming languages. I’ve selected one called Python, because it has a very simple grammar and is one of the closest computer languages to being readable English. I’ll also include some comments to the right of each line to clarify

what the code is doing.

Here is the factorial algorithm, coded in Python. If you are so inclined, you could run this on a computer. Much in the way we were naming functions before, I can give each algorithm a name then write its inputs inside brackets next to it.

def factorial(n): # I am defining the algorithm called # ‘factorial’ and it starts with a number ‘n’ running_total = n # Remembers n as the starting value of # the running total while n > 1: # Repeats the next bit until n is no longer # bigger than 1 n = n - 1 # Subtracts 1 from n running_total = # Multiplies the running total running_total * n # by the new n return running_total # Returns the running total

I’ve just double-checked this program to make sure it works. Once loaded up, I can enter `factorial(13)`

into my computer to double-check $13!$. And, sure enough, $6,\!227,\!020,\!800$ appears

back on the screen. So then I let it loose on $52!$ and here is the exact output from my computer:

>>> factorial(52) 80658175170943878571660636856403766975289505440883277824000000000000

That’s a number with sixty-eight digits. A truly huge number. To say it the long way, there are 800,000 billion billion billion billion billion billion billion ways a pack of cards could be

shuffled. There are only about 1 million billion billion stars in the observable universe. And the universe is only about 4 hundred million billion seconds old. So this means that if every star in the universe had a billion planets, each with a population of a billion hypothetical aliens, all shuffling a billion packs a second since the dawn of the universe, we would now be only halfway through every possible arrangement. And that’s for a pack of only fifty-two cards! Thank goodness we didn’t include the jokers.

Anyway, now we know what the answer is, we can try to calculate it in a different way: using a recursive algorithm. We simply need to state the algorithm in terms of itself. Something like: ‘The factorial of $n$ is $n$ times the factorial of $n – 1$.’ The only extra thing we need to know is that the factorial of $1$ is $1$. This is the ‘get-out clause’ in the algorithm which stops the recursion going on for ever.

Step 1:Remember that the factorial of $1$ is $1$.

Step 2:Multiply $n$ by the factorial of $n – 1$.

Translated into Python:

def factorial(n): # I am calling the algorithm ‘factorial’ # and it starts with a number ‘n’ if n == 1: return 1 # The factorial of 1 is 1 return n * factorial(n - 1) # Calculate n multiplied by the factorial # of n - 1

Presented with `factorial(13)`

, my computer now runs down the chain of recursions until it hits `factorial(1)`

, then comes racing back up to give $6,\!227,\!020,\!800$ once more. Likewise, putting in `factorial(52)`

gives back the same 68-digit monster. Yet nowhere have I actually told the program how to calculate a factorial, merely how one factorial calculation relates to a smaller one. Once again, recursive algorithms are magic: conjuring answers out of seemingly empty code.

We now have two different computer programs which compute the same answer two different ways. Which leaves us with only one option: make them fight! I just took a quick break to race both factorial programs head to head. I decided that the winner would be the first to compute the factorial of $100$. Computing the full 158-digit answer to $100!$ took the recursive Python program 0.000068 seconds, whereas the normal one came in at only 0.000046 seconds.^{1} A decisive win for the non-recursive program!

*If you liked that, “Things to Make and Do in the Fourth Dimension” is out now in paperback and contains plenty more playful mathematical investigations. There’s also a fantastic website to accompany the book, with loads of interactive doodads, at makeanddo4d.com*

- 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000, for the record.

We’ve often mentioned category theorist and occasional media-equation-provider Eugenia Cheng on the site, and she’s now produced a book, Cakes, Custard and Category Theory, which we thought we’d review. In a stupid way.

The book is in two halves: the first is a general introduction to the idea of mathematics and mathematical thinking, and a tour of some fundamental ideas in mathematics such as how to interpret real-world problems, as well as an introduction to group theory and topology. The second half is about category theory. Cheng describes it as being ‘the mathematics of mathematics’, and anyone who knows a bit of category theory will understand what a challenge it is to develop and communicate the necessary ideas in a form understandable to a book audience.

Cheng is well-known for her love of baking and cakes, and is often called on to produce equations relating to foodstuffs (including scones, pizza and donuts), so naturally her book ties this hobby in with her other passion, mathematics. As well as using baking as an analogy for the process of doing maths, Cheng goes one step further and actually includes full recipes for several different foods in her book. The start of each chapter features a recipe, which is then used as an example to illustrate a point she’s making about maths.

Since we’re idiots, we spent an afternoon actually baking and trying out the recipes. I invited round two mathematicians called Sam (you may remember them from our π approximation challenge), along with Aperiodical regular Paul, to have a go at baking the recipes, tasting the results and not in any way letting our ineptitude at making edible food influence our opinion of the book.

The first thing we tried making were Cheng’s gluten free chocolate brownies, from Chapter 1. The idea behind including this recipe is that you need both the ingredients and the method to make a recipe work (in this case, it won’t work if you bake it in one big pan, since it’s gluten-free flour, you have to do small ones), in the same way that maths is about not just the ingredients but also the method. I think. We found it pretty easy, although the baking time given in the recipe wasn’t nearly enough, and we ended up putting them back in the oven twice, because they were basically liquid in the middle, but then the third time we put them back in we forgot because we were busy baking something else, so they ended up horribly overbaked. They’re still quite nice though. 8/10.

Next we tackled the so-called ‘Conference chocolate pudding': baked one evening after a boozy conference social, these illustrate that if you have the principles of how to bake cakes you can do it, even if you’re wasted, without a recipe. This echoes the way that a mathematician who knows basic principles can derive any mathematical result. It turned out that we didn’t have enough cocoa powder to do this properly, since we already weighed out everything for the other recipes, and so we used vanilla instead for these. They turned out pretty presentable, if a little plain-looking. 7/10.

The book covers an impressive range of maths – not shying away from difficult topics, and jumping from topic to topic with impressive enthusiasm. As well as being split into chapters, practically each paragraph has its own heading, with different topics connecting from one to the other. It’s basically the stuff I’d like someone to have written a book about – from the way mathematicians think, to some of the really interesting pure mathematical concepts that people don’t even find out exist unless they study maths at university.

Our next baking adventure was the Olive Oil Plum Cake, from Chapter 5. While not containing many of the traditional things you’d expect a cake to, like flour, or sugar, this illustrated the chapter on generalisation – once you know what a cake is, you can imagine things which are basically the same as a cake, but aren’t a cake. We managed to successfully bake what we all agreed was not a cake, and while we followed the instructions to the letter and it looked like a cake on exit from the oven, once inverted it quickly became a soggy mass which looked hugely unappetising, despite still being a bit tasty (mostly due to how awesome plums are). Its popularity among the group varied, and we give it 5/10.

We then followed the recipe for Jaffa Cakes, from Chapter 7. The chapter is about axiomatisation, and the recipe simply calls for ‘small round cakes’, ‘marmalade’ and ‘chocolate’. Each of these could have been broken down into more detailed recipes, but the point is that you have to decide what’s an axiom and what can be derived (using a recipe from simpler ingredients). We bought a cuboid cake, and cut it into small round pieces; we also tried, since they do technically count as ‘small round cakes’, using some Eccles cakes, to make Eccles Jaffa cakes. If nothing else good comes from this whole exercise, we at least have that. The main conclusion we came to here is that bought Jaffa cakes are better, although you can’t go far wrong combining cake, marmalade and chocolate. 6/10.

Cheng uses a lot of analogies in the book. Imagine a hedgehog, but where the spines of the hedgehog are analogies. That’s what the book is like. This is good, because they’re well chosen analogies (One of my favourites: pure maths is building things out of basic 2×1 Lego bricks, while in applied maths you get to use the wheels and doors and hinge pieces, so you can do more interesting stuff, but isn’t the pure maths better somehow?), although it does sometimes make for a slightly tangled web (imagine if analogies were woven by spiders). As a result, the amount of time dedicated to explaining the actual mathematics is sometimes slightly less than you’d like. It’s important to get where the maths sits in context, and the analogies are great for that, but sometimes the maths explanations might need reading and re-reading to get an understanding of the way it actually works.

By this stage our energy was flagging and our attention waning, but we pushed on to bake (or rather, not bake) the Raw Chocolate Cookies from Chapter 13. By now the book is starting its explanation of how category theory works, and dealing with the concept of equality and sameness – what things are equal to each other? Numbers can be equal, but there’s a sense in which ‘2+4′ is not the same thing as ‘6’; is homotopy equivalence in topology a form of equality? The analogy here is that the cookies, which might have started as regular cookies, have been made gluten-free, then vegan, then sugar-free, then low-fat, and each step doesn’t take you too far away from the previous cookie, but overall when you’ve finished they’re very different.

Here we struggled with a few things – firstly, some of the ingredients are pretty rare. I now own a jar of coconut oil, which I didn’t before, but struggled to get hold of cocoa butter, which we substituted with… some butter, and we also ran out of cocoa powder halfway through, so we had to add some other stuff, including a bit of flour and some white hot chocolate powder. We basically undid the veganness and the gluten-freeness, and the low-fatness. All of the things we put into these cookies were ingredients you’d normally find in a nice baked product, but somehow all our substitutions and ineptitude culminated in biscuits which looked, and tasted, like dog biscuits. Not even my funky maths cookie cutters could save these. They’re very much not equal to biscuits. 2/10.

The book has a lovely tone – it’s relentlessly positive about maths, the ways in which it can be useful and fascinating, and people’s ability to do and engage with mathematics. It’s also full of friendly anecdotes about Cheng’s own failures and successes, in and out of the kitchen and maths department, and draws the reader in with her enthusiasm and charm. Cake-based metaphors are used even away from the recipes in each chapter – had you noticed that the multiplication table for $\mathbb{Z}_2$ was a Battenberg cake?

We did have one final success story – and since we’d been doing it in amongst everything else and leaving things to soak, we almost forgot – which was that we’d also made the chocolate and prune bread-and-butter pudding from Chapter 6, which came with one of my favourite cake/maths analogies. The recipe had been developed to use up some leftover bread, and prunes, and the chapter discusses motivation for doing and learning maths – the motivation can be external (people telling you maths is useful, or you having a particular problem to solve) or internal (you just want to do it, or you enjoy it, or you want to know the answer) and you can’t expect people to learn maths without both types of motivation. The leftover food had been an internal motivation for making the pudding, which probably wouldn’t have happened otherwise.

We found this the easiest of the recipes to follow – it uses shredded up breadcrumbed bread instead of whole pieces, which is unusual, but works – and the result was a lovely, moist, fruity cake which would go well on its own or warm with custard or ice cream, in our opinion. We ended up with one big square cake, which we cut into squares and put each in a paper case, and they were well tasty. 8/10.

Our forays into mathematical baking were probably hindered by a combination of the fact that a) this isn’t actually a cookbook, so you’re probably not meant to bake these things; b) we didn’t have all of the right ingredients, despite a frantic afternoon in a huge ASDA trying to find cocoa butter and potato flour (which I had to swap for just regular gluten-free flour), and c) trying to bake 6 different things at the same time probably doesn’t result in the best focus/concentration. But we had fun! And that’s what maths is all about.

I’d imagine this book would be great for someone studying maths at uni, or a keen A-level student, although it’d probably take a decent amount of concentration to make sense of it all – it’s definitely not for the casual reader. As someone who already understands most of the concepts covered, I found it a lovely round-up of some brilliant kinds of mathematics (and I never did quite *get* category theory first time round, so it was nice to have it laid out in simple terms) – although I’d imagine if you don’t already know all of the maths, you’d need to be careful navigating the complex web of analogies and jumping from topic to topic.

We’re terrible at baking, but this book was fun and covered some cool maths, using some nice analogies, and would serve as a good intro for someone getting into category theory. Maybe not for complete beginners, but there’s already plenty of books out there for them, right?

Cakes, Custard and Category Theory, on Amazon

Noel-Ann Bradshaw’s review, in the Times Higher Education

Cakes, Custard and Category Theory, on the Profile Books website

]]>Check out the video below, and consider chucking some money on the KnitYak Kickstarter page.

]]>The first major UK show of Escher’s work has been put together by the Scottish National Gallery of Modern Art, in Edinburgh, and includes nearly 100 works from the collection of the Gemeentemuseum Den Haag in the Netherlands. It will be on display at the Scottish National Gallery from 27 June to 29 September, after which it’ll move to the Dulwich Picture Gallery in London from 14 October through to 17 January.

Both exhibitions have an entry cost, although there’s also a free event taking place at the Scottish National Gallery on 27 August, in which mathematician Professor Ian Stewart will talk about the mathematics in Escher’s work, apparently ‘in simple non-technical terms and with many illustrations’ (because people who go to art galleries presumably wouldn’t like it otherwise).

The Amazing World of MC Escher, 27 June to 29 September, Scottish National Gallery of Modern Art

Event – Escher: A Mathematician’s Eye View, Prof. Ian Stewart, 27 August, Scottish National Gallery of Modern Art

MC Escher, 14 October to 17 January 2016, Dulwich Picture Gallery

]]>The MathsJam annual conference is a magical time when maths geeks converge on a conference centre ~~in the middle of nowhere~~ near Stone and spend a weekend sharing their favourite puzzles, games, and mind-blowing maths facts.

Registration for the 2015 weekend, taking place on 6-7 November, has now been opened. More information about the conference, and how to register, can be found on the MathsJam Conference website.

We’ll all be there: join us!

]]>Somdip Datta wrote in to tell us about his illustration of the classic maths textbook, *Lilavati*, by the Indian mathematician Bhāskara II.

*Lilavati* contains definitions, algorithms and problems dealing with arithmetic, geometry, combinations, and quadratic equations, all written in meter.

This edition is really just a sample of the original book, with a few illustrated excerpts interspersed with information about the history of the book and its translations, along with solutions and some hints to the questions.

It’s an interesting book, and the information pages add valuable context to explain, for example, why Bhāskara’s method of multiplication made more sense for someone working on a dust-board instead of on paper. The questions could divert, say, a table of MathsJam attendees, for an hour or so. While the maths involved is very simple (one theory is that Bhāskara wrote the book for his daughter), the framing livens things up a bit – monkeys leap from trees, archers shoot everyone up, and merchants share gems equally. It’s literally a textbook example of fake-world maths problems, but that’s not always a bad thing.

Unfortunately, the translation used is from 1816, so the language used in the questions is quite old-fashioned and cumbersome, making some of them into challenges of your parsing ability rather than of maths. The illustrations are pleasant enough, and the print is very large so it’s readable on a phone screen.

At $0.99, there are worse ways of spending your money, but don’t expect it to last you more than an hour or so.

*The Illustrated Lilavati* by Somdip Datta, available on iTunes, Google Play and Kindle, from LiLBooX.

Lilāvati on Wikipedia

]]>But the Sword of Damocles hanging over Camelot’s changes is that there will be an extra ten balls to choose six from (59 instead of 49), dramatically lengthening the odds of winning all of the pre-existing prizes. This is our round-up of the media’s coverage of this mathematical “news”.

Here at the Aperiodical, we like to cover the hard-hitting questions people are demanding the answers to. Our extensive research – watching and screengrabbing the press release video, below – reveals that the balls bearing numbers 50-59 will be coloured PURPLE (pale lilac/heliotrope). Ok, fine, the maths stuff.

Various media outlets have weighed in on the new odds, although many are disappointingly willing to simply rehash Camelot’s press release with its unsurprisingly upbeat view of their “enhancements”. Others are more willing to put the sword in Camelot’s stone – everyone seems very angry that the expected return on your £2 stake has gone from around 45% to around 45%. At one point the Independent uses the phrase “so-called ‘Millionaire Raffle’,” like that’s not just exactly what it is.

It’s interesting to compare which newspapers are willing to state the mathematical facts of the new odds directly, and which were only willing to hedge and attribute the immutable nature of numbers to the opinions of various roped-in statisticians. The Guardian’s main article is willing only to stipulate that “statisticians suggest” the new jackpot odds are 1 in 45m; later quoting a somewhat more forceful assertion from “statistician Robert Mastrodomenico” that the odds “would increase to precisely one in 45,057,474″.

The Evening Standard’s piece also ascribes this combinatorial certainty to Mastrodomenico, while the coverage in the Daily Express corrals “lottery expert Professor Ian Walker”, and in the Daily Mail article “statistics lecturer David Hodge” is called in to distance the paper from having to put provable truths directly on record. The prize for best hedge maze goes to the article in the FT, which in addition to badly garbling the new rules, goes only as far as saying “The Guardian reports statisticians believe” what the new jackpot odds will be, an impressive third order distancing from stating a high-school probability fact.

The Times (£) and BBC online are creditably willing to stake their reputations on the correctness of the binomial theorem and simply report the new odds rather than launder them through the mouths of the nearest PhD-holder.

Persistent Aperiodical-hassler Matt Parker’s piece in the Guardian really burns Camelot’s cakes, by pointing out the charming if Bayesianly-questionable fact that under the new odds, “as a UK citizen, it’ll be more likely that Prince Charles is your dad than you choosing winning lottery numbers.” and muses on the real motivations of lottery players, which he controversially suggests may not be the dispassionate maximisation of their expected financial returns.

And finally, some more interesting maths analysis: statistician and Only Connect winning team member Michael Wallace has tried to untie Camelot’s Gordian Knot in his article for stats mag Significance by tackling the sticky question of exactly where those ‘free’ lucky dip tickets are coming from – if they’re being ‘paid for’ out of the prize fund, rather than generated separately and entered without it taking any money, how does that affect the game?

Changes to Lotto, at the National Lottery website

New Prize Structure (including all the odds), at the National Lottery website

It could be you? Perhaps, but lottery success just got more complicated, at Significance Magazine

You’re still not going to win the lottery. But you might have more fun not doing so, by Matt Parker at The Guardian CiF

Camelot: Lotto changes ‘will make more millionaires’, on the BBC website

Fury over National Lottery ‘rip-off': Chance of winning jackpot is now 45 million to one, at The Daily Express

It could be you (but probably won’t be) as Camelot revamps National Lottery, at The Guardian

National Lottery adds ten more balls, at The Evening Standard

Why you will soon be twelve times more likely to be eaten by a shark than win the lottery… but it won’t stop JAMES DELINGPOLE playing!, at The Daily Mail

Odds of winning the lottery improve: now it’s just 1 in 10 million, at The Times (£)

Since You Asked: Camelot’s logic not likely to make you a millionaire, at the Financial Times

The Carnival rounds up maths blog posts from all over the internet, including some from our own Aperiodical. See our Carnival of Mathematics page for more information.

]]>

Puzzlebomb is a monthly puzzle compendium. Issue 42 of Puzzlebomb, for June 2015, can be found here:

Puzzlebomb – Issue 42 – June 2015

The solutions to Issue 42 will be posted at the same time as Issue 43.

Previous issues of Puzzlebomb, and their solutions, can be found here.

]]>I know I usually write up the goings-on at Manchester MathsJam, but since I spent much of the last month ‘In Residence’ at the University of Greenwich, I spent the second-to-last Tuesday evening of May at the London MathsJam. Here’s a summary of what transpired.

We spent a good while building Sierpinski tetrahedra for me to take back to the exhibit at Greenwich. Pub manufacturing standards are slightly lower, due to it being a bit dark and all the beer and so on, but we managed to construct a 64-tetrahedron pyramid, which I took back. The smallest pyramids are made using a simple tetrahedron net printed up with the Sierpinski triangle design, then taped together at the corners.

Some discussion of pyramid-related puzzles ensued:

- If you have a regular pentagon-based pyramid, is it possible to slice it in a single plane so that the cross-section is a regular hexagon?
- If you build a square-based pyramid with a square and four equilateral triangles, then disassemble it and use the same triangles to make a tetrahedron, what is the ratio between the areas of the two solids?
- If four ants stand at the corners of a tetrahedron, and each set off walking with the same speed along a randomly chosen edge, what’s the probability that no ants meet at a corner, or pass each other going in opposite directions?

A nice puzzle with overlapping circles was passed around: If three circles are placed in a line with overlaps between each pair, can you arrange the numbers 1-5 in each of the five sections so that the numbers in each individual circle total to the same answer?

Now, level up: four overlapping circles in a line, and the numbers 1-7?

Serious business: five overlapping circles, and the numbers 1-9?

Colm Mulcahy, aka Card Colm, was visiting London and came by to see us. He showed us some amazing card tricks, but I can’t remember any, so you’ll have to buy his book.

Some people were looking at the Advanced version of Cheryl’s Birthday Puzzle.

A pile of humans from UCL’s Chalkdust Magazine were in attendance, and are dead nice. They helped out with building tetrahedra, and also brought along a few puzzles, including their £100 prize number crossword.

]]>