TorchLean API

FloatLib.Numerics.Exact.RadixText.ScannerProof

Positional scanner laws shared by decimal and hexadecimal text #

Digit scanning computes the positional value, counts consumed digits, and leaves a nondigit suffix unchanged. For radix greater than one and a decoder that recognizes the printed digits, printing then scanning recovers any natural number, including zero.

theorem FloatLib.Numerics.RadixText.scanDigits_stop (radix : ) (readDigit : CharOption ) (tail : List Char) (htail : ctail.head?, readDigit c = none) (accumulator : ) :
scanDigits tail accumulator radix readDigit = (accumulator, 0, tail)

A radix scanner leaves a nondigit suffix untouched.

theorem FloatLib.Numerics.RadixText.scanDigits_map_append (radix : ) (readDigit : CharOption ) (digits : List ) (tail : List Char) (hdigits : digitdigits, readDigit digit.digitChar = some digit) (htail : ctail.head?, readDigit c = none) (accumulator : ) :
scanDigits (List.map Nat.digitChar digits ++ tail) accumulator radix readDigit = (accumulator * radix ^ digits.length + Nat.ofDigits radix digits.reverse, digits.length, tail)

Digit scanning computes the positional value, independently of the chosen radix.

@[simp]

Radix output has at least one digit, including for zero.

theorem FloatLib.Numerics.RadixText.scanDigits_naturalDigits (radix : ) (hradix : 1 < radix) (readDigit : CharOption ) (hdigit : digit < radix, readDigit digit.digitChar = some digit) (value : ) (tail : List Char) (htail : ctail.head?, readDigit c = none) :
scanDigits (naturalDigits value radix ++ tail) 0 radix readDigit = (value, (naturalDigits value radix).length, tail)

Printing then scanning recovers an arbitrary natural and leaves the nondigit suffix.