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
1
vote
1 answer

Python adding garbage values at end of number on multiplication

I am trying to do Karatsuba multiplication. Whenever the number of digits exceed 16, python fills garbage values at the end when multiplying by a power of 10 For example: 5789640666777942 * pow(10, 16) =…
1
vote
1 answer

Karatsuba algorithm

I keep getting these errors when I run my program, can anyone spot the mistake? I am not experienced with using recursion and I might have messed up base case. My testing consists of two numbers of the same length, and my goal is to multiply two Big…
1
vote
1 answer

Karatsuba multiplication implementation in Java BigDecimal

Recently I was trying to implement Karatsuba multiplication for large numbers. Then I tried comparing my implementation with the Java BigInteger implementation. I could not follow this line of code: // result = p1 * 2^(32*2*half) + (p3 - p1 - p2) *…
chandra_cst
  • 307
  • 2
  • 13
1
vote
1 answer

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

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…
Lesscomfortable
  • 823
  • 1
  • 6
  • 13
1
vote
4 answers

Base case for Karatsuba Multiplication

Just wondering why the base case for Karatsuba multiplication ( shown here: http://www.sanfoundry.com/java-program-karatsuba-multiplication-algorithm/) is chosen to be "N<= 10"? I found "N<= 4, 3, 2 ,1 " will not give me a correct result. Anyone can…
teddy
  • 413
  • 3
  • 8
  • 24
1
vote
1 answer

Karatsuba Algorithm in Javascript

I implemented the Karatsuba's algorithm in Javascript. const multiply = (a, b) => { let sizeA = numOfDigits(a); let sizeB = numOfDigits(b); if(sizeA < sizeB) { a = '0'.repeat(sizeB-sizeA).concat(a); } else if(sizeB <…
Mayur Arora
  • 447
  • 5
  • 11
1
vote
2 answers

Karatsuba Infinite Recursion - Python

Beginner here. I've spent most of the day working on the Karatsuba Algorithm just because I thought it would be fruitful. I've seen similar questions on here, but they are in other languages and seem strangely complex. The following is my code. The…
Ryan
  • 1,312
  • 3
  • 20
  • 40
1
vote
2 answers

terminated by signal SIGSEGV (Address boundary error) in recursive function

I'm trying to implement Karatsuba algorithm for multiplication. I'm kinda follow the pseudocode in this wiki page. But I'm always getting this error: terminated by signal SIGSEGV (Address boundary error) When I replaced the lines that cause the…
Rafael Adel
  • 7,673
  • 25
  • 77
  • 118
1
vote
1 answer

Karatsuba and Toom-3 algorithms for 3-digit number multiplications

I was wondering about this problem concerning Katatsuba's algorithm. When you apply Karatsuba you basically have to do 3 multiplications per one run of the loop Those are (let's say ab and cd are 2-digit numbers with digits respectively a, b, c and…
Simon
  • 2,643
  • 3
  • 40
  • 61
0
votes
0 answers

clarifications about katasuba algorithm

i'm investigating multiplication algorithms for a design im working on. I'm trying get an implementation of a 128 bit multiplier using the karasuba algorithm, however I'm not getting the results that I expect all the time, so I believe I'm still…
0
votes
0 answers

Karatsuba Algorithm using C

I am trying to write the Karatsuba algorithm using C. I tried my code using small numbers for example 9999 * 9999 and it is working fine however I am noticing when I increase the size of the number above 7 digits (I tried on 9999999 * 9999999 and it…
tonyjk
  • 21
  • 5
0
votes
1 answer

How to deal with an 64 digit input for a Karatsuba algorithm implementation in java

This is my implementation and what i need for it is to calculate the multiplication of two 64 digit number. So type Long is not enough (even tho the one with parameter type of long worked just fine). However when running with String, this popped…
0
votes
1 answer

Assign variable values in parallel

I am building a program that deals with numbers in different bases, and I wanted to optimize it by using parallel programming, but I am new to all of it. Right now, I am trying to implement a parallel Karatsuba multiplication algorithm: public…
0
votes
0 answers

Compute only most significant half of GF(2)[X] polynomial (or integer) product efficiently?

I know about Karatuba's algorithm and other even more efficient ways to multiply two large polynomials or integers. I also know that there is a "middle product" version of Karatsuba which computes only the middle bits (or digits) of a product more…
0
votes
1 answer

Karatsuba Multiplication with Recursion

I am trying to implement Karatsuba Multiplication in Python. Unfortunately, my code is failing on 64 digit test cases (curriculum I am working on) because I start yielding negative numbers for my gauss calculations. I included my code below and was…