TorchLean API

NN.Floats.NeuralFloat.Format.Digits

Integer Digits, Scaling, and Slices #

These definitions are the effective integer layer used by radix-based rounding algorithms. Signed division and remainder use Int.tdiv and Int.tmod, matching Flocq's quotient and remainder toward zero rather than Lean's Euclidean / and % operations.

Integer radix power, with the Flocq convention that negative powers are zero.

Instances For
    @[simp]

    The signed radix digit at position k.

    Instances For
      @[simp]
      theorem TorchLean.Floats.neuralDigit_of_neg_index (β : NeuralRadix) (n : ) {k : } (hk : k < 0) :
      neuralDigit β n k = 0

      Every signed digit has absolute value strictly smaller than the radix.

      Shift an integer left for nonnegative k, and right with truncation for negative k.

      Instances For
        theorem TorchLean.Floats.neuralScale_of_nonneg (β : NeuralRadix) (n : ) {k : } (hk : 0 k) :
        theorem TorchLean.Floats.neuralScale_of_neg (β : NeuralRadix) (n : ) {k : } (hk : k < 0) :
        neuralScale β n k = n.tdiv (neuralIntPower β (-k))
        @[simp]
        def TorchLean.Floats.neuralSlice (β : NeuralRadix) (n start width : ) :

        Extract width radix digits beginning at start; negative widths produce zero.

        Instances For
          @[simp]
          theorem TorchLean.Floats.neuralSlice_zero_value (β : NeuralRadix) (start width : ) :
          neuralSlice β 0 start width = 0
          theorem TorchLean.Floats.neuralSlice_of_neg_width (β : NeuralRadix) (n start : ) {width : } (hwidth : width < 0) :
          neuralSlice β n start width = 0
          theorem TorchLean.Floats.neuralSlice_abs_lt_power (β : NeuralRadix) (n start : ) {width : } (hwidth : 0 width) :
          |neuralSlice β n start width| < neuralIntPower β width

          A nonnegative-width slice has absolute value below the corresponding radix power.

          @[simp]
          theorem TorchLean.Floats.neuralSlice_neg (β : NeuralRadix) (n start width : ) :
          neuralSlice β (-n) start width = -neuralSlice β n start width

          Number of base-β digits in the absolute value of an integer.

          Instances For
            theorem TorchLean.Floats.neuralDigits_bounds (β : NeuralRadix) {n : } (hn : n 0) :

            A nonzero integer lies between consecutive powers selected by its digit count.

            The radix digit count of a positive integer is the magnitude of its real embedding.

            theorem TorchLean.Floats.intCast_lt_neuralBpow_digits (β : NeuralRadix) {n : } (hn : 0 < n) :
            n < neuralBpow β (neuralDigits β n)

            A positive integer is strictly below the radix power selected by its digit count.

            The successor of a positive integer does not exceed its next radix-power boundary.

            theorem TorchLean.Floats.neuralDigits_unique (β : NeuralRadix) {n : } (hn : n 0) {d : } (hd : 0 < d) (hlower : β.base ^ (d - 1) n.natAbs) (hupper : n.natAbs < β.base ^ d) :

            The power bounds uniquely determine the digit count of a nonzero integer.

            theorem TorchLean.Floats.neuralDigits_mono_abs (β : NeuralRadix) {n m : } (hn : n 0) (hnm : n.natAbs m.natAbs) :

            Digit count is monotone with respect to integer absolute value away from zero.

            theorem TorchLean.Floats.neuralDigits_mul_le (β : NeuralRadix) {n m : } (hn : n 0) (hm : m 0) :

            A nonzero product uses at most the sum of the operand digit counts.

            A positive radix power has one more digit than its exponent.