Only 17% of all 64-bit Integers are products of two 32-bit integers

lemire.me

105 points by sebg 4 days ago


Dylan16807 - 3 hours ago

> I find it interesting to consider that if you pick a value at random, it will usually fail! That is, most 64-bit integers cannot be written as the product of two 32-bit integers.

While I find the 17% number interesting to think about, "most" is far less interesting. Multiplication doesn't care about order so you're instantly cutting 2^64 possibilities down to about 2^63. That's a hair's breadth away from "most" already, and considering even a tiny amount of overlapping results gets you there.

What gets interesting is actually trying to quantify the overlapping results.

cobbzilla - 8 minutes ago

I must be missing something. Aren’t ~50% of 64-bit integers the product of the number 2 and another 32-bit integer?

tobz1000 - 36 minutes ago

> the proportion of all 2n-bit values that can be generated by the product of two n-bit values goes to zero as n becomes large. This means that if you have, say, 10000000-bit integers multiplying 10000000-bit integers, you’d expect relatively few 100000000000000-bit integers to be produced.

That should be "relatively few 20000000-bit integers", right?

pants2 - 3 hours ago

I dream of a future where all 64-bit integers are products of 32-bit integers. Together, we can change math for the better.

kingstnap - an hour ago

This is something I had thought about some time back where I was thinking about the feasibility of somehow using the upper and lower registers inside a multiplier as general purpose storage for fun / seeing if you could make them more compact.

Anyway here is a fun pattern you get when you multiply 8 bit unsigned integers. Not all pairs of (upper bits, lower bits) are reachable, and it has a lot of distinct patterns.

https://i.imgur.com/Gb3HDR0.png

(Should I host the image on GitHub Gists so it doesn't vanish?)

henry2023 - 2 hours ago

There are about 4 billion 64 bit integers for each 32 bit integer.

The chance of a random 64 bit integer being a 32 bit integer is 0.0000000233 %

The chance of a random 64 bit integer being a product of two 32 bit integers is 17%

Nice

- an hour ago
[deleted]
da_chicken - 2 hours ago

This feels like a underlying property that contributes to of Benford's Law[0]. That is, most numbers we measure and record are the results of various independent (addition) and dependent (multiplication) factors stacking together, and we observe this property in the distribution of them.

[0]: https://en.wikipedia.org/wiki/Benford%27s_law

- 3 hours ago
[deleted]
PunchyHamster - 15 minutes ago

Well, that is entirely not surprising. Pretty sure people writing not terrible hash functions figured it decades ago

crest - an hour ago

So you're better of using a 8x8->16 widening multiplication SIMD instruction or even just a multi register TBL/TBX instruction?

MarkusQ - 2 hours ago

If this seems counterintuitive, consider that only about a third of the two-digit numbers ({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36, 40, 42, 45, 48, 49, 54, 56, 63, 64, 72, 81}) can be written as the product of two one-digit numbers.

nicechianti - 2 hours ago

[dead]