karatsuba

Implementing karatsuba recursion function in python class, errors

痞子三分冷 提交于 2019-12-11 14:23:19
问题 Previously I posted a question on this subject and it was answered quite well. Implementing merge sort function in python class, errors And yet there is still something that escapes me about recursion in a class. In the linked problem above, if I added prefixive self. to the recursion subroutine, I get the exact same error that is produced below in the class output (third block of code in this post). I understand why this happens; object.karatsuba() only takes self as its input, and yet the

Karatsuba algorithm working for small numbers but not for big ones, can't see why

情到浓时终转凉″ 提交于 2019-12-11 04:28:07
问题 I am relatively new to programming and am not looking to be particularly efficient with this algorithm regarding running time but only trying to replicate the Karatsuba algorithm and make it work. I have tried it with many numbers and small numbers (like y = 40004009343254, x = 40004001343234) work fine and when the numbers increase in size (like y = 4000400934325423423, x = 4000400134323432423), the algorithm stops working correctly and returns similar but incorrect answers. Any clue about

Karatsuba Multiplication Implementation

佐手、 提交于 2019-12-02 02:49:37
问题 I recently implemented Karatsuba Multiplication as a personal exercise. I wrote my implementation in Python following the pseudocode provided on wikipedia: procedure karatsuba(num1, num2) if (num1 < 10) or (num2 < 10) return num1*num2 /* calculates the size of the numbers */ m = max(size_base10(num1), size_base10(num2)) m2 = m/2 /* split the digit sequences about the middle */ high1, low1 = split_at(num1, m2) high2, low2 = split_at(num2, m2) /* 3 calls made to numbers approximately half the

Karatsuba Multiplication Implementation

怎甘沉沦 提交于 2019-12-01 23:39:12
I recently implemented Karatsuba Multiplication as a personal exercise. I wrote my implementation in Python following the pseudocode provided on wikipedia : procedure karatsuba(num1, num2) if (num1 < 10) or (num2 < 10) return num1*num2 /* calculates the size of the numbers */ m = max(size_base10(num1), size_base10(num2)) m2 = m/2 /* split the digit sequences about the middle */ high1, low1 = split_at(num1, m2) high2, low2 = split_at(num2, m2) /* 3 calls made to numbers approximately half the size */ z0 = karatsuba(low1, low2) z1 = karatsuba((low1+high1), (low2+high2)) z2 = karatsuba(high1,