Documentation

Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Count

Native Chan–He collision counting #

This fixed native program first decodes signed Euclidean residue keys, then builds a histogram and counts ordered collisions. Register setup between the two loops is charged. For injective input arrays its counter is exactly the existing Chan–He coll.

Main definitions #

Main results #

References #

Residue routine registers occupy the first sixteen registers.

Instances For

    Histogram registers occupy registers sixteen through twenty-six.

    Instances For
      @[reducible, inline]

      Encoded integer input base.

      Instances For
        @[reducible, inline]

        Residue scratch base.

        Instances For
          @[reducible, inline]

          Number of input values.

          Instances For
            @[reducible, inline]

            Encoded positive modulus.

            Instances For
              @[reducible, inline]

              Histogram destination base.

              Instances For
                @[reducible, inline]

                Output collision count, an ordinary unsigned word.

                Instances For
                  @[reducible, inline]

                  Histogram input base register.

                  Instances For
                    @[reducible, inline]

                    Histogram output base register.

                    Instances For
                      @[reducible, inline]

                      Histogram length register.

                      Instances For
                        @[reducible, inline]

                        Histogram modulus register.

                        Instances For
                          @[reducible, inline]

                          Histogram constant register, also used to decode the encoded modulus.

                          Instances For

                            Set up the histogram parameters, explicitly decoding the positive modulus.

                            Instances For

                              A single finite native program, independent of input length, modulus and word width.

                              Instances For

                                The complete counting program preserves its input base, scratch base, length, encoded modulus and histogram base registers.

                                def Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Count.memory (mem : ℕ → ℕ) (values : ℕ → ℤ) (n M scratch dst : ℕ) :
                                ℕ → ℕ

                                The residue scratch array and the complete histogram, framed by the original memory.

                                Instances For
                                  theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Count.memory_before (mem : ℕ → ℕ) (values : ℕ → ℤ) (n M scratch dst a : ℕ) (hs : a < scratch) (hd : a < dst) :
                                  memory mem values n M scratch dst a = mem a

                                  Neither the residue array nor the histogram modifies an earlier memory cell.

                                  theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Count.exec {w M : ℕ} (x : WordRAM.Data 28) (values : ℕ → ℤ) (hM : 0 < M) (hmod : GenericRAM.Signed.Fits w ↑M) (hmodreg : x.regs modulus = WordRAM.Signed.encode ↑M) (hfit : ∀ i < x.regs len, GenericRAM.Signed.Fits w (values i)) (hs : WordRAM.Fits (w + 2) (x.regs src + x.regs len)) (hk : WordRAM.Fits (w + 2) (x.regs scratch + x.regs len)) (hd : WordRAM.Fits (w + 2) (x.regs dst + M)) (ht : WordRAM.Fits (w + 2) (x.regs len * x.regs len + x.regs len + 1)) (hsk : x.regs src + x.regs len ≤ x.regs scratch) (hkd : x.regs scratch + x.regs len ≤ x.regs dst) (hinput : ∀ i < x.regs len, x.mem (x.regs src + i) = WordRAM.Signed.encode (values i)) :
                                  ∃ (y : WordRAM.Data 28), WordRAM.ExecWithin (w + 2) program x y (34 * x.regs len + 5 * M + 18) ∧ y.mem = memory x.mem values (x.regs len) M (x.regs scratch) (x.regs dst) ∧ y.regs total = Histogram.pairs (fun (i : ℕ) => (values i % ↑M).toNat) (x.regs len) ∧ ∀ (i : Fin 28), 9 ≤ ↑i ∧ ↑i ≤ 12 ∨ i = dst → y.regs i = x.regs i

                                  Complete native collision counting, including residue computation, clearing the histogram and register setup. Input, scratch and histogram blocks occur in that order and are disjoint. The final halt is excluded. Fit hypotheses are local; a caller must derive them from its input and width contract.

                                  theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Count.exec_coll {w M : ℕ} (x : WordRAM.Data 28) (values : ℕ → ℤ) (hM : 0 < M) (hmod : GenericRAM.Signed.Fits w ↑M) (hmodreg : x.regs modulus = WordRAM.Signed.encode ↑M) (hfit : ∀ i < x.regs len, GenericRAM.Signed.Fits w (values i)) (hs : WordRAM.Fits (w + 2) (x.regs src + x.regs len)) (hk : WordRAM.Fits (w + 2) (x.regs scratch + x.regs len)) (hd : WordRAM.Fits (w + 2) (x.regs dst + M)) (ht : WordRAM.Fits (w + 2) (x.regs len * x.regs len + x.regs len + 1)) (hsk : x.regs src + x.regs len ≤ x.regs scratch) (hkd : x.regs scratch + x.regs len ≤ x.regs dst) (hinput : ∀ i < x.regs len, x.mem (x.regs src + i) = WordRAM.Signed.encode (values i)) (hinj : Set.InjOn values ↑(Finset.range (x.regs len))) :
                                  ∃ (y : WordRAM.Data 28), WordRAM.ExecWithin (w + 2) program x y (34 * x.regs len + 5 * M + 18) ∧ y.mem = memory x.mem values (x.regs len) M (x.regs scratch) (x.regs dst) ∧ y.regs total = ThreeSum.ChanHe.coll (Finset.image values (Finset.range (x.regs len))) M ∧ ∀ (i : Fin 28), 9 ≤ ↑i ∧ ↑i ≤ 12 ∨ i = dst → y.regs i = x.regs i

                                  For an injective integer array, the composed program returns exactly the collision count used by the existing Chan–He prime searches.