Documentation

Complexity.Algorithms.WordRAM.FusionTree.MSBProgram

Checked constant-instruction most-significant-bit execution #

The 44 virtual slots spell out the arithmetic in MSB.msb. Slot zero holds the input; the other 43 slots are constants or binary standard RAM operations. The checked compiler expands them into standard instructions at the original physical word width, using eighteen half-word digits per virtual value. Every virtual intermediate fits in 6w bits.

Main definitions #

Main results #

Code depends on the width through preprocessing constants, with uniformly bounded size and 836 physical registers. The scalar entry uses registers four and six for input and output; the remainder of its register workspace may change. Memory is preserved exactly. There is no uniform fixed-code preprocessing theorem or claim that the constants are generated at run time.

References #

The values of the 44 virtual slots. The two comparison/count stages use the named pure expressions from MSB, so their intermediate bounds remain reusable.

Instances For

    Source operations in destination order. Slot zero is an unused placeholder: execution starts at slot one with the input already present in slot zero.

    Instances For

      Slot zero is the supplied input.

      Every executed source node agrees with its pure arithmetic expression.

      All source operands precede their destination, including the unused constant placeholder at zero. Hence each executed destination is fresh.

      On nonzero inputs, the last slot is exactly the arithmetic expression msb.

      theorem Cslib.Algorithms.WordRAM.FusionTree.MSB.Program.values_output {w x : ℕ} (hx0 : 0 < x) (hx : x < 2 ^ w) :

      With the width-dependent cluster size, the final source value is the highest set-bit index. This is a source-graph result, without a RAM execution assertion.

      Each virtual value occurs in an audited stage list, apart from the unit constant, the selected-cluster offset, the unmasked selected input, and the final output.

      theorem Cslib.Algorithms.WordRAM.FusionTree.MSB.Program.values_lt {w x : ℕ} (hw : 0 < w) (hx0 : 0 < x) (hx : x < 2 ^ w) (i : Fin 44) :
      values (clusterSize w) x i < 2 ^ (6 * w)

      All 44 virtual values fit in the audited 6w virtual bits.

      At widths at least three, the precomputed cluster size is strictly smaller than the physical width.

      Twice the physical width itself fits in a physical word at widths at least three.

      The two guarded comparison inputs and their sums fit in physical words.

      Every shift count used by the source graph fits in one physical word.

      theorem Cslib.Algorithms.WordRAM.FusionTree.MSB.Program.output_add_fits {w x : ℕ} (hx0 : 0 < x) (hx : x < 2 ^ w) :
      have s := clusterSize w; have c := smallMSB s (clusterSummary s x); have v := x >>> (c * s) &&& 2 ^ s - 1; WordRAM.Fits w (c * s) ∧ WordRAM.Fits w (smallMSB s v) ∧ WordRAM.Fits w (c * s + smallMSB s v)

      The final addition has fitting operands and result.

      theorem Cslib.Algorithms.WordRAM.FusionTree.MSB.Program.ops_admissible {w x : ℕ} (hw : 3 ≤ w) (hx0 : 0 < x) (hx : x < 2 ^ w) (i : Fin 44) (hi : i ≠ 0) :

      Every executed node satisfies the concrete multiword compiler's admissibility contract. Only the additions and shift counts require physical-word bounds.

      @[reducible, inline]

      Physical register containing the final scalar answer.

      Instances For
        @[reducible, inline]

        A physical zero used for the input-zero branch.

        Instances For

          The forty-three arithmetic nodes, followed by checked scalar reconstruction.

          Instances For

            Execution of the actual expanded graph on a positive input. Every virtual operation is discharged by Circuit.exec_emit, which uses the checked single-word routines.

            Width two needs only division by two: its possible indices are zero and one.

            Instances For

              The width-selected checked program. For larger widths the zero case returns zero and positive inputs execute the full graph. All constants and conversions are charged.

              Instances For

                A fixed register count and a fixed code-size bound, shared by every physical width.

                The complete standard-basis program executes at the original physical width, from the ordinary singleton RAM input, within a constant instruction count independent of width. No preloaded wide constants, digit encodings, or MSB oracle are assumptions.

                Zero dispatch and positive arithmetic after the input bank entry has been established.

                Instances For

                  Register entry point for composition. The caller supplies its fitting input in physical register four. All 792 bank digits are cleared, the input is split in 44 instructions, and the same checked graph returns its answer in physical register six. No memory is read.

                  Instances For

                    Composable scalar-register execution. The entire incoming register file and memory may be arbitrary. Only the input register must fit. The routine preserves memory exactly and returns Nat.log2 in physical register six within 200000 instructions, including clearing. Registers inside this 836-register workspace may change; renamed embeddings frame all others.

                    The complete flat standard-basis program, with its final halt charged separately.

                    Instances For
                      theorem Cslib.Algorithms.WordRAM.FusionTree.MSB.Program.executes_program {w z : ℕ} (hw : 2 ≤ w) (hz : z < 2 ^ w) :
                      ∃ t ≤ 200001, WordRAM.Executes w (program w) (WordRAM.State.init [z]) z.log2 t

                      Actual halting execution returning the most-significant-set-bit index, with zero returning zero. The register count and the time bound are independent of physical width.