multiplication

Karatsuba algorithm too much recursion

只愿长相守 提交于 2020-01-01 05:14:09
问题 I am trying to implement the Karatsuba multiplication algorithm in c++ but right now I am just trying to get it to work in python. Here is my code: def mult(x, y, b, m): if max(x, y) < b: return x * y bm = pow(b, m) x0 = x / bm x1 = x % bm y0 = y / bm y1 = y % bm z2 = mult(x1, y1, b, m) z0 = mult(x0, y0, b, m) z1 = mult(x1 + x0, y1 + y0, b, m) - z2 - z0 return mult(z2, bm ** 2, b, m) + mult(z1, bm, b, m) + z0 What I don't get is: how should z2 , z1 , and z0 be created? Is using the mult

Efficient product of 1D array and 3D array along one dimension - NumPy

南笙酒味 提交于 2019-12-31 02:00:49
问题 I have two numpy arrays: A 1D array called t of shape (70L,) with element called let s say ti A 3D array called I with shape (70L, 1024L, 1024L), with each elements called Ii. Ii are thus of dimension (1024L, 1024L) I would like to make a product of the two array along the first dimension, i.e.: tI = t1*I1,t2*I2,...,tN*IN such as to obtain again a new array of dimension (70L, 1024L, 1024L) and then take the sum along the first dimension in order to obtain an array of dimension (1024L, 1024L):

Basic matrix multiplication in OpenCV for Android

大城市里の小女人 提交于 2019-12-30 06:27:48
问题 I'm probably being incredibly stupid here but I'm having trouble doing some basicaly Mat multiplication using OpenCV for Android. I have two Mat's both of the same type, CV_64F mat1 has size: 3 rows, 3 cols mat2 has size: 3 rows, 1 cols I want to multiply them to give the product mat3 of size 3 rows, 1 cols. I've tried using: Mat mat3 = new Mat(3, 1, CvType.CV_64F); Core.multiply(mat1, mat2, mat3); But I get an error: CvException [org.opencv.core.CvException:/home/andreyk/OpenCV2/trunk/opencv

BigInteger most time optimized multiplication

a 夏天 提交于 2019-12-29 07:14:20
问题 Hi I want to multiply 2 big integer in a most timely optimized way. I am currently using karatsuba algorithm. Can anyone suggest more optimized way or algo to do it. Thanks public static BigInteger karatsuba(BigInteger x, BigInteger y) { // cutoff to brute force int N = Math.max(x.bitLength(), y.bitLength()); System.out.println(N); if (N <= 2000) return x.multiply(y); // optimize this parameter // number of bits divided by 2, rounded up N = (N / 2) + (N % 2); // x = a + 2^N b, y = c + 2^N d

Divide by 9 without using division or multiplication operator

百般思念 提交于 2019-12-25 18:54:33
问题 This question I have tried to solve it but couldn't get any way. Any pointers would be appreciated. Regular subtraction way of doing division is not the intention here, ingenious way of using shifting operator to get this done is the intention. 回答1: Here's a solution heavily inspired by Hacker's Delight that really uses only bit shifts: def divu9(n): q = n - (n >> 3) q = q + (q >> 6) q = q + (q>>12) + (q>>24); q = q >> 3 r = n - (((q << 2) << 1) + q) return q + ((r + 7) >> 4) #return q + (r >

multiplication of very large with small values [closed]

ぃ、小莉子 提交于 2019-12-25 18:44:33
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . as the result of a large binomial coefficient I summed sorry stored a number as big integer (from the gmp) package Big Integer ('bigz') : [1] > chooseZ(1599,999) Big Integer ('bigz') : [1]

VB.net: How to add different multipliers together?

青春壹個敷衍的年華 提交于 2019-12-25 07:49:52
问题 I am creating an EXP multiplier and I do not know how to separate multipliers. My Aim: My aim is to make it so that the multiplier from 'checkbox5.checked = true' will not multiply by the rest of checkboxes but just add its product. If 'checkbox1.checked = true' it will multiply the EXP, which is the input amount by 2. So if checkbox4 is checked, it will multiply the EXP by 1.5 again. So 2x1.5 = 3 However for checkbox5, which multiplier is x1.1, I do not want it to be multiplying the rest of

Multiplying two polynomials mod n,x^r-1 using long integers: what is the correct window size?

谁说胖子不能爱 提交于 2019-12-24 17:43:13
问题 Using a window multiplication algorithm to multiply two polynomials[coefficients in Z/nZ and the whole polynomial mod x^r-1 for some r] using long-integer multiplications, what size should I give to the window? Where by "window" I mean the bit-length that the coefficients should use in the initial long-integers such that the result of the long-integer multiplication contains the correct coefficients of the result[the sums of the coefficients "don't overlap"]. At the beginning I thought that

Addition operation versus multiplication operation

亡梦爱人 提交于 2019-12-24 16:46:29
问题 I know, that addition operation is more trivial than multiplication operation. But will there be any difference in execution time of 123456 * 3 and 123456 + 123456 + 123456 ? How exactly works multiplication? Do multiplication algorithms vary in different programming languages? How multiplication looks on low-level (i.e. Assembler code)? 回答1: In x86 assembly language the addition and multiplication operations look like this: ADD [operand1], [operand2] where operand1 can be register, operand 2

Boolean convolution using integer multiplication

两盒软妹~` 提交于 2019-12-24 14:16:44
问题 In algorithms presented in Bringmann16 article a Boolean convolution is suggested to use to get sumset for two sets of positive integers. In above work both sets are represented as bitmasks - indicator vectors. If represent them as polynomials in form 1 + bit(0) * x + bit(1) * x^2 + ... + bit(i) * x^(i + 1) + ... + bit(n - 1) * x^n , then indeed their product contains only those monomials, whose power is number either in first set, or in second set or in sumset. The coefficients of product