Documentation

Complexity.Algorithms.WordRAM.FusionTree.Rank

Packed sketch ranks #

Guard extraction and multiplication count all simultaneous comparisons. Complementing the sketches reverses the comparison to obtain inclusive ranks. None of these operations assumes a most-significant-bit primitive. Node constants must be precomputed and loaded separately.

Main definitions #

Main results #

References #

One guard bit per field, with all other bits zero.

Instances For

    The guard mask has no other set bits.

    Move each comparison's guard to the lowest bit of its radix field.

    Instances For
      theorem Cslib.Algorithms.WordRAM.FusionTree.guardFlags_eq {b n q : ℕ} (s : ℕ → ℕ) (hs : ∀ i < n, s i < 2 ^ b) (hq : q < 2 ^ b) :
      guardFlags b n s q = BitString.packRadix (2 ^ (b + 1)) n fun (i : ℕ) => (decide (q ≤ s i)).toNat

      Guard extraction returns exactly the packed zero-or-one comparison digits.

      Count all set comparison guards through the middle field of one product.

      Instances For
        theorem Cslib.Algorithms.WordRAM.FusionTree.countGuards_eq {b n q : ℕ} (s : ℕ → ℕ) (hn : 0 < n) (hb : n < 2 ^ (b + 1)) (hs : ∀ i < n, s i < 2 ^ b) (hq : q < 2 ^ b) :
        countGuards b n s q = ∑ i ∈ Finset.range n, (decide (q ≤ s i)).toNat

        An inclusive sketch rank, obtained by complementing both sides of each comparison.

        Instances For
          theorem Cslib.Algorithms.WordRAM.FusionTree.upperRankExpr_eq_card {b n q : ℕ} (s : ℕ → ℕ) (hn : 0 < n) (hb : n < 2 ^ (b + 1)) (hs : ∀ i < n, s i < 2 ^ b) (hq : q < 2 ^ b) :
          upperRankExpr b n s q = {i ∈ Finset.range n | s i ≤ q}.card

          The expression returns the number of sketches at or below the query. Sortedness is unnecessary for the arithmetic identity; a tree uses sorted sketches to interpret the rank.

          @[reducible, inline]

          Query sketch.

          Instances For
            @[reducible, inline]

            Packed guarded complements of the stored sketches.

            Instances For
              @[reducible, inline]

              Replication multiplier.

              Instances For
                @[reducible, inline]

                Mask selecting all guard bits.

                Instances For
                  @[reducible, inline]

                  Number of payload bits per field.

                  Instances For
                    @[reducible, inline]

                    Power selecting the count product's middle digit.

                    Instances For
                      @[reducible, inline]

                      Field radix.

                      Instances For
                        @[reducible, inline]

                        Largest possible payload.

                        Instances For
                          @[reducible, inline]

                          Replicated complemented query.

                          Instances For
                            @[reducible, inline]

                            Scratch register and final inclusive rank.

                            Instances For

                              Eight standard instructions compute the complete inclusive sketch rank. All eight input registers and all memory are preserved. The precomputed constants are supplied by the caller.

                              Instances For

                                The exact final data, retaining the intermediate temporary register.

                                Instances For
                                  theorem Cslib.Algorithms.WordRAM.FusionTree.RankProgram.exec {w b n q : ℕ} (s : ℕ → ℕ) (x : WordRAM.Data 10) (hn : 0 < n) (hb : n < 2 ^ (b + 1)) (hs : ∀ i < n, s i < 2 ^ b) (hq : q < 2 ^ b) (hw : 2 * ((b + 1) * n) ≤ w) (hxq : x.regs query = q) (hxn : x.regs node = packedNode b n fun (i : ℕ) => 2 ^ b - 1 - s i) (hxc : x.regs copies = queryMultiplier b n) (hxg : x.regs guards = guardMask b n) (hxb : x.regs bits = b) (hxm : x.regs middle = 2 ^ ((b + 1) * (n - 1))) (hxr : x.regs base = 2 ^ (b + 1)) (hxmax : x.regs maximum = 2 ^ b - 1) :
                                  WordRAM.Exec w code x (result x b n s q) 8 ∧ (result x b n s q).regs out = {i ∈ Finset.range n | s i ≤ q}.card ∧ (result x b n s q).mem = x.mem

                                  Checked execution of the full inclusive rank in eight instructions. The packed word occupies at most half the physical width, making the count multiplication legal too. Construction/loading of the node constants and compressed query remain separate.