Documentation

Complexity.Algorithms.WordRAM.Hashing.MultiplyShift

Self-contained Word-RAM multiply-shift hashing #

This file implements the multiply-shift universal hash family of Dietzfelbinger, Hagerup, Katajainen, and Penttonen [DHKP97] as a self-contained pair of structured Word-RAM programs over Cslib.WordRAM.Basis.exact:

We prove that initCode w₀ induces the exact uniform distribution PMF.uniformOfFintype (Fin (2 ^ (w₀ - 1))) on the seed register regB, that evalCode w₀ M computes Cslib.Probability.multiplyShift w₀ M b x, and hence that the Word-RAM evaluation map is (2 / 2 ^ M)-universal (isUniversalHash_evalData).

Main definitions #

Main results #

References #

Register layout (Fin 5) #

@[reducible, inline]

Register 0: holds the sampled seed b < 2 ^ (w₀ - 1).

Instances For
    @[reducible, inline]

    Register 1: holds the input key x < 2 ^ w₀.

    Instances For
      @[reducible, inline]

      Register 2: receives the M-bit hash value multiplyShift w₀ M b x.

      Instances For
        @[reducible, inline]

        Register 3: first scratch register.

        Instances For
          @[reducible, inline]

          Register 4: second scratch register.

          Instances For

            Seed initialization (initCode) #

            Structured Word-RAM program that initializes the multiply-shift seed b ∈ [0, 2 ^ (w₀ - 1) - 1] in regB using 2 instructions and 1 rand call.

            Instances For

              Closed-form machine data after initCode w₀ samples k.

              Instances For

                Exact ProbComp computation induced by initCode w₀ from initial data d.

                Instances For

                  When w₀ ≤ w, initCode w₀ executes cleanly in 2 instructions and 1 rand call with exact ProbComp semantics initComp w₀ d.

                  theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.initCode_execRandWithin {w₀ w : ℕ} (hw : w₀ ≤ w) (d : WordRAM.Data 5) :
                  WordRAM.ExecRandWithin w (initCode w₀) d (fun (d' : WordRAM.Data 5) => d'.regs regB < 2 ^ (w₀ - 1) ∧ d'.regs regX = d.regs regX ∧ d'.regs regOut = d.regs regOut ∧ d'.mem = d.mem) 2 1

                  Hoare-style specification for initCode w₀: runs in 2 steps and 1 rand call, placing a seed < 2 ^ (w₀ - 1) in regB while preserving regX, regOut, and memory.

                  Extracting the seed < 2 ^ (w₀ - 1) from register regB of a machine state d', defaulting to 0 outside the valid range.

                  Instances For
                    @[simp]
                    theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.extractSeed_initData (w₀ : ℕ) (d : WordRAM.Data 5) (k : Fin (2 ^ (w₀ - 1) - 1 + 1)) :
                    extractSeed w₀ (initData w₀ d ↑k) = (finCongr ⋯) k

                    Uniformity of the sampled seed: the distribution of extractSeed w₀ z.1 under (initComp w₀ d).eval is the exact uniform distribution PMF.uniformOfFintype (Fin (2 ^ (w₀ - 1))).

                    Deterministic hash evaluation (evalCode) #

                    Structured Word-RAM program that evaluates multiplyShift w₀ M in 9 deterministic instructions (0 rand calls), reading b from regB and x from regX and writing the hash value into regOut.

                    Instances For

                      Closed-form final machine data produced by evalCode w₀ M from d.

                      Instances For
                        @[simp]
                        theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.evalData_regs_out (w₀ M : ℕ) (d : WordRAM.Data 5) :
                        (evalData w₀ M d).regs regOut = ((2 * d.regs regB + 1) * d.regs regX &&& 2 ^ w₀ - 1) >>> (w₀ - M)
                        theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.evalData_regs_out_eq_multiplyShift (w₀ M : ℕ) (d : WordRAM.Data 5) (b : Fin (2 ^ (w₀ - 1))) (x : Fin (2 ^ w₀)) (hb : d.regs regB = ↑b) (hx : d.regs regX = ↑x) :

                        The output register regOut of evalData w₀ M d equals Cslib.Probability.multiplyShift w₀ M.

                        theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.evalCode_exec {w₀ M w : ℕ} (hw₀ : 0 < w₀) (hw : 2 * w₀ ≤ w) {d : WordRAM.Data 5} (hb : d.regs regB < 2 ^ (w₀ - 1)) (hx : d.regs regX < 2 ^ w₀) :
                        WordRAM.Exec w (evalCode w₀ M) d (evalData w₀ M d) 9

                        Exact 9-instruction execution of evalCode w₀ M without intermediate word overflow when 0 < w₀, 2 * w₀ ≤ w, d.regs regB < 2 ^ (w₀ - 1), and d.regs regX < 2 ^ w₀.

                        theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.evalCode_execWithin {w₀ M w : ℕ} (hw₀ : 0 < w₀) (hw : 2 * w₀ ≤ w) {d : WordRAM.Data 5} (hb : d.regs regB < 2 ^ (w₀ - 1)) (hx : d.regs regX < 2 ^ w₀) :
                        WordRAM.ExecWithin w (evalCode w₀ M) d (evalData w₀ M d) 9

                        Bounded-time execution corollary for evalCode w₀ M (9 instructions).

                        theorem Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.isUniversalHash_evalData {w₀ M : ℕ} (hw₀ : 0 < w₀) (hM : M ≤ w₀) (d : WordRAM.Data 5) :
                        Probability.IsUniversalHash (PMF.map (fun (z : WordRAM.Data 5 × ℕ) => extractSeed w₀ z.1) (initComp w₀ d).eval) (fun (b : Fin (2 ^ (w₀ - 1))) (x : Fin (2 ^ w₀)) => (evalData w₀ M ((d.set regB ↑b).set regX ↑x)).regs regOut) (2 / 2 ^ M)

                        Universal hashing guarantee for the Word-RAM multiply-shift implementation: under the seed distribution of initCode w₀, the hash function mapping x : Fin (2 ^ w₀) to the output register regOut of evalData w₀ M is (2 / 2 ^ M)-universal whenever 0 < w₀ and M ≤ w₀.