 Based on my campus, this is a really busy, stressful time of year. So you've taken an hour for bonus math outside of what you have to do for class. I think that's pretty great. I really like giving this talk because I think the title is something all of you can relate to. I mean, there's no scary math words in this title, right? But when I say what's in your wallet, this is not a credit card commercial. I'm guessing you probably have a student ID. You might have lots of other things in your wallet. What I want to talk about today is coins. Again, something all of you have dealt with, right? Pennies, nickels, dimes, and quarters. You might be wondering how we're going to get a whole 45-minute talk out of this. Because surely you spent lots of time adding up coins maybe in grade school. You think it's all done. But I hope to convince you in the next 45 minutes that if you look at them the right way, there's actually a lot of interesting math hiding inside of here. But the first issue is not everybody spends their coins in the same way and so you can see my menu across the top here. I've come up with a few models of how I think people might spend their coins. And we'll talk about the mathematics that goes with each of those models of how people spend their money. So are you ready? I'll also say one more thing I tell all my classes on the first day. I show up for conversations. I think dialogues are more interesting than monologues. So if I ask a question, I hope even though we're just meeting just now, you're willing to tell me what you think. So don't be scared if I ask a question. That's my other disclaimer. But my first model is what I think is the simplest way to deal with coins. It's what my brother does. Do you have any guess what I might mean by coinkeeper? Sure. Piggy banks. Piggy banks, yeah. And it doesn't even have to be a piggy bank, right? It's someone who hangs on to their coins. My brother really doesn't like having coins in his wallet. And so when he has to spend cash, he pays in bills. And then sometimes he gets coins as change. And he puts them in his pocket, doesn't think about them until he gets home, and they go in a giant jar. So if you don't want to spend coins, you're just collecting them as you go throughout your day. And you put them in a piggy bank or in a jar if you're not quite as fancy. Here's my question to you. What percentage of the coins in the jar do you think are pennies? Any guesses? If you say something between 0 and 100, you're doing all right, because that's a percentage, right? We heard 90, we heard 50. I guess the majority. Over 50%. So we're thinking a lot of pennies. Do you have a reason for that, or it's kind of your gut feeling? Majority of the time is 2 cents, 90 months, and if you remove a penny, you screw up the whole system. OK, that's true. Pennies are involved in a lot more transactions than transactions that only take silver coins. So yeah, we'd expect a lot of pennies. Have I given you enough information to answer this question? Or do you maybe have a question for me? I heard something. Well, how many pennies? That would help me answer the percentage if I knew how many pennies and how many are in the whole thing, right? But I think I also need to tell you about my assumptions on how the pennies get in the jar. So here are some assumptions I'm going to use throughout this talk. First, I need some assumptions on what prices look like. And you can tell me if you think this is reasonable or not. I know you might look at this and say, a lot of prices end in 99 cents or 97 cents, so maybe I'm making things too simple. But here's my counter argument. When I go to the grocery store, I don't just buy one thing. I buy 10 or 15 or 20 things. And by the time I buy a whole group of things, I really can't predict what the coin part of my grocery receipt is going to look like as reliably as I can that a can of soup that probably ends in 99 cents. So if I'm buying a collection of things, I think this is a little more reasonable. And if you don't think it's reasonable, well, my homework to you is rewrite the talk with a new assumption for number one. Because this is the assumption I'm going to use to keep things simple for this talk. Number two, I think, is a little less controversial. I'm going to assume that when you spend money, the cashier gives you change in a predictable way. And even if you don't have math words for this predictable way, I think you know what I mean. So let me check my conjecture. If the cashier needs to give you 4 cents, what coins do you expect them to give you? 4 pennies, because that's the only choice, right? What if the cashier needs to give you 6 cents? What do you expect them to do? OK, but that wasn't your only choice. Why are they doing a nickel and penny instead of all pennies? Less change, right? So they're trying to be efficient. What about 41 cents? What do you expect? OK, one of each. If we're only dealing with pennies, nickels, dimes, and quarters, 41 cents is one of each. But that was one of 31 choices. So does the cashier have to think through all the possible ways to make 41 cents? Or is there a quick way for the cashier to make change? What do you think? What's that? I heard something in this direction. You could do four dimes, one penny. That's one option. But my guess is the cashier would probably do this, because this has five coins and this has four. So in my experience, the cashier gives me the fewest coins possible to make change. But do they really have to think through this whole list? I don't think so. I think they're actually doing something that's called the greedy algorithm. And so that might sound a little bit more like math words, but don't be scared by the inequalities here. What this says is if the cashier needs to give you C cents, they're going to give you as many quarters as possible without going over. Then they're going to look at C minus how much they gave you in quarters and give you as many dimes as possible. And after they're done with quarters and dimes, as many nickels and then as many pennies, so there is a quick way that cashiers often make change. And let's check that this setup makes sense with 47 cents. How many quarters would a cashier give you for 47 cents? One, right, because two is too many. It would go over 47. So now you have a quarter. How many dimes would they give you? Two, right? And now you're up to how many cents? 45, OK, still not so scary on the math, right? How many nickels? Zero, because if I gave you a nickel, I'd go over. And then how many pennies? Two, and pennies are the cleanup job. So this is called the greedy algorithm, where I give you as many large-valued coins as possible first. And then I just go down in size of coins, quarters, then dimes, then nickels, then pennies. But is this really the most efficient way to make change? Is this something you know? Or is this something you trust that this process will give you the least possible coins? Trust? I'm glad you're willing to admit that there's some thought that goes in here. Because let me take you to a different world for a minute and then come back to this. I don't think it's always obvious the greedy algorithm is the most efficient way to make change. For example, what if you only had 1 cent, 3 cent, and 4 cent coins to work with? What does the greedy algorithm say you should do to get 6 cents? Start with a 4, and then after the 4, what do you do? Two 1s. So the greedy algorithm will give you three coins to make 6 cents. Is that the best way in this world? What's better? Two 3s. So there are systems of coins where the greedy algorithm is not the most efficient thing. And people actually do research on this. Look at the year on this paper. I see everybody in here looks more than 12. So this is in your lifetime. This is a paper on you can input the set of coins you have available, and it will do a computation and say either greedy algorithm is the best thing to do or no, there are times like this where the greedy algorithm is not the best. So people actually think about these things. The change making problem is a research problem people talk about. And I'll tell you often the greedy algorithm is best. And in the world you live in with pennies, nickels, dimes, and quarters, it is. But it's not a trivial, obvious thing to say the greedy algorithm is always the best thing to do. So I've taken a little bit of a detour to tell you about my assumptions. Do you remember my original question? OK, you're all with me. This is awesome. So I want to talk about my brother's coin jar. And this was all a detour to be clear on my assumptions. If I'm assuming that all the prices happen equally often, if I want to get a snapshot of what's in that jar, I just need to think of one copy of each of these 100 transactions. And then I can tally up the coins. And that's the distribution of pennies, nickels, dimes, and quarters I expect to see in the long run in this jar. And well, if I'm charged $1, I know I'm getting nothing in change. But I can go through each of these transactions and say, what would the greedy algorithm give me? For example, if you got charged $0.76, you'd expect $0.24 in change. And this is how you'd expect it. And I don't want to make a list of 100 things, but my computer does it for me. And it says the total coins I have after all these 100 transactions are right here. And so there are more pennies than anything else, but it's actually slightly under half, interestingly enough. So this is the distribution I expect to have in my brother's coin jar. And this talk is actually based on a paper I wrote with a friend when we were writing it every so often I'd call my brother and say, tell me the percentage of coins you have. And this was actually a pretty good model for what he finds on his coin jar from time to time. So that's my first model, the coin keeper. Any comments or questions before I switch it up a little bit? That was my assumption at the very beginning. Remember if I go back here? And so yes, according to going way back here. That was my first assumption. So matching this assumption, that's what's going on. So if you think you have a better model for how the prices are, then you're welcome to redo this computation with a different assumption. But yes, for the sake of this talk, you correctly said the assumption I'm using. And I gave you my motivation for that. We usually don't buy things one at a time. We usually buy them in groups. And then that does even it out quite a bit. So good observation. And realize that's going to stick with me the rest of this talk to stay consistent. So yeah, if you don't think that's what models the prices you're spending, this is not quite the right computation. But assuming they're all equally likely, yeah, that's what you would get. And so now I'm going to show you a different way where you don't just collect coins, but you actually spend them. But I'll start simple with that too. And I'm just calling it the simple spender. So my friend Eric that I did this project with really hates spending cash money at all. And so he uses his debit card as much as possible. But there's one exception. The coffee shop down the street from his office doesn't take debit cards. So he has to pay cash then. And so the only time he spends cash is when he goes to get his latte. And his latte costs $5.20. And he doesn't like carrying coins. So if he has no coins, he's going to have to do like my brother and spend dollar bills and get some coins back and change. But he doesn't just take the coins home. The next time he goes to the coffee shop, he tries to get rid of some of his coins. So let's think about what Eric's wallet looks like. If he doesn't like coins, he starts out with no coins. After he buys his first latte, how many coins do you expect him to have? How many cents? 80, right? That's your change from $5.20. And now he goes and buys another latte. How much do you expect him to have? 60, because he can do the bills on the side. And then he can spend $0.20 of his $0.80 to work on getting rid of them. What happens after 60? 40, and then back to start. So Eric's wallet kind of moves in a cycle. If you know how much money is in his wallet right now, you have a 100% chance of knowing what it's going to be after his next transaction. And it only takes one slide to analyze Eric's wallet. But I want you to be on the lookout for this kind of behavior as we move through some more complicated models. This is what I'd call cyclic behavior, where when you know what you have at one point, there is a 100% chance of where you're going for the next transaction. Does that definition of cyclic behavior make sense? All right. Well, then we're going to go to something a little fancier. In fact, we're going to go to another planet and talk about some coins that don't look like ours to work on building up to the whole big picture at the end. So we're going to go to a planet I call Markovia. And their coins look kind of like Skittles. They come in two colors. They're kind of high tech. So in Markovia, they're not using these coins for spending money. They're using them for playing the lottery. And their lottery is a little bit weird. So let me explain the details, and then we'll just have the summary version on the next slide. When you go to play the lottery, you go and buy one of these Skittle looking tokens. And it comes all wrapped up, and you open it, and there's a 50-50 chance that it's red versus that it's blue. And then to keep the drama up, they have 10 rounds of the lottery. So in each round of the lottery, your Skittle looking coin might stay the same, or it might change color. And then after 10 rounds of this, everybody who has a blue coin shares the prize of the end. And so we're going to analyze these red and blue coins. Again, this is my shorthand. So this first row says, at the beginning, there's a one-half probability of having a red coin, one-half of having blue. And then these other two rows tell me the probability of changing from one color to the next in one round of the lottery. So starting red and staying red has a 2-thirds chance. Starting red and changing to blue has 1-third. And then similarly down here. Does it make sense how to read my table? OK, so instead of all these words, I'm just saving the table on the next slide. This is the main information you need to know about this lottery. And to check that these probabilities make sense, I have some questions for you. So if I have a blue coin now, what's the probability that it's going to switch red in the next round and then blue right after that? Any thoughts? I could take half the question. If I have a blue coin now, what's the probability it'll be red in the next round? So if I have a blue coin now, the probability it's red in the next round is 3-fourths. And then I said after that it changes from red to blue. What's the probability of changing from red to blue? 1-third, what should I do with those two numbers? Multiply them, because I want one thing to happen and the other thing to happen. When you want two things both to happen, you need to multiply 1-third times 3-fourths on a good day as 1-fourth. There is a 1-fourth chance of having blue, then red, then blue in subsequent rounds of the lottery. Are you with me? Let's get a little more fun, because that still doesn't tell me if I win. What's the probability you have a completely undramatic coin that when you first get it, it's blue, and it stays blue for the whole lottery? Any thoughts on how I'd compute that? OK, 1 over 4 to the 10th tells me blue to blue. That's most of it. What else do I need besides that it goes blue to blue at each of the 10 rounds? Yeah, yeah. So it'll be combining those two. I need to start with having a blue coin. That's what that 1-half is. And then for each of these 10 rounds where my coin may change color, I need to multiply by 1-fourth, because that's the probability of having blue and staying blue. So 1 over a little more than 2 million, not very likely that you have an undramatic coin. There's a bit of hype going on here. Do you understand where these probabilities are coming from? I still haven't answered the big question yet, though. If you're playing the lottery, you don't care if you have an undramatic coin. It could be red, blue, red, blue, red, blue, as long as it ends on blue. That was the rules of this crazy lottery. So what's the probability you actually share the prize at the end of 10 rounds? I think this is at least a little more complicated. You can agree on that, right? In fact, the answer is we need to talk a little bit about this model called a Markov chain. So a Markov chain is a model for exactly this kind of situation where you have a finite list of things that could happen. The only things that can happen here are I have a red coin or I have a blue coin, only two possibilities. And the only probabilities, the only way that events are related are going from one time step to the next. So the probability I have a blue coin now just depends on what color I had one round ago. Doesn't matter what color you had five rounds ago. The probabilities all go from one time step to the next. And it turns out to answer this question, it's going to help if I stop writing a table and break this up into two matrices. Because do you see there's really two kinds of probabilities running around in this table? In the first row, these are probabilities about what color coin you have at just one instant in time. And these four are really transition probabilities about going from one step in time to the next. So I'm going to break these up into two matrices. That first matrix I'll call a vector because it's just one row. You see in red the probability of starting with a red coin. And in blue the probability of starting with a blue coin. And then this square matrix tells me about my transitions. I've color coded them again. So this first row still stands for starting with a red coin. This is the probability of going from red to red. This is the probability of going from red to blue. And similarly on the next line. Exact same stuff that was in your table. But now I've put it into matrices because it's two kinds of probabilities. And I claim if you want to know what's going on, I steps into the lottery. You really just need to take that initial vector and multiply it times this two by two matrix I times. So to convince you of that, let's see if we can remember how to multiply two matrices. I have a one by two matrix times a two by two. How big of a matrix should I get when I multiply those? One by two. Okay, so that's a good size if I'm looking for a snapshot of red versus blue at one moment in time. And think about how you actually multiply these to get my one by two matrix. The first entry is gonna be this row times this column. So you notice the one half times two thirds is there. The blue one half times the three fourths is there. And to get this second entry, I'm gonna take that vector times this column. And so same idea. You see the red one half times the blue one third. You see the blue one half times the blue one fourth. And I hope these colors convince you where these numbers are coming from. What are we computing here? This is starting red and staying red or starting blue and changing to red. These are the two ways to have a red coin one step into the problem. Did that make sense? I see some nodding. I see no one looking angry, so that's a good sign. Over here, what does this represent? Okay, starting red changing to blue and what does this represent? Starting blue, staying blue. So these are the two ways to have a blue coin one step into the problem. And so one step into the problem, there's a 17 24th chance of having a red coin and a 7 24th chance of having a blue coin. How would I figure out the probabilities two steps in? Do it again. That's right. If I wanna go one more step in time later, I'm gonna take this times this matrix. And sparing new details, that's two steps. And if you wanted to go 10 steps in, what would you do? Yeah, keep multiplying by P one more time for each round of the lottery you wanna do 10 steps in. There's a 30.77% chance that you get to win the Markovian lottery, pretty generous lottery. But it's a good model for trying to follow what's going on with all this matrix multiplication. And you remember what I called this whole setup here? It's called a Markov chain, right? Markov is somebody's name. I wanna tell you a little bit more about Markov chains. So there's a few kinds of Markov chains and it's really important that we understand which kind we have before we move forward going back to our forward and back before we go back to our original set of American coins. So here are some of the things that can happen in Markov chains. Think about this lottery and do you think each one of these applies or doesn't apply? So one kind of Markov chain behavior to look out for is absorbing states. Remember our states here are you have a red coin or you have a blue coin. An absorbing state is a state where once you get to that state, you're stuck there for forever. Does our Markov chain have any absorbing states? Okay, no. If you have a red coin, there's always a chance it could be red or blue on the next round. If you have a blue coin, there's always a chance it could change on the next round. So we don't have absorbing states. A practical example of an absorbing state might be if your high school tracks whether students are freshmen, sophomore, juniors, seniors, what happens after senior? Yeah, hopefully you graduate and if they still keep track of their alums, right? Graduated is an absorbing state because once you've graduated, you're not gonna go back to those other states. So that's not a coin example, but we wanna look out for those. Our lottery does not have absorbing states. Ciclic behavior is when you have a bunch of states where you cycle predictably between them forever. Have we seen Ciclic behavior in this talk? Okay, where? Okay, the simple spender, my friend buying his latte, right? He had a very predictable, only one kind of time he spent his money and so his wallet went in a cycle. Does our lottery act in a cycle? Okay, no, you could go back and forth between red and blue, but it's not like if you have a red coin, there's 100% chance it'll be blue next and 100% chance it'll be red next. Cycle means when you're in one state, there's a 100% chance of knowing where you're going next. So ours isn't absorbing, it isn't Ciclic. If your Markov chain isn't absorbing and it isn't Ciclic, it's probably regular. So our Markovian lottery chain, lottery example is regular. Here's the math definition of regular. Do you remember what P stood for on the previous slide? Which matrix was that? It was the square one, right? That two by two one that told me my probability of what happens from one round to the next round. The official definition of a regular Markov chain is one where this transition matrix to some power has no zero entries. So what does that mean in practical terms? It means think of your favorite state in the Markov chain and think of your second favorite state in the Markov chain. If you wait long enough, there's a non-zero chance you'll get from point A to point B. That's what that means. If you wait at least n steps, you can get anywhere in the Markov chain. So our Markov chain for this lottery is not absorbing, it's not Ciclic, it's regular, which means I actually know a strategy for figuring out what would happen if we kept playing this lottery instead of 10 rounds, but for forever. So let me tell you how to figure out what's really going on in the long run in this lottery because it's regular. Here's the idea. If you have a regular Markov chain, in the end it's gonna settle into this long-term probability distribution of here's the percentage of the time I have a red coin and here's the percentage of time I have a blue coin. It's gonna stop wavering around and kind of approach a limit. And so if you have this vector of probability of having a red coin and then probability of having a blue coin and it really is the long-term distribution, when you multiply times this transition matrix, you should get back the same thing. That's what long-term distribution means. And so if I wanna figure out what would happen from playing this Markovian lottery for forever, well I really need to do that vector of probability of being red, probability of being blue times my transition matrix equals that vector again. And so notice these equations are what I get from multiplying these two matrices. Do you have an idea where this last one comes from? Yeah, yeah, has to equal one, that's right. So this whole list of numbers in L, there are a bunch of probabilities that run through all the possible states. The sum of those probabilities has to be one. And so I can solve this system of equations and it says if you play the Markovian lottery for forever, there's a 913th chance of having a red coin and there's a 413th chance of having a blue coin. So this strategy right here of finding the long-term probability is the strategy I'm gonna use moving forward. I just always have to check that my Markov chain is regular before I try this strategy. So now I'm ready to go back to real coins. We went to Markovia so that we had an example that we could see really well. But do you have any questions about this example before I go back to US coins? Yeah. So yes. So whenever you have one of these transition probability matrices, what's the sum of each row here? One, right? And so as a consequence of that, the last equation I write here is always going to be dependent on previous things. And so you do need this. Yeah, that's gonna scale it down to actually be probability size. So yeah, it looks like I have one too many equations, but as a consequence of this being a row of probabilities summing to one, the last one that came from here is unnecessary. Good question. Other questions or keep going. Because we still gotta get back to those coins at the beginning of the talk, right? I don't think we're quite ready for all of them though. So let's start with a slightly simpler example. Let's pretend we live in a world that just has quarters and 50 cent pieces and all our prices end in multiples of 25. What are some possible collections of coins you could have in your wallet in this world? Okay, if you're really poor, how many coins are in your wallet? Okay, could have zero. What's another collection of coins you could have in your wallet? Okay, you could have 25 cents. What else could you have? 50, how many ways are there to have 50 cents? Two. And there are two ways to have 75 cents. And if you're determined to spend your money, you're never gonna have more than this. Because if I get to here and I'm charged some amount of money, I'm gonna spend and get rid of some of it. So this is an example that instead of two states has six states, and I can play the same game as I did for the Markovian lottery and set up this transition matrix. So here my rows and my columns are labeled in this order. Let me talk through, for example, the first row here. So this first row is your probabilities from starting with an empty wallet and then ending with empty or 25 cents or 50 cents and so on. Do you understand why the entries are all zero or 1 fourth? Why 1 fourth? What was my first assumption in this talk? I'm assuming what about the prices? Yeah, that they're equally distributed. And so there are four possible charges I could have, zero cents, 25 cents, 50 cents, or 75 cents. And I'm assuming that they're equally likely. So there's a 1 fourth chance of starting with an empty wallet, getting charged zero cents and staying with an empty wallet. There's a 1 fourth chance of starting with an empty wallet, getting charged 75 cents and then ending up with 25 cents and change. Let's see, this one is starting with an empty wallet, getting charged 50 cents and then getting a 50 cent piece efficiently and change. And then this one over here is starting with an empty wallet, getting charged a quarter and then getting this in change. And so you won't get to here or here in one step from the empty wallet but there's a 1 fourth chance of going to any of these four because we were assuming the prices are distributed uniformly. I could talk through another row if that helps or you can say that makes sense go on. What's your feeling about this matrix? Okay, okay, so I sat there and I thought through all the options, right? Starting with an empty wallet, starting with 25 cents and so on. This is my transition matrix for this particular situation. And let's see, what kind of Markov chain am I hoping this is? What was the vocab word? Regular, regular means that no matter what two wallets states you're thinking of, if you wait long enough, there's a non-zero chance you'll get from point A to point B. I promise that if you take this matrix to the third power the zeros go away. So if you trust me, I've checked. This is a regular Markov chain and I can use my strategy. So I want this list of six probabilities of what's the probability of having an empty wallet? What's the probability of having just a quarter and so on in the long run? To find the long-term probability I'm really solving this equation. Well, there's six variables here. So I have six equations that came from the transition matrix. And again, this last one is all my probabilities gotta add to one. Again, no one wants to do that by hand, really. So I get my computer to do my work and it says this is the answer. One fourth of the time I expect an empty wallet. One fourth of the time I expect 25 cents. Does that surprise you or no? Why should I one fourth of the time have an empty wallet? Because what am I assuming? Yeah, I'm assuming the prices are evenly distributed which also means the amount of change in my wallet is evenly distributed between zero cents and 99 cents. And if there's only one way to have an empty wallet, one fourth of the time I'm gonna have an empty wallet. There's only one way to have 25 cents. So one fourth of the time I'm gonna be in this state. There were two ways to have 50 cents. So notice these add up to one fourth of the time but a 50 cent piece is a little more likely than two quarters. And I'm gonna have 75 cents one fourth of the time but apparently it's a lot more likely to have a 50 and a 25 instead of three quarters. So the machinery still works, it just got a little bit bigger than the Markovian lottery. Comments, questions, concerns, or scale it up because we're getting close to what I promised at the beginning but I wanna make sure you got the steps along the way. How are you feeling? Okay, I got some nodding, I got some thumbs up. You look happier than my calculus students on a Monday so that's good. So now you see my title, the whole shebang. We're gonna think about what happens if I use pennies, nickels, dimes and quarters. It's gonna be bigger than six by six. So first again, let me go over my assumptions. These are the ones I've had the whole time. Number one, I'm still assuming the fractional parts are distributed uniformly. You can either say that's an unrealistic assumption and rewrite the talk with a different number one or you can say okay, I get it if you buy things in groups. I'm assuming cashiers return change using the greedy algorithm but I also need some assumptions on how you're using your coins. So here are some assumptions I'm gonna make about how you spend your coins for this particular version of the model. So number one, if the coin part that you're being charged is more than the amount of coins in your wallet, you're just gonna sit on it and get change. So for example, if you have 25 cents and you get charged something that ends in 32, you'll say okay, whatever, I can afford to get more coins. But if you have more coins than the coin part of your price, I'm gonna assume you overpay by as little as possible. For example, if you were charged something 29 and you have 30 cents, you'll pay the 30 cents and then just have a penny in change. Did that make sense? But you don't have arbitrarily many coins to work with and so sometimes there might be ties. Like right, there's two ways to make 30 cents. Maybe you have a quarter and a nickel and you also have three dimes and so if you have to break ties, I'll assume that you go for the big coins first. You would rather spend a quarter and a nickel than three dimes and you can redo this where you change the assumptions but for the purpose of the example I'll show you, this is how I'm assuming you're spending your money. So the first thing we need to figure out is does this make sure that you never rack up infinitely much money? Like is there a maximum amount of coins you expect in your wallet? How much is the maximum you think might be in your wallet if you spend in this way? Okay, 99 cents and we can prove that. If you have 99 cents before a transaction at most, you'll still have at most 99 cents after, right? Because if you had more money than you were charged, you're gonna pay and have even less. So that's starting with 99 or less and ending with 99 or less. What if the price is more than what's in your wallet? Well, you're gonna stick with your money that's in your wallet and you'll get 100 minus P and change and notice I've just regrouped the parentheses but this is the same quantity. It's 100 minus a positive number so it's still less than 100. So yeah, it's true. There's a cap on how much is in your wallet with my assumptions, you have at most 99 cents. Before I set up a matrix, what kind of Markov chain am I hoping is going on here? Regular and regular again means no matter what wallet state you think of, wallet state A and no matter what wallet state you think of, wallet state B, if you wait long enough, there's a non-zero chance that you can get from A to B. I'm gonna give you a recipe to get from your favorite wallet state A to your second favorite wallet state B to convince you this is regular. This might not be the most efficient way, but it is a way. So let's say you're in wallet state A. You have your favorite wallet state in mind. Is there a way to get from there to the empty wallet? How much would you have to be charged to get from your favorite wallet state to the empty wallet? Yeah, exactly that amount. And since you have at most 99 cents, that's an option. So in one step, you can get from wallet state A to the empty wallet. And now I claim there's a smart sequence of charges that will get you from the empty wallet to whatever you thought of as wallet state B. Pretend you're trying to get to a wallet state that looks like this. Well, if you have the empty wallet and you're hoping to rack up Q quarters, I'm just gonna keep charging you 75 cents and you're gonna keep getting Q quarters and change. And since this wallet state is at most 99 cents, you're trying to get at most three quarters. That 75 cent charge is still always gonna be more than what you have in your wallet at the moment. So doing this first will rack up Q quarters. Then after you've racked up as many quarters as you were hoping for, you have at most 75 cents. So getting charged 90 cents, you're gonna sit on it and start racking up dimes and so on. This is a recipe that gets you from any wallet state you wanted to start with to the empty wallet and then from the empty wallet to this other one in at most Q plus D plus N plus P plus one steps. So it's regular. Didn't promise this was the most efficient route but no matter what collection of coins you have, less than 99 cents and whatever collection of coins less than 99 cents you were hoping to get to, there is a way to do it. This is regular so my plot I've been using will work. How big do you think the matrix is? We've seen a two by two and a six by six. How many states will there be if you're trying to model all the ways to have up to 99 cents? Any estimates before I show you? Thousands, like how many thousands? Okay. Does anyone wanna say high or lower? Exactly right. It's big. It's bigger than six. Do you have a reaction? Okay. 99. 99 total states? 99, it's a nine. Okay. A nine X. Yeah. I'll point out that you can have up to 99 cents but there's more than one way to make most of those so it's gonna be more than 99. In fact, if you have at most 99 cents, right? You have at most 99 pennies, at most 19 nickels and so on. If you just multiplied all the options for pennies, nickels, dimes and quarters, it'd be 80,000 but most of those are overkill, right? Cause if you have 99 cents already in pennies that forces you to have zero of the others. So again, I get my computer to do my work when I can. I had the computer go through all of these 80,000 possible states and say, yeah, that many survived and are less than or equal to 99 cents. So more than 5,000 but you're in the right ballpark. 6,720 rows, 6,720 columns and I'm not gonna actually write out all the digits but I'll zoom out and show you a picture of it. This is the zoomed out version of this matrix. The almost 7,000 rows, almost 7,000 columns. You can think of the white spaces entries that are zeros and then we were assuming the prices are evenly distributed so there's all those black dots stand for one over 100s. So there's 100, one over 100s in each row and a lot of zeros. And if you've had linear algebra already this next paragraph is for you, if you have not don't stress it won't matter on the next slide but I do wanna connect it to things people who have seen linear algebra before might recognize. This equation that we've been using all along should look familiar from linear algebra. If we find a vector where L times this transition matrix equals L, we're really finding an eigenvector that goes with eigenvalue one, right? There's a nice theorem called the Perron-Ferbenius theorem that you don't have to stress out about too much but it says if your matrix is full of probabilities like this, the largest eigenvalue is one and the largest eigenvalue is called the dominant eigenvalue. So when we do this we're really looking for what's called the dominant eigenvector. And if you've taken linear algebra you see the size of this matrix and go there's no way I'd wanna find all the eigenvalues and eigenvectors and my computer feels that way too but there are special algorithms to find the dominant eigenvector. So good news, the special algorithms work for exactly what I need. So 25 hours in the computer later I get out this giant vector of the long-term probabilities of all these 6,720 states. Why are these first five not surprising? Yeah, those are the amounts of money where there's only one way to make that amount of change and so I expect to see them one one hundredth of the time. When you get to five cents, apparently most of the time you'll see five cents as five pennies and then the rest of the time is a nickel which didn't even make the top hits list. But this just looks like a bunch of data so maybe you'd enjoy it repackaged as trivia. So the expected number of coins in your wallet is slightly more than 10. And here's the distribution of expected number of pennies, nickels, dimes, and quarters in this model. Fun fact, if you look up how many coins are in circulation by the US Mint, this is a lot closer to what the US Mint has out than my brother's model of just throwing it all in the jar for whatever it's worth. This one was not surprising. We saw it on the previous slide. One one hundredth of the time you expect your wallet to be empty, but almost 60% of the time you expect to have at least a nickel, almost 96% of the time you expect at least a penny, a little over 8% of the time you'll have only pennies and it's a little bit less than 1% a chance of being able to pay any price with exact change. So you can figure out all kinds of things if you believe the assumptions in my model. But let's see, that's not the whole story. We've been questioning assumptions throughout this, right? So was that price distribution the reasonable thing or do you really act like a coinkeeper or do people really spend money the way I describe? My friend and I realized not everybody spends money in the same way and so we tried out a few other options and I won't go into great detail about them because I see the time but here are some things we looked at that I think might be fun to think about who does this. So penniless purchaser, that's someone who only uses nickels, dimes, and quarters. Who's a penniless purchaser? Well, if you're Canadian you are because they stopped minting pennies five years ago. Okay, so that's a model with a lot less states. You only have the silver coins. In fact, it's 213 states I think and I can say more about that in questions if you're curious. Who doesn't use quarters? What's a reason not to use quarters? To pay tolls. To pay tolls or maybe live in an apartment and you gotta save them for your laundry? Some interesting things happen if you only use pennies, nickels, and dimes because what might've looked like four cents versus 54 cents before, you swipe the quarters and those collapse to be the same thing. So it's suddenly more likely than 1% of the time to see four cents if you're swiping your quarters on the side. When we were setting this up I told my collaborator I don't think I spend like the thing we just did. I think I try to match the ones digit in my prices with pennies first and then I treat the silver coins like we just described. So we ran that too. And then this last one's weird. Jeff Shallott is a Canadian mathematician who wrote a paper called What This Country Needs is an 18 cent piece and it wasn't just crazy talk. He was asking another optimization problem with coins. He wanted to know what collection of coins should we have if we want to minimize the amount of coins you would hand over per transaction. And he discovered that you'll have less coins handed over if you replace dime with an 18 cent piece and you see that's in your lifetime as well, right? So there are mathematicians who think about these kinds of things for fun. So I've purposely put in shortcuts here. My slides will be available to you after the talk if you're interested. But I'm going to skip to the end here. What do I hope you got out of 45 minutes of coins? Two things I hope. Number one, always think about your assumptions, right? They affect the kind of answer we get. So if you're trying to model something, assumptions matter and it's good to question them and make sure they're really modeling things as accurately as you hope. There's something else too. And to get at that, let me show you a quote from one of my favorite books. This is from Letters to a Young Mathematician by Ian Stewart. He says, I sometimes think the best way to change the public attitude to math would be to stick a red label on everything that uses math, math inside. There would be a label on every computer and I suppose if we were to take it literally, we ought to slap one on every math teacher. Good luck trying that. But we should also place a red sticker on every airline ticket, every telephone, every car, every airplane, every traffic light, every vegetable. I would add every wallet. I hope this has challenged you to look at the everyday objects that you see all the time and think a little bit more about the math behind them. So this was based on a paper I wrote with a friend a couple years ago. If you're interested to see more details, you can look at the paper. An early version of the paper was reviewed by a Scientific American blog and that's actually a fun read too. I'd recommend it. And if you're interested to see the parts I skipped over at the end, the slides are already on my website. Thanks for listening.