Documentation

Complexity.Computability.WordRAM.ArrayNormalize

Charged in-place normalization of an array #

ArrayNormalize.program replaces each word of a supplied interval by its remainder modulo a supplied positive modulus. It executes actual loads, remainders and stores; the untouched memory need not already be normalized. This small topic module avoids adding an application specific transformation to the allocation API.

@[reducible, inline]

First address to normalize.

Instances For
    @[reducible, inline]

    Number of words.

    Instances For
      @[reducible, inline]

      Positive normalization modulus.

      Instances For
        @[reducible, inline]

        Current index.

        Instances For
          @[reducible, inline]

          Temporary absolute address.

          Instances For
            @[reducible, inline]

            Loaded and normalized word.

            Instances For
              @[reducible, inline]

              Constant one.

              Instances For

                Normalize one cell with five actual native instructions.

                Instances For

                  Fixed code for in-place normalization of an interval supplied in registers.

                  Instances For

                    Mathematical memory after normalizing a prefix; this is not a machine operation.

                    Instances For
                      theorem Cslib.WordRAM.ArrayNormalize.normalizePrefix_read (mem : ℕ → ℕ) (b M n j : ℕ) (hj : j < n) :
                      normalizePrefix mem b M n (b + j) = mem (b + j) % M

                      Every cell in the normalized interval contains its original remainder.

                      theorem Cslib.WordRAM.ArrayNormalize.normalizePrefix_outside (mem : ℕ → ℕ) (b M n a : ℕ) (ha : ¬(b ≤ a ∧ a < b + n)) :
                      normalizePrefix mem b M n a = mem a

                      Normalizing an interval leaves all outside memory unchanged.

                      theorem Cslib.WordRAM.ArrayNormalize.exec {W b M n : ℕ} (x : Data 7) (hb : x.regs base = b) (hn : x.regs length = n) (hm : x.regs modulus = M) (hM : 0 < M) (hfit : Fits W (b + n + M + 2)) :
                      ∃ (y : Data 7), ExecWithin W program x y (7 * n + 4) ∧ y.mem = normalizePrefix x.mem b M n ∧ y.regs base = b ∧ y.regs length = n ∧ y.regs modulus = M

                      In-place normalization costs at most 7n+4 native instructions, including every indexed load/store and loop decision. The input arguments and all outside memory are preserved.