Magical Modular Maths

Here, I’m going to talk about something called ‘modular arithmetic’.  By ‘arithmetic’, I mean things like adding, subtracting, multiplying and dividing.  It’s quite a weird thing really; when you first think about it, it’s almost like reinventing the wheel, making a mockery of other arithmetic you know.  However, it really is quite useful.

 

Before I go into properly though, let’s look at an example.  Funnily enough, you almost certainly use modular arithmetic in your day to day lives, usually without even thinking.  When you look at a digital clock, it usually displays the time using the 24-hour system (or, at the very least, has the option to do so).  So, you have 01:00 for 1am, 13:00 for 1pm of the same day.  So, a 24-hour clock can show 24 different hours.  However, on your ‘old-fashioned’ clock with hands, you only show 12 different hours.  This is modular arithmetic in action!

 

Let’s look at this in a bit more detail.  When you look at a clock and it reads 14:00, you recognise that it is 2pm.  At 17:00, you recognise it’s 5pm.  As you probably figured out, whenever the hour of the 24-hour clock goes past 12, all you have to do is subtract 12 from the hour to figure out what the hour is in the traditional 12-hour system.  This is us working ‘modulo 12’.

 

Modulo 12 sounds a bit weird and scary, but it’s not.  All we mean when we say ‘modulo 12’ is you want your number to be between 0 and 11.  Similar, when working ‘modulo 10’, we want numbers to be between 0 and 9.  In general, a number ‘modulo n’ is a number between 0 and ‘n-1’.  To work out what a number modulo n is is very simple:

-If the number is bigger or equal to n, you subtract n from that number until you are between 0 and n-1.

-If the small is smaller than 0, you add n to the number until you are between 0 and n-1.

 

So, when looking at a clock, you try to work out the hour modulo 12.  If it says ’04:00′, you know that 4 is between 0 and 11, so you don’t have to do anything and it is 4am.  If it says ’22:00′, you know that’s bigger than or equal to 12, so you take 12 away from it.  Since 22-12=10, and 10 is between 0 and 11, you’re now okay and know the time is 10pm.

 

But what about adding?  Say the time is now 10am, and you want to know what time it is in 5 hours time.  Simple.  You add the numbers first, then find the result modulo 12.  So, 10+5=15.  You now subtract 12, and get 3.  So, it’ll be 3pm.  Simple!

 

The clock is a very simple example, and everyone is used to it.  However, it’s no different to anything else; you can work with modulo any whole number bigger than zero.  You can write down, for example, 66 modulo 10 if you want.  Keep subtracting 10 from 66 until you get a number between 0 and 9.  You can even do it with really large numbers, like figuring out what 9351 modulo 123 is (though I’d recommend spending your time doing better things…).

 

So really, modular arithmetic isn’t anything difficult; it’s just doing usual arithmetic, then doing some more adding or subtracting.  Already, you can sorta see it has uses (telling the time), but does it have more?  Well, yes!  It crops a lot, usually because it makes things easier to look at (so, rather than deal with really large numbers, you can look at them modulo a small number; big numbers are scary).  So this is not all something with direct applications, but also something that helps with much more difficult maths.

 

My ‘main problem’ for my research project involves looking at equations modulo a number, but I’ll do more into that another time…

Leave a comment