The Fastest Multiplication Algorithm

  Рет қаралды 93,850

Dr. Trefor Bazett

Dr. Trefor Bazett

Күн бұрын

Keep exploring at ► brilliant.org/TreforBazett. Get started for free for 30 days - and the first 200 people get 20% off an annual premium subscription!
How can you multiply two enormous numbers? We all learn an approach in school which has n^2 total multiplications by single digit numbers. The first improvement was the Karatsuba Algorithm which uses a divide and conquer approach and a bit of clever algebra to reduce 4 multiplication to 3 (in 2x2 case) and more generally to about n^1.58 multiplications asymptotically. For a computer with a 32-bit hardware multiplier, one can iteratively apply the approach until the numbers are within the size of the multiplier. Toom-Cook is a generalization of the Karatsuba Algorithm and is useful in various cryptography applications, but a real change happened with Schonhage-Strassen which use discrete fast fourier transforms to get to O(n log n log log n) complexity, used for applications like the Great Internet Mersenne Prime search. The theoretical best result is Harvey and Hoeven who achieved O(n log n), albeit this becomes more efficient for only impractically large numbers.
0:00 Review of normal multiplication
1:42 The Karatsuba Algorithm for 2x2
3:32 Example of Karatsuba
4:34 Karatsuba for larger numbers
5:45 Complexity of Karatsuba for size 2^k
7:09 Computer architecture and hardware multipliers
8:26 Newer algorithms (Schonhage-Strassen, and Harvey and Hoeven)
12:46 Brilliant.org/TreforBazett
Check out my MATH MERCH line in collaboration with Beautiful Equations
►beautifulequations.net/pages/...
COURSE PLAYLISTS:
►DISCRETE MATH: • Discrete Math (Full Co...
►LINEAR ALGEBRA: • Linear Algebra (Full C...
►CALCULUS I: • Calculus I (Limits, De...
► CALCULUS II: • Calculus II (Integrati...
►MULTIVARIABLE CALCULUS (Calc III): • Calculus III: Multivar...
►VECTOR CALCULUS (Calc IV) • Calculus IV: Vector Ca...
►DIFFERENTIAL EQUATIONS: • Ordinary Differential ...
►LAPLACE TRANSFORM: • Laplace Transforms and...
►GAME THEORY: • Game Theory
OTHER PLAYLISTS:
► Learning Math Series
• 5 Tips To Make Math Pr...
►Cool Math Series:
• Cool Math Series
BECOME A MEMBER:
►Join: / @drtrefor
MATH BOOKS I LOVE (affilliate link):
► www.amazon.com/shop/treforbazett
SOCIALS:
►Twitter (math based): / treforbazett
►Instagram (photography based): / treforphotography

Пікірлер: 170
@Bunnokazooie
@Bunnokazooie Жыл бұрын
I remember my professor saying nlogn might be possible, and then a few years later Harvey-Hoeven proved it! A video on the discrete fourier transform would be awesome. I want to understand how decomposing wave functions has applications in things like multiplication, factoring, and discrete logarithms.
@DrTrefor
@DrTrefor Жыл бұрын
Cool! Ya at some level it should be nlog n just based on the complexity of fast fourier transforms, so all the extra baggage in the early algorithms was just that
@DavidvanDeijk
@DavidvanDeijk Жыл бұрын
@@DrTrefor isnt FFT also a lot of multiplications?
@user-pb8yw8cw3s
@user-pb8yw8cw3s Жыл бұрын
Radix algorithm
@struful
@struful Жыл бұрын
I believe 3blue1brown did a very solid video on FFT a month or so ago
@rogerphelps9939
@rogerphelps9939 Жыл бұрын
The multiplication algorithm is a bit like a convolution which can be replaced with a single multiplication in the transform domain.
@swagatochatterjee7104
@swagatochatterjee7104 Жыл бұрын
The most brilliant part of Karatsuba's algorithm was that he took it up as a challenge to prove Kolmogorov wrong (claim that the lower bound cant be any lesser than n^2) and came up with this brilliant manipulation. Like damn dude , like how confident do you have to be to challenge and disprove perhaps one of the greatest mathematician of the USSR, rather the world! He did all this while he was just a student.
@DrTrefor
@DrTrefor Жыл бұрын
Very cool!
@wyattstevens8574
@wyattstevens8574 6 ай бұрын
It was a very clever manipulation- maybe he went through the steps I outlined in my comment.
@swagatochatterjee7104
@swagatochatterjee7104 6 ай бұрын
@@wyattstevens8574 bro I can't find your comment
@williamchamberlain2263
@williamchamberlain2263 Жыл бұрын
Note that in a program multiplying by a power of two can be just a bit-shift. But you have to recognise when it's a power of two
@mertaliyigit3288
@mertaliyigit3288 Жыл бұрын
The similar algorithm for every number is called binary exponentiation. For example, if you had to multiply x with 24, you first multiply x with 16 with bit shifting, then you multiple x with 8 with again bit shifting, then add those 2 numbers
@JasonMitchellofcompsci
@JasonMitchellofcompsci Жыл бұрын
@@8ightfold Yeah. But that if statement is branching. If you care about speed then clearly you are handling a lot of data so instead you can use AVX/SIMD to multiply many elements, and an unrolled loop to do many of those. The micro-code of your processor is very well coded to stream many of these operations back to back. Or you can ruin it all with an if statement.
@davidhand9721
@davidhand9721 Жыл бұрын
Every old software multiply I see is like this: fn multiply(a, b) { sum = 0 while (b) { sum += a if b & 1 left shift a right shift b } } That's n time where a and b have n bits. Not sure why you guys are doing anything else.
@gregorymorse8423
@gregorymorse8423 11 ай бұрын
So multiplication is O(1) or O(n) depending on if wires or RAM is in play if your number is in base b and you multiply by b^k. However since you must convert to and from that number system, the complexity of base conversion will again not be better than n log n. So the fact you point out though practically useful in digital systems isn't really going to improve things.
@gregorymorse8423
@gregorymorse8423 11 ай бұрын
​@David Hand addition is O(n) and therefore you just described gradeschool multiplication or an O(n^2) algorithm. Not sure what universe you are from but in this one addition is not free. Not to mention bit by bit is terrible in computing performance. All real implementations do it a machine word at a time treating a hardware machine multiply as O(1) which is massively faster than what you wrote e.g. 1024 times faster on a 32 bit system. After n is around 30 to 50, Karatsuba will start to outperform. You might want to try it and do performance measurements before jumping to conclusions.
@bhavesh.adhikari
@bhavesh.adhikari Жыл бұрын
Recently, I wrote a program in C implementing the grade-school multiplication algorithm. It's working fine for multiplying two numbers up to around 130 digits long, but the result for numbers greater than 130 digits starts to differ slightly from that of Wolfram Alpha. I don't know what the issue is. Well i guess it's time to try the Karatsuba algorithm and see how it goes. and as usual great video professor!!
@DrTrefor
@DrTrefor Жыл бұрын
hmm interesting, I wonder if it is some memory issue?
@bhavesh.adhikari
@bhavesh.adhikari Жыл бұрын
@@DrTrefor yeah it might be the reason. as a beginner i am very much satisfied with it hahaha, i will work on it later
@GhostyOcean
@GhostyOcean Жыл бұрын
What types are you working with? I know different types have different memory sizes for them. For example BOOL, LONG, and INT types use different numbers of bits to store their information.
@allanjmcpherson
@allanjmcpherson Жыл бұрын
Yeah, it sounds like you might be getting an overflow error somewhere along the way for large numbers. It might be useful to examine the start and end of the binary representation of the correct answer and the answer your program spits out. If the end agrees and the beginning doesn't, that support the idea that it's an overflow error.
@bhavesh.adhikari
@bhavesh.adhikari Жыл бұрын
@@GhostyOcean i am using character array to take input and then integer array of same size, then converting string input into integer by ascii adjustment then carrying out multiplication just like we human do. and storing the result in dynamically allocated resulting array.
@andrewharrison8436
@andrewharrison8436 Жыл бұрын
There is this lovely tension between theory and practicality in maths. The Greeks: there are an infinity of primes because a finite list can be multiplied together, add 1 and factorise to get a new prime. Cryptographers: take 2 large primes and multiply, bet you can't find the original primes. Karatsuba: multiplying those primes is hard, let's make it faster. Schonhage-Strassen, and Harvey and Hoeven: for numbers so big we can't in fact work with them let's make it faster. Lovely - now we need a theoretical proof that n log(n) is indeed the limit.
@NowInAus
@NowInAus Жыл бұрын
Fascinating. Stumbled onto this and I’d never really thought about the rate determining steps in larger multiplication tasks. Thanks
@interest21stcentury74
@interest21stcentury74 11 ай бұрын
Hey dr, I hope you are doing well! Missed your classes (during the COVID era) and videos very much! Your videos helped me get an A on Calculus. Im also glad you got over 300k subscribers. I am also recommending your videos to my first year friends, because they are extremely helpful.
@prashantsingh6370
@prashantsingh6370 Жыл бұрын
I love learning how things actually works in mathematics for larger numbers. The love only increased further during my electrical engineering days where we had a subject, aptly, called Advanced Engineering Mathematics (AEM) 1 & 2. For sure it was difficult than anything I had done till then but at the same time it felt so cool to understand it and solve problems. In the end, AEM was amongst my top 4 highest scoring subjects. 😅
@moreon340
@moreon340 11 ай бұрын
The best part about O(n log n) multiplication isn't doing it (as is clear from the fact that we don't actually do it), it's analysing other things that use multiplication and just having it be O(n log n) and not muddy the entire analysis with more complicated terms.
@slembcke
@slembcke Жыл бұрын
The first time I heard about the FFT algorithm for multiplication, it seemed... impossible. What did multiplication have to do with the frequency domain after all? I didn't really look into it further since I didn't need to multiply giant numbers anyway. I think it was a 3bluebrown video talking about convolutions in probability, and used long multiplication as an example to introduce it. That was a giant AHA! moment. Of course multiplication is just convolution followed by the carry additions! I immediately opened up a python prompt and had to try it. Mind blown! What a beautifully weird algorithm. Using the FFT to convolve digits of a number in the frequency domain? Brilliant! Maybe a bit useless for everyday computing, but still!
@rohanganapathy8
@rohanganapathy8 Жыл бұрын
Would have loved to learn about the newer theorems but still was very interesting.
@DrTrefor
@DrTrefor Жыл бұрын
I am hoping to do a video at some point really diving into the discrete fast fourier transforms and how they are used for the more advanced algorithms:)
@gblake321
@gblake321 Жыл бұрын
This video was really helpful. I think I know enough to code it up on my own.
@DrTrefor
@DrTrefor Жыл бұрын
Nice!
@johnchessant3012
@johnchessant3012 Жыл бұрын
also the same Strassen as in the Solovay-Strassen primality test!
@DrTrefor
@DrTrefor Жыл бұрын
That's right, the dude was busy!
@rubixtheslime
@rubixtheslime Жыл бұрын
the fun thing about hardware multiplication is they often continue to break the problem down even further. from what i've heard, modern hardware generally breaks it down to 8x8 bit multiplications and then uses the fastest 8x8 bit multiplication known to mankind: a 65k entry table. and you even have a separate table for every 8x8 bit multiplication that has to be done. and while you could do 64x64 bit multiplication (which is implemented in x86_64, i have no idea how to get the full answer in C though) using 27 tables instead of 64 using Karatsuba, they're all done at the same time so in terms of speed that's just more layers of addition. so in case you were wondering how we manage to keep doubling those transistor counts... what i think is really interesting though is that in grade school you're effectively left to assume that division isn't much slower than multiplication. but in reality, multiplication has all these different ways you can improve, while with division it's things like "wow we cut it down by a factor of 4, still 10x slower than multiplication though because none of it is parallel" for hardware and "so basically you multiply a bunch of times because multiplication is just that much faster" for low complexity algorithms (just checked before posting this, turns out dividers can achieve the same complexity as multipliers, though once again, this is by turning it into multiple multiplications). also doesn't help division's case that integer dividers have to provide two almost unrelated answers at once (quotient and remainder), not just one big one.
@johncochran8497
@johncochran8497 11 ай бұрын
I'd suggest you look up Dadda and Wallace trees. Additionally, you might find Booth's multiplication algorithm useful. One nice thing about Booth's method is that it handles signed numbers directly and with a minor modification, handles unsigned as well (basically extend the unsigned numbers an additional significant bit with a value of 0). At the hardware level, this allows for both signed and unsigned multiplies to be performed with essentially the same hardware and microcode. But as for this video, it's only useful for LARGE numbers. For smaller numbers such as used natively by 32, 64, and 128 bit computers, it's generally faster to use the straight forward O(n^2) algorithms or lookup tables. One minor note. If you look at Booth's method, a lot of naïve people will claim that it reduces the number of add operations for performing multiplication. This is wrong. On average the total number of adds will be the same for Booth and conventional. The big advantage to Booth's method is that for multi-bit versions, the values added (or subtracted) are simpler than the values used for conventional multi-bit multiplication. For instance, Radix-4 Booth uses the values 1x, 2x, -2x, -1x. All of which is a simple addition or subtraction of either the value directly, or a single bit shifted value. Whereas radix-4 conventional uses the values 1x, 2x, 3x. The values 1x and 2x are simple. But 3x can't be calculated via a simple shift. It requires both a shift and an addition. So it's considered "complex". And for Radix-8 Booth, the values required are 1x, 2x, 3x, 4x, -4x, -3x, -2x, -1x. So the only complex values needed is 3x, whereas for Radix-8 conventional, the complex values required are 3x, 5x, and 7x (6x is a simple shift of the 3x value).
@SameAsAnyOtherStranger
@SameAsAnyOtherStranger Жыл бұрын
Binary multiplication is a different beast all together. It's adding the multiplicand to a running sum of adding exponentiated copies of itself according to the reversed sequence of ones and zeros in the multiplier. But I'll definitely be trying this method on binary numbers.
@ashutoshmahapatra537
@ashutoshmahapatra537 Жыл бұрын
I had tried it before in binary using bitshifts + recursion but still native multiplication will be faster which makes sense, since it doesn't involve any function calls, ig if it's done in a low level language difference can be seen..
@xGOKOPx
@xGOKOPx 11 ай бұрын
​ @ashutoshmahapatra537 If your compiler is any good then function calls to short functions should be removed during the optimisation stage. Native multiplication will however always be faster because it's done in hardware, not software. Algorithms mentioned in this video come into play when you have to multiply those enormous numbers which you can't represent with native data types.
@egycg3569
@egycg3569 Жыл бұрын
What you're doing is invaluable Dr? Thanks once more
@General12th
@General12th Жыл бұрын
Hi Dr. Bazett! I bet these new algorithms will find a use eventually -- if not in this millennium, then certainly in subsequent ones!
@phitc4242
@phitc4242 Жыл бұрын
it already has, i'm pretty sure (in python for example)
@RobertBraf
@RobertBraf Жыл бұрын
Thanks for this great vid, Professor! Do you also plan to branch to modular Multiplikation algorithms in one of your next videos? Regards, Rob.
@DrTrefor
@DrTrefor Жыл бұрын
good idea!
@harmsc12
@harmsc12 Жыл бұрын
I was taught a slightly different method for multiplying multi-digit numbers, but the point of the video still stands. Instead of just looking at individual digits and having n^2 numbers that need adding together at the end, I was taught to run the entire top number against each digit of the bottom number, with proper carrying, which gave me just n numbers to add together, with n being the number of digits in the bottom number.
@DrTrefor
@DrTrefor Жыл бұрын
Ya fair enough, I sort of think of this as equivalent (you are still doing n^2 single digit multiplications, just organizing your work on the page a bit differently of when you do the additions)
@harmsc12
@harmsc12 Жыл бұрын
@@DrTrefor That's also fair enough.
@Mr.Nichan
@Mr.Nichan 11 ай бұрын
"We all learn how to do this in high school." We learned it in elementary school. By high school, most people were getting rusty at it because we could use calculators, though I always lost my calculator and so got better. (I still was able to write this before I "instantly" knew what 7*8 was, though. It's 56, I remember now.) On yhe ither hand, I like the way you explicitly write all 4 1-digit multiplications instead of just writing out 2 multiplications, one for each of the bottom digits,like I learned to do.
@jamesknapp64
@jamesknapp64 Жыл бұрын
Would the Harvey and Hoeven be useful for checking Fermat number primality? I know F_33 is the first candidate and 2^(1729^12) would be on the order of 2^(2^129) thus F_129 (which doesn't appear to have factors currently) might be a candidate to try and use it with Pepin's Test.
@Omeomeom
@Omeomeom Жыл бұрын
i think everyone should figure out the most efficient algorithms for multiplication and addition and why they are what they are. I feel like that would be a lot of value created.
@abdurrahmanlabib916
@abdurrahmanlabib916 Жыл бұрын
Hello professor. Maybe you can make another playlist on another math course in the future which would help us a lot! Thank you.
@DrTrefor
@DrTrefor Жыл бұрын
Lot's more coming...what would you like to see?
@abdurrahmanlabib916
@abdurrahmanlabib916 Жыл бұрын
@@DrTrefor maybe calculus of complex variables or real analysis
@vineetkaddu1214
@vineetkaddu1214 Жыл бұрын
Hi, you said at 3:00 that we need to do 3 single digit multiplications. But couldn't a+b and c+d also be 2 digit numbers? Thank you for this video , an awesome Explanation of this algorithm! Edit: Ok I get it. a+b or c+d would be guaranteed much smaller than a*10 + b for very large numbers, Thanks again!
@BoBoN4Uto
@BoBoN4Uto 11 ай бұрын
4:10 "you can immediatly tell what 7 times 8 is" me: 64... wait no...
@amoledzeppelin
@amoledzeppelin 11 ай бұрын
Thanks, sticking to Karatsuba.
@sp0_od597
@sp0_od597 Жыл бұрын
In regards to the 32 bit by 32 bit multiplication, you probably would not want to break them up into 32/31 bit segments. The reason being, is you will get a 32 bit integer back. Assuming you are multiplying 2 random 32 bit numbers, the odds of getting a number where you need more than 32 bits to represent is very high. The computer would then just roll over and just give you the last 32 digits and get rid of the rest. Imagine the 2 integers you are multiplying are 2^31 * 2^31 = 2^62. This is clearly not representable using 32 bits. You would want to break them up into smaller segments and the best way to segment the number without overflowing would be 16 bit segments since worst case scenario is (2^16 - 1) * (2^16 - 1) < 2^16 * 2^26 = 2^32 which is within 32 bits so the 16 bit segments will never overflow.
@oscarsmith3942
@oscarsmith3942 11 ай бұрын
many computer instruction sets have a high_mul instruction that will give you the upper bits of the multiplication so the way presented is often going to be faster.
@cs127
@cs127 Жыл бұрын
Interesting algorithm! I love your videos!
@denverbraughler3948
@denverbraughler3948 11 ай бұрын
If you do many multiplications by hand, you should soon notice that once you’ve multiplied for a particular digit, you never have to repeat it. You just copy it shifted over, the same as when multiplying by 1. It’s merely a copy operation. Never are n² digit-wise multiplications required. The maximum is 8n.
@Snowflake_tv
@Snowflake_tv Жыл бұрын
I've just read a description of "About"tab, and I think I'll like you😄
@jmich7
@jmich7 Жыл бұрын
What a super teacher!
@arctan-k
@arctan-k Жыл бұрын
Make a video about fast multiplication using fast fourier transform
@DrTrefor
@DrTrefor Жыл бұрын
I plan to!
@tolkienfan1972
@tolkienfan1972 11 ай бұрын
I've implemented fft multiply. I have a suspicion that a careful implementation with hand tuning can make it beat out the n^2 algo for much smaller n. I had to work on something else tho. Maybe I'll get back to it. The thing is, a naive implementation includes a lot of redundant operations, affecting the hidden constant.
@wyattstevens8574
@wyattstevens8574 6 ай бұрын
Here are the missing steps that Karatsuba (probably) went through to improve this: (i.e. here's how ad+bc equals the new 10s term) (a*10^n+b)(c*10^n+d)= ac*10^2n+(ad+bc)*10^n+bd Focusing on the middle term alone, ad+bc= ad+bc+ac+bd-ac-bd= (a+b)(c+d)-ac-bd ac*10^2n+((a+b)(c+d)-ac-bd)*10^n+bd And the product at 5:00 should be (if I'm right- I went Karatsuba all the way down) 1,117,262,504,544,938. Well- that's what I got.
@davidhand9721
@davidhand9721 Жыл бұрын
Usually when I see a software multiply in old code, computing a*b goes like this: i = 0 sum = 0 while i++ < n { if b & 1 add a to sum shift a left shift b right } The adds and shifts and the and are all O(k) apiece, so the full multiply is O(n). Am I missing something here? Why are we mucking about with nlog n? I suppose it only works out this way in base 2, but only base 2 matters if we're computing complexity. In base 2, a pair of digits can only multiply to 1 or 0, whereas a pair of base 10 digits has to be an actual multiply instead of logical and, and the multiply in that case is not O(k).
@davidhand9721
@davidhand9721 Жыл бұрын
You can replace the if with bitmasking a if you don't like the jump, too
@johncochran8497
@johncochran8497 11 ай бұрын
Yes, you are missing something. The key thing to remember is that they are talking about LARGE numbers. So addition is an O(n) operation where n is the number of bits, not O(1). And for your multiply operation, you're doing n additions at a cost of O(n) each, giving an overall cost of O(n^2). Now, for modern processors, operations on the basic word size are O(1). But once again, in the grand scheme of things, those values that are basic to the CPU are small, whereas the values being talked about in the video are large values composed of thousands to millions of bits.
@thisukainol
@thisukainol 9 ай бұрын
keep up the good work
@misterkite
@misterkite Жыл бұрын
Feels like this is a hint for a handful of Project Euler solutions.
@MarekKnapek
@MarekKnapek 11 ай бұрын
In case of 32bit multiplication hardware... you can use such HW to multiply any two 16bit numbers and get 32bit result without loosing any information.
@readjordan2257
@readjordan2257 11 ай бұрын
5:30 This reminds me of the DeepMind matrix multiplication thing, or the one-up to the 2*2 decomposition of larger matricies. That saves up to 33% less calculation. I forget that guys name.
@readjordan2257
@readjordan2257 11 ай бұрын
9:40 yep. That all just came together.
@johnnyvsx
@johnnyvsx Жыл бұрын
Reminds me of the FFT algorithm for computing the DFT.
@henriquelizsandeflores4662
@henriquelizsandeflores4662 11 ай бұрын
It's fascinating how we used logarithms to make counts faster and now we use them to measure how method is doing counts faster
@JohnDlugosz
@JohnDlugosz 11 ай бұрын
3:00 In binary, you don't have any "single digit" multiplies at all, since they are all 1 or 0. Instead, you have the decision to add or skip the add. The number of adds (and decisions on whether to perform or skip) is equal to the number of bits in the smaller factor. So if you consider n to be the number itself, multiplication has k log n steps. If you consider n to be the size (length) of the input; that is, the number of bits in the factors to be multiplied. then multiplying has kn steps. Really, if you wanted to make multiplication of large numbers fast on a computer, it would do to implement a special type of memory that has an adder and a shifter built-in, that joins the individual cells together for as large of a number as you want. That is, given two numbers stored in this memory A and B, it could perform B+=A in constant time and shift A right one bit in constant time. It's important to note that the number of logic gates is constant for each cell (word or byte) so scales linearly with the number of cells.
@AttackOnTyler
@AttackOnTyler 11 ай бұрын
I can't believe I've never seen 1:09 multiplication where the "cross" of the bottom one's digit to the top ten's digit is completely stored for the additive solution section. Only the tens addition of a phantom ten's on the top ten's digit. This visual makes more sense of large number multiplication.
@europeanmappin
@europeanmappin 11 ай бұрын
0:48 not sure if its just us, but we instead do 6x2, 6x3 and then merge them while calculating, then we do 5x2, 5x3 and merge those while calculating, then we do x+x=x
@AxiomTutor
@AxiomTutor Жыл бұрын
Yeah so much nicer to write the carry inline, never thought of that.
@theowleyes07
@theowleyes07 11 ай бұрын
Have you tried Vedic Way of Multiplication So the Example you gave 32*56 The way a Vedic Mathematician Have done in (3*5) at tens Place (3*6+5*2) then this (2*6)at last. So the way you get 28 can be done by 3*6+5*2
@wyattstevens8574
@wyattstevens8574 2 ай бұрын
He says that's basically the grade-school n² algorithm.
@jek__
@jek__ 11 ай бұрын
When you said enormous numbers and recursively apply the algorithm the first thing I thought was stack overflow lol
@batoulnoureddine
@batoulnoureddine 11 ай бұрын
Can make a video explaining where did the log actually came from? Imran how did we start using log and ln in the first place??
@tissuepaper9962
@tissuepaper9962 11 ай бұрын
It's just a natural, necessary extension of exponentiation. Exponentiation without logarithms would be like addition without subtraction. The story of Euler's number _e_ and the natural log is slightly more interesting. _e_ was chosen so that _e^x_ would be its own derivative.
@satya456srav6
@satya456srav6 Жыл бұрын
super professor!📚😃🏃‍♀️
@DrTrefor
@DrTrefor Жыл бұрын
Thank you!!
@SuperDeadparrot
@SuperDeadparrot Жыл бұрын
I also studied math at University of Toronto. Back when Prof Eric Moore was just Senior Tutor Moore.
@johnvriezen4696
@johnvriezen4696 Жыл бұрын
Hmm.. in your first example, two digits X two digits, you had to do four multiplications using the high school method. But if you choose to represent your numbers in a base greater than the larger of the two numbers, then it will always be a one digit number X one digit number, and you never have to do more than one multiplication. Multiplications can be done in constant time. Q.E.D. 🙂
@DrTrefor
@DrTrefor Жыл бұрын
Haha true! Ya if we just built hardware multiplies of arbitrary size it would multiply in one step!
@theedspage
@theedspage 8 ай бұрын
Do you have a court in Brilliant, Dr. Bazett?
@SoftYoda
@SoftYoda Жыл бұрын
Is there any scientific reading analyzing the type of number we use in scientific or non-scientific computation ? (what size) from 0BC to 2023 ?
@KangJangkrik
@KangJangkrik Жыл бұрын
I like the topology picture at his shirt
@Peppermint3387
@Peppermint3387 Жыл бұрын
How does first algo works with odd amount of number given or odd and even number given
@SuperDeadparrot
@SuperDeadparrot Жыл бұрын
I’m wondering if you can use a Fourier Transform on the entries.
@DrTrefor
@DrTrefor Жыл бұрын
Indeed, that's the basis for the more modern methods
@DaneBrooke
@DaneBrooke 11 ай бұрын
You have to also count the shift operations.
@DrTrefor
@DrTrefor 11 ай бұрын
Shifts (i.e. multiplication by 2 in binary) are computationally cheap from what I understand
@socraticmathtutor1869
@socraticmathtutor1869 8 ай бұрын
I think the shifts won't actually end up getting implemented; rather, they just kind of fall into place by getting the indexes right. To illustrate how this kind of thing works with a toy model, notice that the fastest way to compute x*(2^64) + y isn't to start by computing x*(2^64), it's actually two do the whole thing in one traversal by repeatedly computing x[i+1] + y[i]. I'm not an expert, but I have a feeling that Karatsuba's algo would typically be implemented in a similar way.
@MathOrient
@MathOrient Жыл бұрын
Interesting :)😃
@puppergump4117
@puppergump4117 Жыл бұрын
”We all learn this in high school, for instance” Well we usually learn that in grade school. Or I'd hope so.
@Snowflake_tv
@Snowflake_tv Жыл бұрын
04:06 I've memorized single-digit-multiplication, but recently I'm trying not to use the memorization. I'm trying to imagine a rectangle to multiply.
@dumnor
@dumnor Жыл бұрын
I believe every problem has n log n solution.
@DrTrefor
@DrTrefor Жыл бұрын
it's not a bad null hypothesis!
@cem_kaya
@cem_kaya 11 ай бұрын
isn't toom-cook O(N+e) epsilon as small as you want ?
@wafikiri_
@wafikiri_ Жыл бұрын
If you multiply two binary numbers of length n, you have to perform n shifts left on one number (padding 0 as least significant bit), and at most n additions to it of the other number, one per each one found in the latter, zeros don't count, looking from the least significant bit. Isn't this the fastest multiplication? Order n, for sums, no multiplications.
@gdclemo
@gdclemo Жыл бұрын
You are talking about n additions of arbitrary length numbers, when you break that down into additions of fixed size integers you are back to O(n^2).
@wafikiri_
@wafikiri_ Жыл бұрын
@@gdclemo Yes, whether you use breaking integers down (for conventional computers) or hybrid conventional with Turing processors, a sum requires to go along successive pairs of ciphers n or n+1 times. Thus, O(n) times. And O(n) number sums, therefore, require O(n²) elemental operations But my point was that, with binary numbers, you don't need multiplications! Whatever the multiplication method, whatever the base, you still need O(n) sums of numbers, therefore O(n²) elemental operations just for sums, plus the elemental or combined multiplications in bases greater than two.
@gdclemo
@gdclemo Жыл бұрын
@@wafikiri_ Well you've just broken the multiplications down to their elemental components to the extent that you're just multiplying by zero or one, which are of course trivial. But those operations still add up to O(n^2) in total which is much slower than the optimal algorithm. Big-O notation doesn't care what the operations are or how long they take individually, only how they grow.
@MissNorington
@MissNorington 11 ай бұрын
3:15 mentions computers, but the title doesn't specify this. Fastest multiplication algorithm for computers would be a better description.
@youneschafi5273
@youneschafi5273 Жыл бұрын
2:59 a+b and c+d are not necessarly single digits.
@WhitEagle7
@WhitEagle7 Жыл бұрын
0:08 bro you learned the multiplication in high school? bro...
@DrZygote214
@DrZygote214 11 ай бұрын
@9:00 "For numbers after about 10 to the 96th..." Is that a typo? 10^96? That is a grokking huge number, far far huger than 2^64. If this is true then this algorithm is not worth it even for x64 architecture.
@okaro6595
@okaro6595 Жыл бұрын
Who does it the way you first presented? You of course first multiply 32 by 6 and then 32 by 5 one shifted. The you add.
@DrTrefor
@DrTrefor Жыл бұрын
Well this is the same, you are just writing less down, when you multiply 32x6 you are presumably doing 2x6 and 30*6 in your head and adding them. And I do too, I normally only write down 2 lines not 4 but I'm writing all 4 to make explicit that there are 4 single digit multiplications involved.
@cheto96
@cheto96 Жыл бұрын
Did you just say you learn multiplying in HS 0:08
@DrTrefor
@DrTrefor Жыл бұрын
I learned it way back in the before times that is all a murky blurr:D
@vivekm.s8819
@vivekm.s8819 Жыл бұрын
First view proffesor.❤
@DrTrefor
@DrTrefor Жыл бұрын
Nice one!
@livedandletdie
@livedandletdie 11 ай бұрын
56*32 is easy to do... it's just (40+16)*(40-8) or 40²+(16-8)*40-16*8 3 multiplications and 3 additions. I mean if we did numbers like 96*93 it's stupidly easy, it's 8900+28 I did 1 multiplication a simple one, -7*-4... That's all I needed. And how I came up with those numbers, oh boy. 96*93=(100-4)(100-7) 100²+100*((-4)+(-7)) + (-4)(-7) And you still say that's 3 multiplications... and I say it's not, 96-100=-4 , 93-100=-7 96-7=89 -4×-7=28 89 concatenate 28 is 8928... 1 multiplication the rest is addition.
@SvenWM
@SvenWM 11 ай бұрын
given enogh storage space you could just look at a table with the solutions for any multiplications. guess that is a bit of cheating but O=1 is technically possible
@DrTrefor
@DrTrefor 11 ай бұрын
At some point, searching within the table would be the hard part!
@anntakamaki1960
@anntakamaki1960 11 ай бұрын
“Seven times eight and you immediately know the answer” 🤔 😬
@stephenkolostyak4087
@stephenkolostyak4087 11 ай бұрын
multiplication is first being taugh tin high school, now? ...
@jamescraft5300
@jamescraft5300 11 ай бұрын
0:06 highschool?
@danielguy3581
@danielguy3581 11 ай бұрын
What I once thought was some yokel's ignorant misunderstanding of language, I now realize is the common way Americans pronounce 'Fourier'. I get it if you feel this is petty and that math should stand above such matters of culture and language - by all means, call it "wave decomposition" or somesuch. But if you're going to name something after a person - might as well get their name right.
@tissuepaper9962
@tissuepaper9962 11 ай бұрын
Go be insufferable somewhere else, Daniel. Maybe you should learn Ancient Aramaic so you can say that Biblical name of yours properly. After all, if you're going to name something after a person, you might as well get their name right.
@aldob5681
@aldob5681 11 ай бұрын
high school? or primary school?
@Fidelity_Investments
@Fidelity_Investments Жыл бұрын
sorry, highschool? I learned this in 3rd grade
@joyjin538
@joyjin538 Жыл бұрын
With hand? Use log and log tables. That's what they are invented for originally.
@anamoyeee
@anamoyeee 11 ай бұрын
Nah, better do 1729 dimensional fourier transform
@ilikeapplejuice8658
@ilikeapplejuice8658 11 ай бұрын
In highschool? Im sorry i learned multiplication in grade 2
@moadot720
@moadot720 11 ай бұрын
4:32 "A little bit"...? (No offense.)
@jakesnake5534
@jakesnake5534 11 ай бұрын
Isn't binaty multiplication almost as fast as addition though?
@DrTrefor
@DrTrefor 11 ай бұрын
multiplication by 2 is very fast in binary specifically, but not any two numbers.
@jakesnake5534
@jakesnake5534 11 ай бұрын
@@DrTrefor can't you multiply by any number you want by doing bitshifts and addition really easily? I.E. to multiply by 5, shift bits2 left, and add the original value once, Or to multiply by 6 shift bits 2 left and add the original value twice?
@colecook834
@colecook834 11 ай бұрын
This looks like recursive functions from coding.
@CM-dx6xu
@CM-dx6xu Жыл бұрын
Engineers would just round those to at most 3 significant figures then multiply it 😂 no need to fuss
@DrTrefor
@DrTrefor Жыл бұрын
😂
@AlanAlmeidadeAndrade
@AlanAlmeidadeAndrade 11 ай бұрын
Looks like o dont know instantly whats 7 times 8 is
@andjohnmurugan100
@andjohnmurugan100 11 ай бұрын
Why does he randomly start to talk in italian?
@MrMaelstrom07
@MrMaelstrom07 11 ай бұрын
Anyone else hungry for carrot soup now?
@yjlom
@yjlom Жыл бұрын
nah, I prefer my doubly iterated succession
@omri.d
@omri.d Жыл бұрын
I don't think you can use big O to the complexity, the Karatsuba always does that number of multiplication, not in the worst case
@DrTrefor
@DrTrefor Жыл бұрын
Well it always does that if it is exactly 2^k, otherwise there is extra inefficiencies by going up to the nearest power of 2
@omri.d
@omri.d Жыл бұрын
So it's even MORE wrong, the big O in the video is the best time, not the wrost
@MythicWiz
@MythicWiz Жыл бұрын
if it always do 3^n,then it still do 3^n in the worst case isn't it?the same thing happens to merge sort with O(n log n) in every scenario
@MythicWiz
@MythicWiz Жыл бұрын
@@omri.d also even with 2^k+1 digits it does 3^(k+1) computes which is 3*3^k that still falls in the same complexity so it's not wrong
@kkanden
@kkanden Жыл бұрын
you learn multiplication in high school what????
@DanDart
@DanDart Жыл бұрын
Have the times table literally in a table :p
@tissuepaper9962
@tissuepaper9962 11 ай бұрын
Many hardware implementations of multiplication break big numbers down into 8-bit chunks and then use a 65565-entry lookup table.
@Warlord_Megatron
@Warlord_Megatron 11 ай бұрын
With due respect i just wanna say this is utterly useless
@wyboo2019
@wyboo2019 Жыл бұрын
if i'm not mistaken, and its kind of cheating, but i'm pretty sure early mathematicians multiplied numbers with logarithm lookup tables. for example, say you wanted to do: 31415*92653 what you can do is: ln(31415*92653)=ln(31415)+ln(92653) look up these logarithms in your lookup table to get: 10.35504076483705 + 11.43661661111373 which is much easier to do: = 21.79165737595078 then use your logarithm lookup table in reverse: = 2,910,693,995 really nowadays you'll always have your phone with you for a calculator, and if you don't have your phone you also probably don't carry around a logarithm lookup table (although that would be so cool to own actually), it's still super useful to know in some oddly specific circumstances i think i might buy a pocket logarithm lookup table just in case
@andrewharrison8436
@andrewharrison8436 Жыл бұрын
The problem is that the look up of the logarithm has built in accuracy limits - my paper copy is 5 digits so completely superceeded by computer calculation.
@DirtyDickMurdok
@DirtyDickMurdok 10 ай бұрын
For 1 day I would like to know what it was like to be that smart
Intro to Gradient Descent || Optimizing High-Dimensional Equations
11:04
Dr. Trefor Bazett
Рет қаралды 56 М.
The reason you should shuffle 7 times
19:27
Dr. Trefor Bazett
Рет қаралды 30 М.
ISSEI funny story😂😂😂Strange World | Magic Lips💋
00:36
ISSEI / いっせい
Рет қаралды 42 МЛН
Самый большой бутер в столовке! @krus-kos
00:42
Кушать Хочу
Рет қаралды 7 МЛН
Лизка заплакала смотря видео котиков🙀😭
00:33
How Karatsuba's algorithm gave us new ways to multiply
18:48
Nemean
Рет қаралды 1,1 МЛН
Multiplication | Logical Redstone #13
14:32
mattbatwings
Рет қаралды 49 М.
Mathematicians Use Numbers Differently From The Rest of Us
33:06
Veritasium
Рет қаралды 6 МЛН
A problem so hard even Google relies on Random Chance
12:06
Breaking Taps
Рет қаралды 1,1 МЛН
The "Just One More" Paradox
9:13
Marcin Anforowicz
Рет қаралды 2,9 МЛН
How AI Discovered a Faster Matrix Multiplication Algorithm
13:00
Quanta Magazine
Рет қаралды 1,3 МЛН
The fastest matrix multiplication algorithm
11:28
Dr. Trefor Bazett
Рет қаралды 278 М.
Euler's Formula Beyond Complex Numbers
29:57
Morphocular
Рет қаралды 215 М.
An Exact Formula for the Primes: Willans' Formula
14:47
Eric Rowland
Рет қаралды 1,3 МЛН
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 697 М.
ISSEI funny story😂😂😂Strange World | Magic Lips💋
00:36
ISSEI / いっせい
Рет қаралды 42 МЛН