 What's up guys my name is Michael and welcome to my YouTube channel today We are going to go over the Fibonacci numbers because I haven't actually made an explanation tutorial in a long time Okay, so you probably know what Fibonacci numbers are Basically, it's just taking the previous term plus the term before it and then they'll be your next term And that's what this equation that is divine as that's the Fibonacci numbers So if we take a look at here in the next next picture here, we have 0 1 1 2 3 5 8 13 21 34 55 89 And the reason why this is that is because 0 plus 1 is Equal to 1 and that's the next number of 1 then 1 plus 1 is 2 and that's the next number 2 1 plus 2 is 3 and that's the next number 3 2 plus 3 is 5 That's the next number 5 3 plus 5 8 5 plus 8 is 13 8 plus 13 21 13 plus 21 is 34 21 plus 34 is 55 55 plus 34 is 89. So that's basically the gist of Fibonacci Numbers alright now there's a few properties that are pretty interesting that you probably haven't heard about yet But they might actually come in handy alright the first property is Cassini's identity Which basically is just telling you that if I take the previous term Then multiply it by the next term then subtract by the current term squared It'll tell you the the current sign right You if I did it'll tell me if the current sign that the current number is on so it would tell me a negative 1 to the End and that's just will tell you the current sign of what it's on so that's pretty that's pretty cool I guess but you might May or may not need it, but it's a cool identity anyway alright the next rule is the addition rule so basically it's just taking the Current term and if I jump by the case steps to the to the right right that term is just going to be Whatever value is that the case step? multiplied by the next term added by the Previous term for the case value multiplied by the current term so that's just I know this is like a handful It's kind of confusing, but yeah, that's basically what the addition rule is basically if I jump by case steps Whatever value the in my next case step is it would just be The value at the previous at the k-term multiplied by the next term Plus the k-1 term multiplied by the current term. So yeah All right guys now if you were to substitute k equal to n because this property works And if you were simplifying it Basically, this is the same like if I take two times n like that if I'm on the nth term I take two times n that's going to equal to nth term multiplied by the term right after it plus the term before it So because of that previous property if you take any number k and you multiply it by n of the nth term That this number of the Fibonacci number is going to be a multiple of the nth term So that's pretty cool. You could use that Pretty crazy with GCD though Alright, so the inverse is also true if the mth term is a multiple of the nth term Then we know m is a multiple of n. Okay, this identity is kind of crazy If I just take the GCD of the mth term and the nth term of the Fibonacci sequence, right? That's number is going to equal to the GCD of individual m and n that m and n and that That term is the answer to the GCD So that's pretty that's pretty crazy though. I didn't know you could do that, but that's that's a thing in Fibonacci okay, so you could also represent Fibonacci as binary numbers and I think I don't know why but hey, this is a thing So to do this you would use a simple greedy algorithm. You're gonna loop through the Fibonacci numbers from the largest to the smallest Until you find one that is less than or equal to n and then suppose this number was f of i right then we're gonna subtract this number from n and then put a 1 in the i-2 position of the binary number the binary index from left most right most bit and then we're just gonna keep repeating this until there is no remainder at the end we add a 1 to the final code word in the end so then that would basically just tell us the representation of the binary code So yeah, and if you see here f of 2 is 1 1 f f 3 is 0 1 1 f of 5 plus f of 2 is 1 0 1 1 F of 6 is 0 0 0 0 1 1 f f of 6 plus f of 2 is 1 0 0 0 1 1 F of 7 plus f of 5 plus f of 2 is 1 0 1 0 1 0 1 1 okay Okay, so the next cool property is that you don't have to actually Repeatably add up numbers and a loop using a loop You can actually do this in constant time without actually using any loops using this equation So f of n is equal to 1 plus square root of 5 over 2 to the nth power Subtract by 1 minus square root of 5 over 2 to the nth power divided by a square root of 5 So this is a property that was created using something called generating functions. I'm not like a hundred percent Sure how they came up with this formula, but it does does work though are the next property is that if you were to put these The previous term in the current term in a matrix. It's going to equal to the two previous terms before multiplied by the matrix 0 1 1 1 Okay, and if you were to denote the this matrix is 0 1 1 1 as p You'll realize that the current term and the next term is equal to The 0th term and the first term multiplied by p to the nth. So we're going to raise the power of P the matrix p to the nth power and then multiply by f of 0 f of 1 And I'll get you the nth term and the nth plus 1 term Okay, so the last property is basically just using the binary exponentiation of the previous Previous property that we had before and then it's going to use this to calculate the Fibonacci numbers I don't see a reason to explain the this code because you could just black box it anytime you need it You could just copy and paste this but basically this code returns f of n and f of n plus 1 as a pair and it solves the binary Exponentiation and it solves the faster way to calculate the Fibonacci numbers pretty quickly. So yeah Hope you guys enjoyed this video rate com subscribe. I'll check you guys later. Peace