 Hi everyone. So I thought it would be kind of fun to do some videos, maybe just exploring some fun or interesting computations that can be done, you know, without a lot of heavy mathematical machinery or background. So maybe, you know, for example, for this one, I might assume some background in maybe a course in undergraduate calculus, linear algebra, ordinary differential equations and that kind of thing. But maybe you don't necessarily need a graduate background in mathematics to see what's going on. So the one I wanted to talk about today was a computation that I really liked from my own undergraduate years. I was taking a discrete mathematics course and we had a section on recurrence relations. And at that time, I was reading this other book called Generating Functionology by Herbert Wilf. And he has a great sort of computation in the first chapter there, which shows how to derive the or derive a closed form expression for the Fibonacci sequence, which I thought was really neat and sort of exhibits how useful and interesting and magical generating functions are. These are one of my favorite topics. I thought it would be kind of fun to share it. So let me just kind of say what the goal is. If you haven't seen the Fibonacci sequence, don't worry, I'll tell you what it is in just a moment. But the idea is, given a sequence, it's just some ordered list of numbers. It makes sense to ask what is the nth entry in this list? What is the nth element of the sequence? And in general, you can sort of define sequences by recurrence relations where maybe computing the nth term involves maybe computing some of the k less than or equal to n terms, some of the stuff you've computed beforehand. But with this method of generating functions, sometimes I can just solve for that explicitly. You just ask yourself, wouldn't it be nice if somebody just handed me an n, I could tell you what the nth element in this list is without necessarily going back and computing all of the elements prior to n. So let me just say what the Fibonacci sequence is. This is a reminder. Or if you haven't seen it before, then maybe useful. This is the Fibonacci sequence. And there's just kind of a rule, a recipe for doing it. So there's a little bit of silliness. I have to tell you what the first two are. I could just give them to you. But after that, after that second term, there's a recipe. And it goes like the following way. You just take or the next term in your sequence, the way you obtain it is you take previous two terms and you add them up. So for example, here, I add these two up to get two. I add these two to get three for my next term, and these to get five. So on and so forth, five plus three, five plus eight is 13, eight plus 13 is one, so on and so forth, and continue off to infinity. So what I'll do is I'll maybe label these. This first element will be a naught. This second will be a one. This will be a two, a three, and then a four, and so on and so forth. The nth term of the sequence will be called a n. And it satisfies the following recurrence relation. Essentially, the recipe I just told you provided that you're in this sort of range beyond those first two that it took to get the sequence started, because you had to have two things to add up. So the recipe is the following, that if you want the a n plus first or the n plus first element of the sequence, you obtain it by looking at the nth term and adding it to the n minus first term. That's at least a formula for how to get it. And in general, a recurrence relation can be any function. So this a n plus one on the left hand side can be any function of k, where k is less than or equal to n. So it could include many, many more terms. It could also be like a much more complicated function. You could take something like that term and square it, or you could take a square root of the entire thing. You can sort of do lots of very complicated things with recurrence relations. But this will be sort of a linear recurrence relation. If you've seen something and you've seen a little bit of ODEs, ordinary differential equations, this is a very analogous to like a linear second order differential equation, ordinary differential equation. And so you might remember if you've seen that that differential equations, for example, sometimes you may not have a solution or you may have sort of a huge family of solutions. In order to pin down one solution, you need to sort of set some initial conditions or some boundary conditions. And that turns out to be the case here as well. This determines quite a lot of sequences. But I need to tell you what the at least two terms of the sequence are, the first two. And we decided above that we're going to start with one and one for these two here. And this is kind of the standard Fibonacci sequence. But in reality, I could just give you sort of, I could prescribe different values for this A0 and this A1. And you could still run the same recipe after those first two, and you would get some other type of Fibonacci sequence, which is related but not equal on the nose to this this sequence up here. This is enough to specify recurrence relation times Fibonacci sequence. And there's like a general method to solve these kinds of things. Well really, there are many methods just as there are many methods to solve a differential equation. So the method that we're going to be using is generating functions, which you can think of is an analogy to like solving an ODE using power series kind of solution and expanding. So we'll use generating functions. We'll also point out that there's there's a beautiful connection here. The same way in ODE is you can sort of do things like, you know, for linear second order ODE, you could look at this, I'm sure what does it call it, the characteristic polynomial or something, and sort of read off the solutions from the properties of that polynomial. And that kind of thing actually will work in this situation too. We'll use this generating function approach just to see how it goes. The reference, see did I write it down above? Okay, so now I'll write it here. The reference to see for this is chapter one of Wilf's generating functionology, generating functionology, a great book, and I highly recommend it. But I'll just go through the method that's discussed there for how to solve. Again, the problem is, is we want to find say what a n plus one is in just a closed form as maybe just a function of n, as opposed to a function of the a sub ns. So again, this saves me for having to compute all of these smaller ones in order to get the n plus first one. So the method roughly goes as follows. The first thing you do is you name your function. So I'll call it capital F of X. And it's going to be a generating function is really just a power series. I'm just going to write this power series a n. It's a sum over n bigger than zero, bigger than or equal to zero of a n times X to the n. The point here is that if you if you expand this out, you're going to see your sequence living inside of this series. This will be a not plus a one X. I'll say two X squared one. And so you can just see that the the ends on the a the exponents are really just keeping track of where the elements of your sequence are. So will cause this generating function is like a closed line upon which you you can hang your sequence. So really it's carrying the same information where it's carrying at least as much information as it turns out it miraculously somehow carries more information, which is why it's useful. So once we've given a name to it, you're sort of the the the main work that goes into what we want to do is really try to solve for this F of X as maybe some closed form kind of function that isn't a power series. You can imagine if these if these a n's were coming from a like a geometric progression. So if this was a geometric sequence, then we could sum this and get one over one minus X, which is a functional function of X. And that's kind of a really nice situation to be in. So we're going to try a name for something like that if I can get some kind of rational function of X for F of X, and maybe we can do some things with that maybe like expand it in a different way and get some handle on what these these coefficients might actually be as a function of event. So what you do is you start with your recurrence relation a n plus one equal to I just sum the previous two terms. And this there's kind of a weird step here. What you do is you multiply both sides by X to the n. So let me just do that. And for for everything that's happening here, you can just think of the X to the n. This is really just some kind of like formal power series. The X to the n doesn't really have meaning at this point. But later on, we might want it to so we might actually go out into complex plane and ask for this sequence to they converge uniformly on some small disc in which case we can start doing like analysis with this sequence. But for now we're kind of just doing algebra with it. So it's just some formal power series. The next to the end is just keeping track of where we are in that power series. The next thing you do is you take this whole thing and you sum it over all of the ends for which the for which the recurrence relation is valid. So that's that's kind of one tricky part here is that this recurrence relation, I should have mentioned here is only valid for in well in plus one. What I want to say here for in bigger than or equal to two, right? Because if I was in this situation of just being the first two, right, if I wanted to compute this one, I had to go and sum up the two previous ones, but I don't even have two previous ones until I'm out here. This recurrence relation is only valid for some specific range and we had these like manual initial conditions to specify the first couple. So what we'll do is some over I guess maybe this is valid for in bigger than one, I think is actually what I want to say here. Right, because we started we started counting at zero over in bigger than one. And I should be okay. What I do in this step is sum over in bigger than one. I have these these two terms in the sequences on on either side. So I've converted them into power series. And now it's mostly just about playing games with these sequences to somehow cook up. But I really want to see parts like this. And I want to rename some sequences things that look like f of x. What I'll do here is I'll note that so this is one on the coefficient doesn't match up with the the n's appearing in the exponent. So I can just kind of force that to hold by pulling out a power of x. If I just write one or x I can sum again over the same index set and plus one, I can put an x to the n plus one here. Right, because if I just multiply in this x, then I take a one off of that exponent. So I have the same thing on the left hand side. For the right hand side, I'm just going to go ahead and distribute the sum out into two sums. I think it's sum of n bigger than or equal to one of a n x to the n plus the sum of n in bigger than or equal to one of a n minus one x to the n. And so far, like this one is looking pretty good. It looks close to f of x, except for maybe up to some indexing I might need to fiddle with. This one I have kind of the same problem where the the index doesn't match the exponent, but I can force that to hold by see what do I need to do here. I can take a one off of the index at the expense of putting an x out in front. If I multiply that in it adds one to the exponent so I can undo it. And maybe now I just need to maybe I'll just rename some indices really quickly. Again, I just have this one over x on the left hand side. Let me sum over L's. And I guess I want this to be a to the L x to the L. I guess what I'm doing here is letting L be n plus one. I just have to figure out what the indexing set needs to be. L is kind of just a dummy variable that only lives inside of this this series. And this is bigger than or equal to two now. Right, because if n plus one is bigger than or equal to two and is bigger than or equal this one, I think I can just leave as is. And x to the n, this one I'm going to do the same sort of trick where I just reindex and I think I'll also call it maybe I'll call this one m and bigger than or equal to zero of a m next to the m. Here I said m to be n minus one. So really just setting whatever the exponent was up there to be this new variable and then figuring out what how I need to change the indexing to match that match up with that. Okay, so now a little bit of trickiness. What I realized is that what I have here is essentially f of x, except for the indexing is a little bit wrong. I've left off the first two terms. And just remember that f of x, this whole was just where I sum and x to the n over all and bigger than or equal to zero. Here, I'm summing over that for everything bigger than or equal to two, I can rewrite this as f of x. But then I'm subtracting off the first term. And also, all right, I've left out the first term and second term. And that's just exactly what this this series is, really just f of x, leave. So that's the thing there, leaving out the first two terms, which are those same deal here. This is really just f of x where I've left out the first term. This is f of x minus a not. And I'm adding on to it. I guess this one is actually, yeah, this one is f of x on the nose, because I'm summing over everything greater than or equal to zero. What I really want to do here is solve for f of x. And I see that everything else, right, so it's going to be some kind of rational function because these a knots, a ones that are showing up everywhere, these are just numbers. And it's going to be some powers of x, maybe some powers of one over x. So let's see. Maybe I'll just tell you what happens when we solve for f of x. It's not so bad. Let's just do it. So we get something that's like, let's move this f of x over here, like it's something like f x f of x. Or, let's see, let me let me do this part first. We have f of x minus a not minus a one x. And I'm just going to multiply this x through, like it x of x minus a not x x squared f of x. And now maybe it's easier to solve for this f of x. Like it's something it's like f of x is equal to we're going to have one this is going to be some fraction. What is going to be upstairs? I think we'll have we'll have this negative a not and then negative a one x. And maybe this I'm I guess I'm moving all of this left to the left hand side. So I guess I get a plus a not x. And then I think I get a one a negative one plus x plus x squared, I think. Okay, so hopefully that's right. We'll see you momentarily. I know the values of a not and a one. So what I get is negative one minus one times x plus one times x over negative one plus x x squared. And this whole thing is equal to well, these two cancel out negative one up here. So I'll push it through to the denominator. I get something it's like one minus x minus x squared, I've solved for what this f of x is and I got some rational function out of it. And this will turn out to be sort of useful. Right? So now I want to now run the game backwards and I want to try to find some other way to expand this out. And usually I'm going to try to see some kind of geometric series or something. That's that's a very easy thing to sum and find like a closed form for what I'll maybe do is try to apply partial fractions. So I'll get something that looks like one over one minus x minus x squared. Okay, so this is a in order to polynomial or quadratic. I'll just tell you it does factor. If you just plug it into the quadratic formula, you'll get two real roots. Maybe we'll write them in kind of a funny way. There'll be an r plus floating around and an r minus floating around. These will be the two roots you get out of the quadratic formula. And I'm also kind of writing this in. Well, okay, so these won't be the exact roots. You'll get some roots and then I'm calling r plus something more like a reciprocal root. Once you rearrange, you can get something of this form where r plus or minus will be equal to one half of one plus or minus root five. These these just happen to be the roots of this this polynomial. Let me move this out of the way a little bit. We won't need what these the actual values of these roots are until a little bit later. If we're doing partial fractions, I just have two linear factors here. So this will end up being something of the form a over one minus r plus x, just that first term. And then I can add b plus the other term or over the other term minus one over b over one minus or minus of x. And right, let's see. There is a clever way to sort of do this. Yeah, so let me see if I can explain what you do in order to find out what this value of a is. There's this sort of a cover up method. If you Google it, I'm sure you'll find a full description of how it works. The idea is if you want to compute what this a is, you go back up to this expression here, and you cover up the term corresponding to a. So this was this one minus r plus. That just means you cover up this one minus r plus. You're just thinking about just this fraction one over everything else. And in that everything else you plug in the thing that zeros this out. That's a little bit tricky. But what I mean here is a is equal to essentially this thing. But what I do by covering up what I really mean is I take this whole thing, and I multiply it by one minus r plus of x. Again, that's just this term with this term, which was the denominator for the b a. I'm just kind of removing that from the equation by multiplying it in. And I take this whole thing and I evaluate it at the thing that zeros out this term. The thing that zeros that out is x equal to one over r plus. So if you do that, what you get is something that's like one over. It's just this term that's left. And you get one minus. So r minus times one over plus that kind of thing. If you multiply it out, you get r plus over one minus r minus or sorry, maybe r plus minus r minus. So this thing is our value of a and the way you do this for b is almost it's really the same method works this cover up method. For those that are interested, this is really like some form of computing complex residues. So these are just like simple polls, polls order one, we're computing the revenue there. If you want to find b, you take this equation, you look at the thing that was involved in b in our original partial fractions. That was this r minus thing in the denominator. So you multiply that out to achieve the effect of covering it up. And so there's that term and we're multiplying it in to cancel it out. And then you evaluate at whatever thing would have zeroed this out. The thing that would have zeroed that would have been one over one, one over r minus. It's like that one minus one. And I'll just tell you if you run through the same steps. I mean, we can just do it. It's, it's over one minus x times r plus evaluated at one over r minus. So you get an r plus over r minus now. Earlier it was a r minus over r plus. If you multiply this through you get an r minus over r minus minus r plus a negative r minus over r plus minus r minus. That last step, it's not clear that we need it yet, but it's just to make it match up with the denominator that's happening here. It was an r plus minus r minus. This one was an r minus minus r plus. So it's useful to put in the negative sign. There is our a, there is our b. So we can go back to our partial fractions and write this out. Now, let me grab this, our original function. The whole thing we're trying to do is expand this one over one minus x minus x squared. And we found what a was a was negative r r plus over r plus minus r minus and b was the negative r minus. Let me just put the negative outside r minus over r plus minus r minus. And so this is kind of why having that same denominator is useful because we can pull it out. We get something like one over r plus minus r minus. And what we're left with is r plus over one minus r plus times x minus r minus over one minus r minus of x. Hopefully that works out. Yes. Okay, so everything looks good. We've done partial fractions. And what's really nice about this is that this is a geometric series, or at least, I don't know, we're assuming like everything's a formal power series. So maybe we can expand this as a geometric series in some small disk in the complex plane. But you can also just expand it formally using that right really quick one over one minus anything over one minus y, for example, is the sum over all indices bigger than the zero. And what do you put there? You put it's going to be a one and then a y to the n. But if you had some kind of like other t here, one minus t y, then this would be like a t y to the n. That's kind of what we're doing here where the t is an r plus or an r minus. And then this thing up here, we can just pull it out as a factor in the sum. Let me just write this another way of saying what this is is we have this whole term floating around out in front, whenever r plus minus r minus. And in here, we have r plus times a sum. This is n bigger than or equal to zero of, see, this should be r. And I want to say this is r plus x to the n. Okay, this will work. And we're subtracting off this r minus of the sum in bigger than or equal to zero of r minus x to the n. So what I'll do now is I'll multiply this term into the sum and multiply the term into the sum. And just notice here that I would get like an r plus to the n. And this is going to change it to an r plus to the n plus one when I incorporate this extra term. Same deal here, there's like an r minus to the n happening there. I'm going to get an r minus to the n plus one when I pull in that new term, the one over r plus minus r minus out in front. And we're multiplying this by the sum over the index set is still the same. We get an r plus to the n plus one times x to the n. And we're subtracting off a sum again over the same index set where it's r minus to the n plus one to the n. And these sums, these two sums have the same index set. So I can combine them by combining their terms. Let me just rewrite just part of this stuff. While it's happening here is I can just combine coefficients by grouping up all of the terms on a like exponent. Like an r plus to the n plus one minus r minus to the n plus one, all of that is showing up in the x to the n term. Okay. And I guess maybe I'll go ahead and just pull in this last thing here. So what I get is sum of this form in bigger than or equal to zero. And maybe I'll just write cn x to the n. And that cn is going to be let's say it's this thing r plus to the n plus one minus r minus to the n plus one over this thing that was out in front, one over r plus minus r minus. That's the coefficient of this power series. And I'll just tell you, you can sort of plug this into a symbolic calculator if you want to figure out just remember r plus minus, we had a number for that. It was equal to so you want to say one plus or minus root five over two, which I think is the golden show and maybe you don't quote me on that. I don't remember offhand if that's exactly what it is, but it should be very closely related. I'll tell you that actually, I guess it's pretty easy to see that if I take the positive one of these and I subtract off the negative, the only thing I'm left with is this root five one plus root five over two minus one minus root five over two, two root five divided by two. So there's a square root of five in the denominator and upstairs. You get something that maybe it's worth writing explicitly what it is this time. You have one plus root five one plus root five over two. That was the r plus and plus we raise that to the n plus one power and we're subtracting off this other term, which is one minus three five over two. That's the n plus first power. And we have some some kind of fraction like this. But that just is CN. And by the way, I should go back up the beginning here and realize the whole thing was actually f of x to be with this was our original generating function. So these CNs are actually the ANs from all the way back at the beginning because we said that f of x was the sum of an x to the n and we found some different power series expansion of it where the coefficients of these CNs. So the CNs have to be equal to the ANs. This whole thing is AN, which by the way is supposed to be our nth Fibonacci number. And so this is this is a closed formula for it, right? Because if you just give me the n, then I just plug it into this and then there's no a sub n minus one or a sub n minus two or anything like that floating around. It's all just a function of n, right? So there's an n plus one and plus two or n plus one. So this is our closed form. And there's actually something a little bit nicer. You can get out of this. So we're essentially done now, right? We found a closed form for it. You can plug this into a calculator. Remarkably, this thing is an integer is not all clear that this this thing would ever be an integer, right? Some something involving like square roots and fractions, then you're raising it to some crazy power, you're subtracting off something similar raised to a similarly crazy power, and you're dividing by a square root, right? So like super unclear that this would ever be even a rational number, much less an integer, but it must be, right? If you if you right, so it's just equal to the power series we had above where we constructed it where the coefficients were just integers. So yeah, some some kind of miraculous magic going on there. And then there's also something kind of nice here. We have the closed form. I want to talk a little bit about the asymptotics of this form for large n. If you think about n really, really big, kind of what happens to this term. In general, we wouldn't be able to say much. It's just some really big term potentially, minus some other really big term. But there's there's something kind of nice happening here where this term is strictly bigger than one. One way you can see that is root five is bigger than one, right? It's bigger than root four, which is two. This is like bigger than three halves. But it only matters that it's bigger than one, because if I'm raising something bigger than one to a big power, it gets bigger. So this term is going to be getting larger. And it turns out that this whole thing here is actually less than one. It's I think you even get it you can get a pretty tight bound on it to be like less than one half, for example. But the main point is it's less than one. And if you raise things that are less than one to a big power, they get smaller. So I'm saying here is that this whole thing has absolute value bigger than one. And this whole thing has absolute value less than one, which means that if you start taking really large powers of n, this thing is going to get really big. This thing is going to get really small. And so the dominating term if you have a large n, it's going to essentially look just like this with some marginal sort of small error coming from this term. You can ask yourself, we can try to approximate it, right? So just try the approximation. So for large n, we'll say cn, well cn and we know they're the same now. We just take the entire thing up here and forget about the the other term. And what's exactly equal to cn, cn would be exactly equal to this as I written it. But if I just take off the entire term, then I get an approximation. And the question is, is it just like, is it a good approximation or a bad one? If you think about the bound for a minute that this thing was less than one half, I guess I'll have to leave it to you to actually to show that it's not too bad, I promise. That actually means it's a pretty good approximation because one half, one over two to the n goes to zero pretty quickly. So what happens? Right, so yeah, this is the last thing. So since, okay, let me just write this. I could also write let me call this thing c tilde n. The c tilde n is just defined to be this ratio. So the an is approximately equal to that and was our number in the sequence here. I'm just taking some approximation where I left off that one term. So it turns out that sense, right? So this whole thing up here was plus to the n plus one. This whole thing here was our minus to the n plus one. So since absolute value Rn plus bigger than one, and you can show that the absolute value of Rn minus is less than one half, the difference between like the difference between the actual Fibonacci number and this approximation that we're taking where we've left off a term ends up being no more than one half. Just because we're neglecting a term here, whose magnitude is no bigger than one half. But now there's something kind of nice. And we know as an integer and CN is not an integer, right? Because we've left off some term. But it's no more than one half away from the correct answer. So if we just round it to the nearest integer, we'll get an exact formula, right? It implies that an is just equal to, I guess I know what great notation is for this, like CN tilde. And you might have to take the floor or the ceiling, depending. This is just the nearest integer function. And this formula is exact. This is an exact formula. Maybe since, right? Since the ands had to be integers to begin with. Really, they're natural numbers, but there you have it. Right. So let's just quickly recap of what we did. Go back up to the beginning here. Started with the Fibonacci sequence. We noted that there were like a bunch of different Fibonacci sequences. So I have to sort of specify these first two numbers to give you like the standard usual Fibonacci sequence. With this rule that you add to get the nth term in the sequence, you add the previous two. You turn that into a recurrence relation that's valid for some values of n, where you also maybe need to specify some initial conditions. And then you go into playing these games with generating functions again with the that the problem you're trying to solve is like, can I find some formula for an or an plus one that only depends on n and doesn't depend on all of the previous terms in the sequence? Right. You can imagine that it would be computationally much more effective to just plug your thing into a formula rather than computing, you know, if you want the one millionth term, you don't have to compute 999,999 previous terms to get it. We use this thing about generating functions, which gives you a way to get at this and being to take your sequence, wrap it up into a generating function, find some closed form for this F of X, this rational function of X, and then find maybe some different way to expand that closed form. Maybe it's like a geometric series or something, you get a handle on the actual coefficients in some different way. And then maybe with those actual coefficients, you can get some closed form from that. We did that. The method was take your recurrence relation, multiply everything by X to the n, and then some overall of the values for which that recurrence is valid. And then everything from here to here was just playing with indices to get F of X to show up and really just rewrite your sums in terms of F of X. So that way you can solve for F of X, hopefully as some rational function. And that ended up working here. We got a rational function out of it. We simplified things and found that it was, was this. So now I've wrapped it all up. The idea was to expand it back out again, maybe using geometric series. So we did partial fractions versus kind of cover-up method or sort of like computing a residue to get it as some function like this. And then we note that you can just kind of pull the A out in front. And then what you're seeing down here looks an awful lot like a geometric series that you can expand. So once you figure out what those coefficients need to be, they're just some numbers. You go back down here. You take these. We had some number out in front. We had these two fractions, which are like one over one minus X roughly. And then we expanded them out as geometric series. And then we just collected coefficients. And noted that the coefficients appearing were now just numbers. But they weren't the original A sub n's we started with, like we knew that that was abstractly some Fibonacci number. Now we're seeing it's some kind of root of that polynomial that came out of that denominator and the generating function. Once you have that, you can just read off the coefficients. The cn was this numerical value, whatever it was. And now you can kind of play games with this numerical value. And for example, you know, just plug things into it. You see it only depends on n. So I can just plug it into it and get my exact value of the Fibonacci number back. You can also just try to approximate it because in general, you'll get like a much more complicated kind of function out of this. But maybe you just kind of leave off some terms or something. And then if you can put like sufficiently nice bounds on your terms, like say, you know, your sequence is integer valued. If you're neglecting a term that's no more than one half away from the correct value, and your sequence is an integer, okay, just round your thing to the nearest integer and you'll get an exact formula. Okay, so I think that's pretty much all I wanted to say for this computation. I think it's really fun. A nice thing to work through gives you some handle on like how to work with series and their indices, some sort of non-trivial steps there. But I think it's that's a really fun thing to try and work through. All right, so if anybody has other ideas for computations they'd like to do or like to see, maybe just let me know in the comments or drop me a message.