Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: [OT] The statistics of hashing.

by moritz (Cardinal)
on Apr 01, 2012 at 10:44 UTC ( #962873=note: print w/replies, xml ) Need Help??

in reply to [OT] The statistics of hashing.

I'm not sure I understood the question correctly, but I hope my answer is still helpful for you.

Further to that, if the number of sub hashes and vectors is increased to 10, by permuting each of the four sub hashes against the other 3 and XORing, does that substantially decrease the odds of false matches? (Or increase them? Or leave them the same?)

Statistically, the only thing that matters for the probability of collisions is the total entropy of the hash. If you create a 128bit hash over a string, you have 128 bits of entropy. If you create two 128bit hashes, one over the first part and one over the second part of the string, you have 256 bits of entropy. If you XOR the two hashes, and use the results, you have 128 bits again.

If you use one 128bit hash, the probabilities for getting no collision on inserting the nth number is

P(no_collision, n) = (1 - 1/2**128) ** n

I'm pretty sure that the number of collisions follows (at least approximately) a Poisson distribution, though I haven't yet figured out how to calculate the expectation value.

Replies are listed 'Best First'.
Re^2: [OT] The statistics of hashing.
by BrowserUk (Pope) on Apr 01, 2012 at 11:30 UTC

    Hm. Attempting calculate 1 - 1/2**128 using my calculator just returns 1.

    So then I tried Math::BigFloat, and still got just 1. What Am I doing wrong?

    use Math::BigFloat; $moritzFactor = Math::BigFloat->new( 1 )->bsub( Math::BigFloat->new( 1 )->bdiv( Math::BigFloat->new( 2 )->bpow( 128 ) ) ); print $moritzFactor; ;; 1 [0] Perl> print $moritzFactor->bstr;; 1 [0] Perl> print $moritzFactor->bsstr;; 1e+0

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      You'd need a floating-point number with a mantissa of about 128 bits to hold the value of (1-1/2**128)

      Luckily there are other ways to evaluate the expression. If we set x = 1/2**128, we can do a taylor series to evaluate (1-x)**n around x = 0 (and since x is very small, it's a good approximation:

      (1 - x)^n = 1 - n * x + 1 / 2 * n * (n - 1) * x ** 2 + ...

      Where higher orders can be neglected. If you chose an n that is high enough, you can get non-1 values as the result.

      Though I'm not sure if that's really helpful. What you'd really need is the expectation value of the number of collisions (the lambda symbol in Poisson Distribution, then you could easily calculate everything you wanted.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962873]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2019-02-21 09:24 GMT
Find Nodes?
    Voting Booth?
    I use postfix dereferencing ...

    Results (109 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!