Documentation

Complexity.Algorithms.WordRAM.Deduplicate.Count

Native counting of one adjacent run #

The counter tests the array bound before every read and stops at the first different word. No sorting or counting oracle is used. The mathematical end index is a proof parameter and does not occur in the code or a register.

Main definitions #

Main results #

@[reducible, inline]

Input length.

Instances For
    @[reducible, inline]

    Sorted input array.

    Instances For
      @[reducible, inline]

      Unique-key output array.

      Instances For
        @[reducible, inline]

        Multiplicity output array.

        Instances For
          @[reducible, inline]

          Input cursor.

          Instances For
            @[reducible, inline]

            Number of completed output runs.

            Instances For
              @[reducible, inline]

              Current run key.

              Instances For
                @[reducible, inline]

                Current run multiplicity.

                Instances For
                  @[reducible, inline]

                  Loaded input word.

                  Instances For
                    @[reducible, inline]

                    Address temporary.

                    Instances For
                      @[reducible, inline]

                      Constant one.

                      Instances For
                        @[reducible, inline]

                        Run-counting loop flag.

                        Instances For

                          Read the next word only if the cursor is in bounds; count it or end the run.

                          Instances For

                            Count from the current cursor, starting with zero count and flag one.

                            Instances For
                              theorem Cslib.Algorithms.WordRAM.Deduplicate.Count.exec {w s n start stop k : ℕ} (x : WordRAM.Data 16) (hn : x.regs len = n) (hs : x.regs src = s) (hi : x.regs idx = start) (hk : x.regs key = k) (hc : x.regs count = 0) (ha : x.regs active = 1) (ho : x.regs one = 1) (hle : start ≤ stop) (hstop : stop ≤ n) (hmem : ∀ (j : ℕ), start ≤ j → j < stop → x.mem (s + j) = k) (hnext : stop < n → x.mem (s + stop) ≠ k) (hfit : WordRAM.Fits w (s + n)) :
                              ∃ (y : WordRAM.Data 16), WordRAM.ExecWithin w code x y (8 * (stop - start) + 10) ∧ y.regs idx = stop ∧ y.regs count = stop - start ∧ y.mem = x.mem

                              Count a maximal adjacent run in 8c+10 instructions, including the terminating test. stop is a proof parameter: execution learns the boundary solely through charged comparisons and loads. The source memory is unchanged. Empty runs are also admitted by this kernel.