1

AKS Meets Pascal

Published on Thursday, February 06, 2014 in , , , ,

TED-43's Pascal's triangle imageIn mathematics, there are many times where you explore an apparently simple idea, and you find unexpected beauty.

Numberphile has recently been posting about tests for prime numbers, also referred to as primality tests, and their latest one fascinated me because of the amazing patterns involved.

Their first video on this topic was about Fermat's primality test, and the fascinating concept of liar numbers. However, I'm going to discuss their more recent video on the AKS primality test, named for the last initials of the authors, Manindra Agrawal, Neeraj Kayal, and Nitin Saxena:



Let's examine this formula a bit closer, with the help of Wolfram|Alpha. The command used to find the expanded form of an equation is simply the command Expand[]. So, if we wanted to find out the expanded form of (x-1)3, we simply enter it as Expand[(x-1)3], and just like in the video, we get the result x3 - 3x2 + 3x - 1.

As in the video, if we subtract x3 - 1, we're left with - 3x2 + 3x, and both coefficients are divisible by the original power, 3, so we know we've got a prime.

Let's try that with the power 4, resulting - 4x3 + 6x2 - 4x + 2. While 4 is obviously evenly divisible by 4, the numbers 6 and 2 are quite obviously not, so 4 isn't prime.

Note that the powers of x don't really matter much, so perhaps it would be nicer to just look at this problem without all the variables and powers getting in the way. Since the AKS test starts with the simple form of (x - 1)p, all the resulting coefficients (the numbers multiplied by the variables and their powers) are simply what are known as binomial coefficients.

Don't worry, binomials are easy to understand when taught properly. They're basically the number of ways k things can be combined of n possibilities without regard to the exact order. BetterExplained.com's post on permutations and combinations makes this clear. What you really want to focus on in that post in the part about combinations, as they are also known as binomials.

Wolfram|Alpha uses the command Binomial[n, k] to work out these combinations, also read as n choose k. For example, entering Binomial[8, 3] gives us 56, telling us that there are 56 ways 3 items can be combined from among 8 possibilities. The Mind Your Decisions blog's fresh fruit puzzle explains how binomials are used in probability.

Now, if we want to see just the coefficients of the cube of (x - 1), we can combine the Binomial[] command with the Table[] command in Wolfram|Alpha to read Table[Binomial[3, k], {k, 0, 3}]. This command is telling Wolfram|Alpha to work out the possible combinations of 0 objects from among 3, then the combinations of 1 object from among 3, then the combinations of 2 objects from among 3, and finally the combinations of 3 objects from among 3, and to put all that information in 1 horizontal table. The result is {1, 3, 3, 1}, which are the same numbers from the calculation above, but without all those messy variables and powers to spoil the view!

Just for fun, let's throw in the Column[] command, and go through the same process for all the numbers from 0 to 10, by entering the command Column[Table[Binomial[n, k], {n, 0, 10}, {k, 0, n}]]. Does that pattern of binomials look familiar?

.                     {1}
                     {1, 1}
                   {1, 2, 1}
                 {1, 3, 3, 1}
               {1, 4, 6, 4, 1}
             {1, 5, 10, 10, 5, 1}
           {1, 6, 15, 20, 15, 6, 1}
         {1, 7, 21, 35, 35, 21, 7, 1}
       {1, 8, 28, 56, 70, 56, 28, 8, 1}
    {1, 9, 36, 84, 126, 126, 84, 36, 9, 1}
{1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1}
If it looks familiar, it's because you probably know it as Pascal's Triangle! I've talked about it before, most often in my annual 12 Days of Christmas post, but also in my Happy 10/11/12! post. I think it's interesting that a test for primes has lead us to Pascal's Triangle!

You might note that all the binomials in Pascal's Triangle are positive, while the multiplication of (x - 1) to various powers gives us alternating positive and negative signs. This is easily remedied, by multiplying every other number in the command above by -1. However, the signs really don't matter in the AKS test, as -35 is just as evenly divisible by 7 as +35, so I'm going to ignore the signs from here on out.

Another thing to notice about the binomials in Pascal's Triangle is that the entire pattern has left/right symmetry. For example, the binomials in the 8th row, representing the coefficients for (x - 1)8, are {1, 8, 28, 56, 70, 56, 28, 8, 1}. The first 5 a different, {1, 8, 28, 56, 70}, but then they start going back down from 70 in the same way they built up. By taking advantage of Wolfram|Alpha's Floor[] command, and only going halfway across each table, we can shorten the list of coefficients we need to examine by half!

Also, remember in the text that for any power p, xp is subtracted, which effectively removes the first coefficient from the list. So, by starting at the 1st coefficient instead of the 0th, we can trim the list even more. Not surprisingly, this eliminates the tables for the power of 0 and 1, so we'll just start the list with coefficients of the power of 2.

At this point, we can look at just the coefficients for any power, without getting the numerous variables and powers in the way, and we've minimized the numbers we need to examine at each step. It's time to run through the AKS primality test again. For each of the numbers 1 through 10, it's not hard to see whether the coefficients are divisible by those numbers, because we're so familiar with them. What about numbers on a larger scale?

Let's turn our Pascal's Triangle generator into a generator for a single power, so we can run tests on individual numbers. We remove the Column[] command, and set n to an individual number. I'm going to use 71 for the first test, since James Grime uses that example at about the 2:20 mark in the video above. The result is this horrendous-looking set: {71, 2485, 57155, 971635, 13019909, 143218999, 1329890705, 10639125640, 74473879480, 461738052776, 2560547383576, 12802736917880, 58104729088840, 240719591939480, 914734449370024, 3201570572795084, 10358022441395860, 31074067324187580, 86680293062207460, 225368761961739396, 547324136192795676, 1243918491347262900, 2650087220696342700, 5300174441392685400, 9964327949818248552, 17629195603524593592, 29381992672540989320, 46171702771135840360, 68461490315822108120, 95846086442150951368, 126764178842844806648, 158455223553556008310, 187265264199657100730, 209296471752557936110, 221256270138418389602} *PHEW!*

Since few of us are familiar with our multiples of 71, you can't easily tell whether all these numbers are evenly divisible by 71. If you could verify that, then this test and our refinements via Pascal's Triangle will verify that 71 is a prime number. If all these numbers were evenly divisible by 71, then there would be no remainder. We can take advantage of this by using modular arithmetic!

If we simply take each of the above numbers, and apply mod 71 to them, we get a far simpler result: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} Every number is clearly divisible by 71, so 71 is prime!

Using the AKS primality test this way, you can set n to any number, and instantly tell whether than number is prime. Do you see any numbers other than 0? Then it's not a prime number. Is the number 391 prime? If you set n to 391 in this test, you'll see plenty of numbers that aren't 0, so you know 391 isn't prime.

If nothing else, I hope you get an idea of where exploring one idea in math can lead you to some surprising places. Sometimes, it's just fun to explore!

3

Danica McKellar's Math Bites

Published on Sunday, February 02, 2014 in , , , , , , , , ,

Danica McKellar's Math Bites seriesNo, I'm not insulting Danica McKellar's math ability, I swear! I even sell her math books over in the Grey Matters Store!

Math Bites is actually the name of Danica McKellar's new weekly video series from Nerdist, which started last month.

Math Bites can be found on YouTube, and you can subscribe to the Nerdist channel for regular updates, as well.

Each episode is only about 5-6 minutes long, and focuses on one math topic. The style is somewhat like that of Square One TV, in that there are short comedy skits and musical segments that help reinforce the concepts or give you breathing time to let the concepts sink in. I especially like the takeaway tips at the end of each episode, which summarize the important points of each episode.

The first episode focused on a topic near and dear to my heart, the constant Pi:



While many Grey Matters readers have memorized Pi to 400 digits, some might prefer the full Dance of the Sugar Pi Fairy to help them memorize Pi to 139 digits.

The second episode talked about the importance of being able to do math in your head. No, this episode doesn't talk about extraordinary mental math feats like those taught in the Mental Gym, but rather knowing how to do basic arithmetic and estimation well enough so that you don't get ripped off:



You can already get an idea of why I like this series so much. It touches on the basics of topics I've posted about many times before. I've posted about binary numbers both on their own, and their importance in Nim, so the 3rd episode on binary numbers was also helpful and entertaining:



The most recent episode as of this posting is about percentages, and focuses on how they can mislead you. Sometimes you can get taken advantage of when businesses can't do math, and also when businesses can do math, so percentages can be very important to understand:



Even if you missed the initial announcement of Math Bites, you're now completely caught up with the series. Here's hoping that Danica McKellar keeps this series up for a long time to come!

0

10% of Your Brain?

Published on Thursday, January 30, 2014 in , ,

US National Institute on Aging, Alzheimer's Disease Education and Referral Center's PET scan of a normal brainOne of my major pet peeves, as many Grey Matters know, is the portrayal of memory and understanding as opposite ways to learn, instead of simply two approaches that can aid each other.

Today, we turn to another pet peeve of mine, the classic myth about people using only about 10% of their brains!

TED-Ed recently posted a wonderful video, titled What percentage of your brain do you use?, that takes apart the classic 10% myth from many different angles. It's quite an eye opener!



If you're registered at the TED-Ed site, you can delve into the full lesson here.

That's all for now, but I'm glad to finally have a decent reference to which I can refer people about this all-too pervasive myth. Enjoy this food for thought!

0

Yet Still More Quick Snippets

Published on Thursday, January 23, 2014 in , , , , , , , , , , ,

Luc Viatour's plasma lamp pictureFor January's snippets, I'm featuring an unusual mix.

This time around, I've got 3 different things for you: Math, memory...and Macs?!?

• Numberphile took a breather from their usual number videos to do something a bit different. They interviewed UC Berkeley professor Edward Frenkel with the question, “Why do people hate mathematics?” It's an interesting topic and well worth your time:



• In the video above, they talk about the important roles of math teachers. Longtime Grey Matters readers know that I'm not just a big proponent of memorizing, but rather memorizing along with understanding. Above and beyond great sites that aid in mathematical understanding, such as BetterExplained and Plus magazine, there's also an excellent free ebook called Nix The Trix. It's aimed at students who are great with shortcuts, but never took the time to understand the foundations of what those tricks are actually doing. It can help teachers undo the damage by showing how to teach the actual mathematical basis, which is also a great help in understanding when to use the math tricks.

• Almost just in time for this month's snippets, Reddit featured an interesting and popular thread asking, “What are some things worth memorizing?” Yes, of course, there are the usual array of sarcastic and silly answers, but if you take the time to wade through some of the roughly 12,000 comments (at this writing), there are some great ideas. I won't rob you of the joy of discovery, especially as the reply you most enjoy may not even exist yet as I write this!

• If you've ever memorized something with the help of spaced learning, where the concept you're trying to memorize is reinforced 3 times at spaced intervals, you know how powerful it can be. There's now an online web service called MemStash which help you do this almost automatically. You save things you wish to remember by highlighting them in an online page, and then clicking a special MemStash bookmarklet. After that, they'll send you 3 reminders at spaced intervals, which can help you recall what you saved!

• OK, this last snippet isn't really along the usual Grey Matters topics, but I thought it would be fun to sneak it in. 30 years ago this week, the Apple Macintosh computer first came on the market. During Super Bowl XVIII on January 22, 1984, they aired their now-classic 1984 ad, announcing the upcoming release of the Macintosh on January 24th. The lesser-known January 24, 1984 introduction of the Macintosh has also been preserved on video:



That's all for this month's snippets. I hope you enjoy them!

0

Knight's Tour

Published on Sunday, January 19, 2014 in , , , , , ,

Mbdortmund's chess knight photoI love it when two old friends visit and get along!

Numberphile recently took a look at one of my favorite challenges: The Knight's Tour! This is a chess-based puzzle that challenged some of the greatest minds in mathematics.

In a rare video appearance, Brady himself describes some of the fascinating aspects of the Knight's Tour in the following video:



If you'd like to try the Knight's Tour out for yourself online for free, I've created 2 versions you can play. This version is in the Mental Gym (select level 1 for the classic challenge), and here's a more modern version hosted on Dropbox (select “New Game” > “All 64 Squares” for the classic challenge).

When it's a new challenge, it can seem quite difficult. Often, you get past about 50 squares, and then start having difficulty. If you want to be able to tackle this challenge, I have provided a complete Knight's Tour tutorial over in the Mental Gym. If you can understand and remember a few simple patterns, you can not only solve the Knight's Tour starting from anywhere, you can even have someone select a starting AND ending position, and still be able to solve it!

My dropbox version of the Knight's Tour offers various settings, including the ability to show a numbered path, as in the video. This version also auto-detects whether the numbered path is a semi-magic square, as discussed in the video, starting at about the 2:23 mark.

If you can learn to solve it, as in the Mental Gym tutorial, is it possible to learn to start anywhere and create a semi-magic knight's tour square? The answer is almost. Magician Harold Cataquet has done some incredible work on working out just how to do this, and it's written up in the ebook Mind Blasters, by Peter Duffie. If you're really interested in being able to the Knight's Tour AND finishing with a semi-magic square, the article is worth the price of this one book alone.

As Brady mentions in the video, there's an amazing amount of mathematical research done on the Knight's Tour. You can see many of the directions in which this challenge was taken over at Knight's Tour Notes, for a start.

Play around and enjoy the Knight's Tour. If you have any interesting discoveries you'd like to share, I'd love to hear about them in the comments!

0

Mutus Nomen Dedit Cocis

Published on Thursday, January 16, 2014 in , , , ,

Scam School logoNo, I'm not just putting random filler text in the title.

Ever hear the expression “the oldest trick in the book”? In this post, you'll learn about a card trick that certainly qualifies, as it's known to date back at least as far as 1769!

I'll start by letting Brian Brushwood perform and explain his version of this classic routine (YouTube link):



Now, you'll note that Brian teaches this with the words:

MUTUS
NOMEN
DETID
COCIS
Usually, the 3rd word down is DEDIT (note the switched T and final D). Brian's version still works because there's still two of each letter, so there's still ways to arrange the cards.

The original pseudo-Latin words, while traditional, can be hard to remember. Fortunately, over the years, many English substitutes have been developed for this trick. Specifically, you need are N words of N+1 letters each (for example, 4 5-letter words, or 5 6-letter words), each of which have only 1 doubled letter, set up so that any pair of words shares a common letter.

In the long-running Word Ways magazine, they've been playing with this idea since 1969. In pages 185-186 of the August 1969 issue, they mention the following English arrangement as an already-standard substitute:
BIBLE
ATLAS
GOOSE
THIGH
Editor David Silverman goes on to propose 2 original alternatives, as well:
LIVELY
RHYTHM
MUFFIN
SUPPER
SAVANT

PILLAR
RHYTHM
MUFFIN
CACTUS
SNOOPY
At the end of a November 1968 article, mentions the challenge of developing a list of 6 7-letter words, which would require the use of 21 different doubled letters of the alphabet, as well as most of the deck (42 cards, obviously).

It wasn't until February of 1972 that the first answer arrived:
MEACOCK
RODDING
GUFFAWS
TWIZZLE
RHYTHMS
KNUBBLY
In the May 1994 issue of Word Ways, Christopher McManus used computer analysis of word lists to take things to an entirely new level, in “Goose Thighs Rehashed”.

Although you probably won't use it, often, A. Ross Eckler did manage to develop versions using all 26 letters and all 52 cards in his article, “A Card Trick Mnemonic Revisited”.

Play around, and memorize your favorite mnemonics for this routine, and I think you'll be surprised by not only the reactions you get, but your own abilities to remember them, as well!

0

Happy 27th Anniversary, Square One TV!

Published on Sunday, January 05, 2014 in , , , , , , ,

Square One TV logoObviously, I'm a big fan of mixing math and fun. It's time to give a little credit to one group that's responsible.

27 years ago this month, Square One TV, a PBS show teaching math with the use of comedy skits, music videos, and guest stars, premiered!

2 years ago, on Square One's 25th anniversary, I posted a tribute to this show, including some of my favorite segments.

At the time I was unable to provide links to complete episodes. Since then, however, several complete episodes have been uploaded to YouTube! Not every episode is available (yet?), but the complete episode guide will give you an idea of what's missing.

I've arranged the full episodes I can find into YouTube playlists by season, with the individual episodes arranged in order of broadcast. The season 1 playlist begins with the original IBM show promo, and then moves on to the very first episode. Here are all the YouTube playlists:

• Season 1
• Season 2
• Season 3
• Season 4
• Season 5

If you watch at least 1 full episode, you'll note that roughly the last third of each episode is dedicated to continuing segment called Mathnet, a sort of mathematical Dragnet parody. Square One TV originally aired Monday throughly Friday each week, so these segments always started a new adventure on Monday, and continued through with the conclusion reached on Friday's episode.

One of the downsides of not having every episode of Square One available is that it's difficult to watch complete runs of the Mathnet adventures. Fortunately, fans have solved that problem by posting 26 of the 30 episodes on YouTube, which you can find in this playlist! The complete Mathnet episode guide, which includes spoilers, can help you catch up on the ones which still aren't available.

I hope you enjoyed this mathematical walk down memory lane. I'll leave you with my favorite segment of Square One TV, a video about how to solve almost any type of problem title “Change Your Point of View”:

1

Day & Moon Phase For Any Date in 2014

Published on Thursday, January 02, 2014 in , , , , , , ,

Dafne Cholet's Calendar* photoHappy New Year!

With a new calendar year, you deserve a couple of new calendar feats to go with it. In this post, you'll learn how to quickly give the day of the week AND the moon phase for any date in 2014.

Even better, both of these feats are much easier than they sound!

DAY OF THE WEEK FOR ANY DATE IN 2014: The method to do this is quite simple, and is known as the Doomsday method, originally developed by John Horton Conway. Don't worry, learning this method for one particular year is very simple.

The "Doomsday" from which the method gets its name always refers to the last day of February, whether it's the 28th or 29th. For 2014, the "Doomsday" is Friday (Feb. 28th, since it's not a leap year). If you think about it, you can already work out any date in February using just this knowledge.

For example, Valentine's Day, Feb. 14th, must also be a Friday, because it's exactly 2 weeks before Feb. 28th. How about Feb. 2nd (Groundhog Day)? Well, Feb. 7th is a Friday, and Feb. 2nd is 5 days before that. What's 5 days before a Friday? The answer is Sunday! Therefore, Groundhog Day will be on Sunday in 2014.

It's also fairly simple to learn the even-numbered months. There's a very simple pattern to remember them: 4/4 (April 4th), 6/6 (June 6th), 8/8 (August 8th), 10/10 (October 10th), and 12/12 (December 12th) will always fall on the same day of the week as the "Doomsday" (the last day of February, remember?).

On which day will Christmas fall in 2014? We know December 12th is a Friday, so 2 weeks later, December 26th, is also a Friday. Since Christmas is one day before that, it must be on a Thursday this year!

The odd months aren't much harder, but the patter is not the same. 5/9 (May 9th) and 9/5 (September 5th) will also always fall on the Doomsday, as will 7/11 (July 11th) and 11/7 (November 7th). This is easy to remember with the following simple mnemonic: "I'm working 9 to 5 at the 7-11". It helps you remember that 9 and 5 always go together, as do 7 and 11.

When is July 4th this year? It's exactly 1 week before July 11th, so it must be a Friday, as well. If you've got all the previous dates down, you've already got the mental capability to determine the date for 10 out of the 12 months!

The easiest way to handle March is to think of Feb. 28th as also being "March 0th". Working forward from March 0th, it's easy to see that March 7th, 14th, 21st and 28th will all be Fridays. St. Patrick's Day, March 17th, is 3 days after March 14th, so it's 3 days after a Friday, making it a Monday in 2014.

In January, it's usually the 3rd day of the month that falls on the Doomsday. In a leap year, however, January 4th falls on the Doomsday. Remember it this way: "3 times out of 4, it's January 3rd. On the 4th year, it's January 4th." In 2014, since it's not a leap year, you only have to recall that January 3rd is on the Doomsday (Friday, for 2014).

January 15th is Martin Luther King, Jr.'s birthday, but what day does it fall on in 2014? January 3rd is a Friday this year, and so is January 17th (2 weeks later). Take back 2 days, and we get January 15th being a Wednesday this year!

With the above knowledge, and a little practice, you can quickly and easily determine the day of the week for any 2014 date. You could get practice at the Day For Any Date (Mentalist Challenge) page, changing the year to 2014, and then trying to determine the date before you click the Show button.

When you're demonstrating this ability for someone, it's nice to be able to prove that you're right about the date. I use QuickCal on my iPod Touch (similar calendar are available for many portable devices).

MOON PHASE FOR ANY DATE IN 2014: 1 year ago, I posted a new tutorial about determining the moon phase for any date. Similar to the year calculations, focusing on a particular year like 2014 greatly simplifies the required calculations. Like the doomsday algorithm above, this formula was also developed by John Conway.

In fact, working out the moon phase for any date in 2014 is even simpler than working out the date! How simple is it?

(Month key number + date - 3) mod 30

It's probably best if I explain each part:

Month key number: January's key number is 3, February's key number is 4, and all other months' keys are their traditional numbers; March is 3, April is 4, May is 5, and so on up to December, which is 12.

Date: This is simply the number represented by the particular date in the month. For the 1st, add 1. For the 2nd, add 2. For the 3rd, add 3, and so on.

- 3: The subtracting of 3 takes the starting point of 2014 into account, which is why this particular formula works ONLY for 2014.

mod 30: If you get a total of 30 or more, simply subtract 30. Otherwise, just leave the number as is. Betterexplained.com has an intuitive explanation of modular arithmetic.

The resulting number will be the approximate age of the moon in days, from 0 to 29. This formula only gives an approximation, so there's a margin of error of ±1 day.

As an example, let's figure the phase of the moon on July 4, 2014. July is the 7th month, and the 4th is the date, so we work out (7 + 4 - 3) mod 30 = (11 - 3) mod 30 = 8 mod 30, which is just 8.

In that example, we estimate the age of the moon to be 8 days old.

What exactly does the age of the moon in days mean in practical terms? Here's a quick guide:

  • 0 days = New moon (the moon is as dark as it's going to get)
  • 0 to 7.5 days = Waxing crescent (Less than half th moon is lit, and it's getting brighter each night)
  • 7.5 days = 1st quarter moon (Half the moon is lit, and gets brighter each night)
  • 7.5 to 15 days = Waxing gibbous (More than half the moon is lit, and getting brighter each night)
  • 15 days = Full moon (The moon is as bright as it's going to get, and will start getting darker each night)
  • 15 to 22.5 days = Waning gibbous (More than half the moon is lit, and it's getting darker each night)
  • 22.5 days = 3rd quarter moon (Half the moon is lit, and gets darker each night)
  • 22.5 to 29 days = Waning crescent (Less than half the moon is lit, and it's getting darker each night)
So, our 8 day old moon from our example, with a plus or minus 1-day margin of error taken into account, means that the moon could actually be 7-9 days old, so it will likely appear as close to half lit, and getting brighter each night. You can even verify this with Wolfram Alpha.

If you have any experiences or thoughts you'd like to share about memorizing the dates and moon phases for the 2014 calendar, I'd love to hear about them in the comments below!