Why is squaring a number faster than multiplying two random numbers?

There exist algorithms more efficient than O(N^2) to multiply two numbers (see Karatsuba, Pollard, Schönhage–Strassen, etc.) The two problems “multiply two arbitrary N-bit numbers” and “Square an arbitrary N-bit number” have the same complexity. We have 4*x*y = (x+y)^2 – (x-y)^2 So if squaring N-bit integers takes O(f(N)) time, then the product of two arbitrary … Read more

Is it possible to implement bitwise operators using integer arithmetic?

First solutions for shifting (shift is the shift distance, must not be negative, a is the operand to be shifted and contains also the result when done). The power table is used by all three shift operations. // table used for shift operations powtab = { 1, 2, 4, 8, 16, 32, 64, 128, 256, … Read more

Haskell or Standard ML for beginners? [closed]

Much as I love Haskell, here are the reasons I would prefer SML for a class in discrete math and data structures (and most other beginners’ classes): Time and space costs of Haskell programs can be very hard to predict, even for experts. SML offers much more limited ways to blow the machine. Syntax for function … Read more

tech