## Modular Arithmetic In Action!

## Mathematics are FUN!

Some autistic (and other) people can tell you the day of the week for any date. They can't explain how they do it. And psychologists normally don't understand it, either. But, it's really a fairly simple skill. The amazing thing is that they do it so fast, and without effort. Let me show you how it's done. The exact details may vary from one person to another.

First, you need to have at least one date that you know, like today or Pearl Harbor Day (Sunday, Dec. 7, 1941).

Then, someone asks for a date like May 12, 1961. Well, there are 20 years from Dec. 7, 1941 to Dec. 7, 1961. That's 20(years) x 365(days) + 5(leap days), or 7305 days. We are looking for May 12, however. So, we have to subtract off some days. May 7 to Dec. 7 is 7 months. Three of those months have 30 days, four have 31 days. That's 214 days. So, 7305-214=7091 days. And May 12 is 5 days more than that, 7096 days. How many weeks is that? Dividing by 7, we get 1013 weeks + 5 days. So, May 12, 1961 was a Friday (Sunday + 5 days).

Was May 12, 1961 a Friday? I'll look it up in my

*World Almanac*. Yup, Friday.

The process is simple. It just takes time, like counting to a thousand. Above I waited until the last step to divide by 7. But, at most steps we can divide numbers greater than 6 by 7 and just keep track of the remainders, which are the days of the week.

Well, there are short cuts, which these autistic people use. These short cuts are natural. And it is not amazing that people come up with them. For example, if January 1 is a Sunday, they know that July 1 is a Saturday on non-leap years (It would be a Sunday on a leap year). And they know that if January 1 is a Sunday, that the next January 1 will be a Monday (add 1 each year), or Tuesday with a leap day in between (add 2). With these tricks, you don't have to divide a large number by 7. This speeds up the process quite a bit.

Let's get down to some details of the shortcuts that I mentioned above. I used Pearl Harbor day as a starting date. To facilitate doing the math in your head, it is much handier to memorize a few January 1st's, to start with:

Jan. 1, 1950 | Sunday |

Jan. 1, 1960 | Friday |

Jan. 1, 1970 | Thursday |

Jan. 1, 1980 | Tuesday |

Jan. 1, 1990 | Monday |

Jan. 1, 1995 | Sunday |

Jan. 1, 1996 | Monday |

Jan. 1, 1997 | Wednesday |

Jan. 1, 1998 | Thursday |

Jan. 1, 1999 | Friday |

Jan. 1, 2000 | Saturday |

Jan. 1, 2001 | Monday |

Jan. 1, 2002 | Tuesday |

Jan. 1, 2003 | Wednesday |

Jan. 1, 2004 | Thursday |

Jan. 1, 2005 | Saturday |

You should be able to figure out the above pattern, for the last seven years of the table, which depends on when the leap years occur.

Now, when January 1 is on Sunday, we can memorize the following situation for the 12 months:

normal | (leap) | |

Jan. 1 | Sunday | Sunday |

Feb. 1 | Wednesday | Wednesday |

Mar. 1 | Wednesday | Thursday |

Apr. 1 | Saturday | Sunday |

May 1 | Monday | Tuesday |

June 1 | Thursday | Friday |

July 1 | Saturday | Sunday |

Aug. 1 | Tuesday | Wednesday |

Sep. 1 | Friday | Saturday |

Oct. 1 | Sunday | Monday |

Nov. 1 | Wednesday | Thursday |

Dec. 1 | Friday | Saturday |

The days for leap year can be deduced from the normal year. So they need not be memorized.

Now, do we need to memorize seven of these charts, one for each kind of January 1 (Sunday, Monday...)? Well, Monday is one day more than Sunday, and Saturday is one day less. These two can be easily deduced without memorization. The other days are not bad either. It should take two or three seconds to figure it out. But, I think that some of the people, who do these things in their head, may have memorized all seven tables (maybe fourteen, because of leap year).

Now, let's look at a typical month:

1 | 2 | 3 | 4 | 5 | 6 | 7 |

8 | 9 | 10 | 11 | 12 | 13 | 14 |

15 | 16 | 17 | 18 | 19 | 20 | 21 |

22 | 23 | 24 | 25 | 26 | 27 | 28 |

29 | 30 | 31 |

I did not label the columns as Sunday, Monday... The idea here is just that 1, 8, 15, 22, and 29 are the same day of the week. This sequence (or the easier 0, 7, 14, 21, 28) can be easily memorized. Then, given the day of the week for the first day of the month, using the above charts, we can easily deduce any of the other days of that month. I know what day of the week the first is, so I know what day of the week the 22nd (same day as the first) is, so I can deduce what day of the week the 25th (three days later) is.

We may need an example. Let's use my May 12, 1961.

Jan. 1, 1960 is a Friday (top table). 1960 is a leap year. So, Jan. 1, 1961 is a Sunday. That makes May 1 a Monday (second table). That makes May 8 a Monday (1 and 8 are the same day). We have to add four to get to May 12. That makes May 12 a Friday.

That agrees with my previous results. And you should be able to see how that can be done in your head.

###
**Addendum #1:**

Here is an easier method. We will use arithmetic, modulo 7 (just divide
by 7 and use the remainder). See Modular
Arithmetic. That means that we use the numbers 0 through 6 only, and 6 is
followed by 0. So, 5+4 (modulo 7) becomes 2. The days of the week will be
0=Sunday, 1=Monday, etc. up to 6=Saturday. We will use this formula:Where:

W=C+Y+L+M+D (mod 7)

**W**is the day of the week (0=Sunday, through 6=Saturday)**C**is a code for the century from this table (for the Gregorian calendar only):1400s, 1800s, 2200s 2 1800 is not a leap year 1500s, 1900s, 2300s 0 1900 is not a leap year 1600s, 2000s, 2400s 5 2000 is a leap year 1700s, 2100s, 2500s 4 2100 is not a leap year **Y**is the last two digits of the year.**L**is the number of leap days since the beginning of the century.**Step1:**Divide the year (two digits) by 4 and throw away the fraction.**Step 2:**Notice that 1900 and 1800 were not leap years, and 2000 was. Only century years divisible by 400 are leap years. So, add 1 for those centuries divisible by 4 (as we haven't counted the leap day for year 00 yet).**Step 3:**Also, don't count a leap day if it happens after the date that you are calculating. In other words subtract one, if you are calculating a date of January or February of a leap year.**M**is the code for the month, from this table:1. Jan. 0 5. May 1 9. Sep. 5 2. Feb. 3 6. June 4 10. Oct. 0 3. Mar. 3 7. July 6 11. Nov. 3 4. Apr. 6 8. Aug. 2 12. Dec. 5 **D**is the date.

Let's try 7/20/1969. We get 0+69+17+6+20 (mod 7) which is 0 (divide by 7 and get a 0 remainder), or Sunday. Looking that date up in the

*World Almanac*, I see that it is right. (Earlier I made two errors in this calculation, and it still came out as Sunday).

This method is similar to that above. But expressing it in a formula makes it easier. And you can get good at arithmetic modulo 7.

I have changed this addendum twice, because it contained errors, and was not very clear. My confusion was due to the century table. For each century year, the table gives the day of the week of the zeroth day, not the first day.

### Modular Arithmetic

### It is time that I defined it. Modular arithmetic deals with the remainders that we get from division. As an example, it is now 1PM; what time will it be in 129 hours? The answer is 10PM, and that was rather easy. It is 1PM, 120 hours leaves us at 1PM (5 days went by there), and 9 additional hours advances us to 10PM. We had 1+129 and got 10, and 130/24 gives us a remainder of 10. Technically, we call that arithmetic, modulo 24. And we deal with these number: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 2, ... As you can see, it is a loop. And we don't say that 130 is equal to 10 (as that would be confusing), we say that it is congruent to 10. The sign for congruence, here, is three horizontal lines, just as the equal sign (=) is two horizontal lines. I do not have a symbol for that in HTML, unfortunately. The clock shows us modulo 24, and 60. The calendar is modulo 7. Wednesday + 150 is Saturday, as 150 is congruent to 3 (mod 7) and Wednesday + 3 is Saturday. Anything cyclic is related to modular arithmetic.

77 is congruent to what (mod 3). The answer is 2. What about -77 in mod 3? The answer to that is 1. -77 is congruent to 1 (mod 3). We always get a positive number. And we can have fractions: pi is congruent to 0.14159... (mod 3).

**Addendum:**

Here is another definition, essentially from an encyclopedia:

This will help us deal with negative numbers, as my first definition allowed a negative remainder (-1 is congruent to 6 (mod 7)). Computer functions give usbis congruent toc(moda) means that (b-c) is divisible bya.

**c**less than

**a**and greater than or equal to 0. This number

**c**does not have to be in that range, unless we are looking for a specific

**c**. For example, 15 and 29 are congruent (mod 7), but they are both congruent to 1 (mod 7). It is sometimes OK to leave off the "(mod 7)," if the value of that modulus is perfectly clear from the context.

###
**Addendum #2:**

Apparently Uspensky and Heaslet gave the following formula, in
*Elementary Number Theory*, 1939, for the Gregorian calendar:

Apparently, no tables are needed. Floor() means to drop the fraction; floor(6.8) is 6.## W=D+floor(2.6m-0.2)+y+floor(y/4)+floor(c/4)-2c (mod 7)

**m**is the month starting with March as 1 and ending with February as 12. January and February of any year are considered to be in the previous year. I have not tried out this formula.

## 0 Comments::

## Post a Comment

Hope you enjoyed :)