Documentation

Complexity.Algorithms.WordRAM.PrefixSums.Update

Fixed Word-RAM point updates for aggregation trees #

The program walks from the root to the updated leaf. Every visited node is incremented, and the next subtree is selected by the position relative to half the current length. The same code handles every height, position and increment. Its arithmetic and all its loads, stores, tests and jumps are actual bounded-word instructions.

Main definitions #

Main results #

References #

@[reducible, inline]

Constant zero.

Instances For
    @[reducible, inline]

    Constant one.

    Instances For
      @[reducible, inline]

      Constant two.

      Instances For
        @[reducible, inline]

        Current subtree pointer.

        Instances For
          @[reducible, inline]

          Current subtree length.

          Instances For
            @[reducible, inline]

            Position relative to the current subtree.

            Instances For
              @[reducible, inline]

              Increment supplied to an update.

              Instances For
                @[reducible, inline]

                Loaded value and arithmetic scratch.

                Instances For
                  @[reducible, inline]

                  Address scratch.

                  Instances For
                    @[reducible, inline]

                    Query answer.

                    Instances For
                      @[reducible, inline]

                      Operation tag, zero for update and nonzero for query.

                      Instances For
                        @[reducible, inline]

                        Persistent root pointer.

                        Instances For
                          @[reducible, inline]

                          Persistent array capacity.

                          Instances For
                            @[reducible, inline]

                            External operation position.

                            Instances For

                              Registers used by both tree traversals.

                              Instances For

                                Increment one node and move to the selected child. A leaf has half-length zero; the resulting length stops the loop before another access.

                                Instances For

                                  Fixed update code, independent of array size, position and increment.

                                  Instances For

                                    The data after one update iteration; this is a mathematical description, not an additional instruction in the machine.

                                    Instances For
                                      theorem Cslib.Algorithms.WordRAM.PrefixSums.updateBody_exec {w b n i δ : ℕ} {x : WordRAM.Data 14} (hx : Entry b n i δ x) (hi : i < n) (ha : WordRAM.Fits w (b + 2 * n)) (hv : WordRAM.Fits w (x.mem b + δ)) :
                                      theorem Cslib.Algorithms.WordRAM.PrefixSums.updateNext_entry {b n i δ : ℕ} {x : WordRAM.Data 14} (hx : Entry b n i δ x) :
                                      Entry (if i < n / 2 then b + 1 else b + n / 2 + n / 2) (n / 2) (if i < n / 2 then i else i - n / 2) δ (updateNext x b n i δ)
                                      @[simp]
                                      theorem Cslib.Algorithms.WordRAM.PrefixSums.updateNext_mem {b n i δ : ℕ} {x : WordRAM.Data 14} (a : ℕ) :
                                      (updateNext x b n i δ).mem a = Function.update x.mem b (x.mem b + δ) a
                                      theorem Cslib.Algorithms.WordRAM.PrefixSums.updateLoop_spec {w h b i δ : ℕ} {x : WordRAM.Data 14} (t : Tree h) (hx : Entry b (2 ^ h) i δ x) (hi : i < 2 ^ h) (hr : t.Rep b x.mem) (ha : WordRAM.Fits w (b + 2 * 2 ^ h)) (hv : WordRAM.Fits w (t.total + δ)) :
                                      ∃ (y : WordRAM.Data 14), WordRAM.ExecWithin w updateLoop x y (11 * (h + 1) + 2) ∧ (t.add i δ).Rep b y.mem ∧ ∀ (a : ℕ), a < b ∨ b + Tree.words h ≤ a → y.mem a = x.mem a

                                      The fixed update loop runs in at most 11 (h + 1) + 2 instructions. It restores the complete aggregation invariant and preserves every word outside the original footprint. The bound assumes the existing tree is supplied in memory; it does not include construction.