Documentation

Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Place

Native heavy extraction and light placement #

The input, unsigned residue array and histogram are supplied by the actual Count.program. One scan copies heavy integers, in input order, to a compact output. Each light integer is tagged and placed directly in the packed node array. The third pass negates its integer and its residue, and writes both copies required by arrZ.

The mathematical comparator is Anthropic's Buckets.lean and NodeArray.lean at formal-math@16a5ce41304fcdaea4e0be7c132e1c361dc26da5. The native code, encoding arithmetic and execution proofs here are original. No Light execution theorem or source-machine simulation is assumed.

Main definitions #

References #

@[reducible, inline]

Input array base.

Instances For
    @[reducible, inline]

    Unsigned residue array base.

    Instances For
      @[reducible, inline]

      Input length.

      Instances For
        @[reducible, inline]

        Histogram base.

        Instances For
          @[reducible, inline]

          Compact heavy output base.

          Instances For
            @[reducible, inline]

            Packed node output base.

            Instances For
              @[reducible, inline]

              Positive modulus, decoded unsigned.

              Instances For
                @[reducible, inline]

                Twice the positive tag added to a light integer.

                Instances For
                  @[reducible, inline]

                  Column in a four-cell group.

                  Instances For
                    @[reducible, inline]

                    Distance to the second write: zero for X/Y, 4M for Z.

                    Instances For
                      @[reducible, inline]

                      Zero for X/Y, one for Z.

                      Instances For
                        @[reducible, inline]

                        Input cursor.

                        Instances For
                          @[reducible, inline]

                          Number of heavy integers already written.

                          Instances For
                            @[reducible, inline]

                            Temporary address.

                            Instances For
                              @[reducible, inline]

                              Current remainder.

                              Instances For
                                @[reducible, inline]

                                Current value and its tagged encoding.

                                Instances For
                                  @[reducible, inline]

                                  Twice the current magnitude.

                                  Instances For
                                    @[reducible, inline]

                                    Current input sign.

                                    Instances For
                                      @[reducible, inline]

                                      Constant one.

                                      Instances For
                                        @[reducible, inline]

                                        Constant two.

                                        Instances For
                                          @[reducible, inline]

                                          Constant four.

                                          Instances For
                                            @[reducible, inline]

                                            Constant zero.

                                            Instances For
                                              @[reducible, inline]

                                              Current histogram count.

                                              Instances For

                                                Negating a Euclidean residue needs only a subtraction and a remainder.

                                                Instances For

                                                  Integer contribution before the positive tag.

                                                  Instances For

                                                    The target index is exactly the residue of the signed contribution.

                                                    A prefix of the compact output; membership is tested against the full histogram.

                                                    Instances For

                                                      A compact prefix has at most as many cells as the corresponding input prefix.

                                                      theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Place.heavyList_eq_filter (values : ℕ → ℤ) (n M k : ℕ) :
                                                      heavyList values n M k = List.map values (List.filter (fun (i : ℕ) => decide (1 < Histogram.count (fun (j : ℕ) => residueKey M (values j)) n (residueKey M (values i)))) (List.range k))

                                                      The compact array is the input subsequence selected by the histogram test.

                                                      theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Place.heavyList_toFinset (values : ℕ → ℤ) (n : ℕ) {M : ℕ} (hM : 0 < M) (hinj : Set.InjOn values ↑(Finset.range n)) :

                                                      The native compact output has exactly the existing heavy subset as its underlying set.

                                                      def Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Place.write (mem : ℕ → ℕ) (values : ℕ → ℤ) (n M out dst col dist t : ℕ) (neg : Bool) (k : ℕ) :
                                                      ℕ → ℕ

                                                      The exact per-input write, either to the next compact heavy cell or to packed light cells.

                                                      Instances For
                                                        def Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Place.memory (mem : ℕ → ℕ) (values : ℕ → ℤ) (n M out dst col dist t : ℕ) (neg : Bool) :
                                                        ℕ → ℕ → ℕ

                                                        All writes of the first k iterations, framed by arbitrary initial memory.

                                                        Instances For

                                                          Copy a heavy integer without changing its signed encoding.

                                                          Instances For

                                                            Tag a light integer using its magnitude and sign, then write its required cells.

                                                            Instances For

                                                              Every iteration reads the original integer, its unsigned key and its exact bucket size.

                                                              Instances For

                                                                The same finite code handles every input length, width, modulus and output length.

                                                                Instances For

                                                                  All runtime parameters survive the scan.

                                                                  theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Place.memory_outside (mem : ℕ → ℕ) (values : ℕ → ℤ) (n M out dst col dist t N : ℕ) (neg : Bool) (hM : 0 < M) (hN : 2 * M ≤ N) (hc : col < 4) (hd : dist ≤ 4 * M) {k : ℕ} (hk : k ≤ n) {a : ℕ} (ha : ¬(out ≤ a ∧ a < out + n)) (hb : ¬(dst ≤ a ∧ a < dst + 4 * N)) :
                                                                  memory mem values n M out dst col dist t neg k a = mem a

                                                                  A scan can only change its heavy capacity block and its packed output block.