Questions tagged [karatsuba]

Asymptotically fast multiplication algorithm for big integers. Understanding this algorithm and its implementations.

Karatsuba algorithm requires O(nlog₂3) single digit multiplication operations to multiply a pair of n-digit numbers and is therefore asymptotically faster than the common O(n²) multiplication algorithm.

It was proposed by Anatoly Karatsuba in a paper published in the Proceedings of the USSR Academy of Science in 1962.

A related tag is that covers both Schönhage–Strassen multiplication algorithm and Strassen matrix multiplication algorithm.

Useful links

92 questions
0
votes
1 answer

Queston on Karatsuba Recursion

I'm trying to implement a recursive Karatsuba algorithm. I successfully coded a recursive algorithm for multiplication but it calculates ad and bc. However, for this program, I've tried noting down each intermediate value namely ac, bd, total, sum.…
0
votes
0 answers

Karatsuba multiplication not working recursively with BigInteger

I am trying to multiply n digit number using karatsuba multiplication. I am getting output for single digit number (Example 4 and 5 = 20). But, when I multiply 1234 and 5678 I am getting error and no output result. I have updated the code and…
Sid
  • 29
  • 7
0
votes
2 answers

Karatsuba multiplication java recursion code not working?

I am trying to multiply two numbers using karatsuba multiplication. My java code is not working. I have used string as parameters and arguments so that we can multiply two n digit numbers (n is even). Also, I don't want to use long or BigInteger.…
Sid
  • 29
  • 7
0
votes
0 answers

Karatsuba does not return correct result because of middle-term

Here is my code: public static double kMultiply( double x, double y, double n ) { if( n == 1 ) { cost += 1; return x*y; } else { double m,a,b,c,d,ac,bd,g; m = Math.floor(n/2); a =…
0
votes
0 answers

Splitting number into bit halves

I'm implementing karatsuba's method as part of an exercise. Karatsuba's method itself isn't terribly difficult, but one part of it is confusing me. Both numbers being multiplied have to be split into two halves, the high and the low bits. But I…
Bob
  • 715
  • 2
  • 11
  • 32
0
votes
1 answer

Product of 64 digit numbers using Karatsuba algorithm

How to use Karatsuba algorithm to calculate product of two 64 digit numbers such that only single digit numbers take part in multiplication ?
0
votes
1 answer

Karatsuba algorithm error

i'm doing a karatsuba implementation but i have this error: java.lang.NumberFormatException: Zero length BigInteger at java.math.BigInteger.(BigInteger.java:296) at java.math.BigInteger.(BigInteger.java:476) at…
colymore
  • 11,776
  • 13
  • 48
  • 90
-1
votes
1 answer

Signed Number Multiplication using Karatsuba Algorithm in Verilog

Tried implementing Karatsuba multiplier for multiplying two binary numbers, the logic below works well for unsigned numbers, but getting incorrect answer when I change one of the inputs to a negative. In the example below a=1010011111000000(equals…
-1
votes
1 answer

can't get the right answer when multiplying two large numbers using Karatsuba multiplication(recursive Gauss "trick")

I have been trying to implement integer-multiplication problems using strings. The product of smaller numbers is always right but for larger numbers the results are wrong. Can anyone tell me which part of the code is causing the problem? a:…
darkknight
  • 13
  • 3
-1
votes
1 answer

Can you please spot the error I made in C implementation of the Karatsuba algorithm

I need to implement the karatsuba algortihm into a c code for my homework and I did my research and came up with the following code: long int karatsuba(long int x,long int y) { if((x<10)||(y<10)) \\if the numbers have 1 digit, I just multiply…
-1
votes
1 answer

karatsuba algorithm error on very long numbers

I learnt about Karatsuba algorithm which allows me to multiply very big numbers using divide and conquer method. Here's my code. I wrote a function which returns the length of a number then I write the multiply function and I used the method with 4…
varo111
  • 307
  • 1
  • 3
  • 8
-1
votes
2 answers

Fast Multiplication on SPOJ

I am solving FAST MULTIPLICATION on SPOJ. My solution looks like this: #include using namespace std; int max(int a,int b) { if(a>b) return a; return b; } long karatsuba_multiply(int x,int y) { if(x<10 or y<10) return x*y; …
-1
votes
1 answer

Karatsuba algorithm subproblems

I am trying to figure out a question about Karatsuba's algorithm when multiplying two binary values. I am trying to multiply: 10110110 * 11001000 I need to figure out which subproblems are completed when using Karatsuba's algorithm. I know that…
masonc15
  • 1,043
  • 2
  • 12
  • 19
-1
votes
1 answer

c++ Karatsuba Multiplication using Vectors

So i've been trying to write out an algorithm for the Karatsuba Multiplication algorithm, and i've been attempting to use vectors as my data structure to handle the really long numbers which will be input... My program can do smaller numbers fine,…
Swallows
  • 199
  • 1
  • 1
  • 11
-1
votes
2 answers

Function returns 0 in karatsuba multiplication

I'm trying to implement Karatsuba multiplication through recursive calls. The code below should work, but I keep getting the Zero as answer. Any thoughts? #define ll long long int ll kmul(ll p, ll q) { ll a,b,c,d,ans; ll n=0; while(p) …