Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Theorem · Uniform invalid rejection through the sharp safe length
parse_number return normally with None.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.Assumptions
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.NumberHelperPartialNumberSafeLength
import Tablet.SourceValidByteSlice
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_parse_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: NumberHelperRejectionSafeLength]
theorem NumberHelperRejectionSafeLength :
forall s : Slice Std.U8,
SourceValidByteSlice s -> s.val != [] ->
s.val.length <= 9223372036854120459 ->
(Not (exists x : DecimalLexeme,
x.leadingSign = none /\
DecimalGoalVocabularyDefault.validNumeric x /\
DecimalGoalVocabularyDefault.bytes s =
DecimalGoalVocabularyDefault.renderNumeric x)) ->
num.imp.dec2flt.parse.parse_number s = ok none := by
Proof
Natural-language proof
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Proof
usize and isize are both 64-bit.
Thus L\leq B<M, every slice length and index used below fits usize,
and every length-to-isize cast fits the nonnegative signed range.
The premise involving DecimalGoalVocabularyDefault says exactly
that the complete input is not a valid unsigned numeric rendering.0x46, eight copies of 0x30,
and eight copies of 0x80. Let c_i be the carry into byte i of
the wrapping addition by 0x4646464646464646, and let d_i be the
borrow into byte i of the wrapping subtraction by
0x3030303030303030; initially c_0=d_0=0. If the test returns true,
the high bit of every byte of both resulting words is zero, because their
bitwise OR has zero intersection with 0x8080808080808080.0x3030303030303030 has no borrow and
produces a word v' whose bytes are all in 0,\ldots,9. Hence
v'<\texttt{0x1000000000000000}=2^{60}. The checked multiplication by ten
is below 10\cdot2^{60}<2^{64}. The checked shift by eight is defined
because 8<64 and gives a value below 2^{52}, so the checked addition is
below 10\cdot2^{60}+2^{52}<2^{64}. The subsequent checked shifts by 16
and 32 are also defined because both counts are below 64; the intervening
masks, multiplications, and addition are explicitly wrapping. If their final
wrapped word is w<2^{64}, then
w\mathbin{\mathtt{>>}}32\leq2^{32}-1. The checked cast to u32
therefore succeeds, and its widening back to u64 is exact.u64, uses wrapping arithmetic for the mantissa, and increments its
count to at most that length. Slicing at the final count is consequently in
bounds. This proves normal execution of both possible digit scans on
arbitrary bytes, not only on numeric input.i64 is exact. The checked sum of the two digit counts is the total
number D of scanned significand digits and satisfies 0\leq D\leq L.
The input is nonempty, so the opening assertion in
num imp dec2flt parse parse partial number succeeds. If D=0,
that function returns None normally and there is nothing further to
check.e or E, no explicit
exponent arithmetic occurs. If it is a marker, unfold
num imp dec2flt parse parse scientific. Its optional sign split is
guarded. An empty suffix or a nondigit first byte returns None; the
option branch and residual operations in ModelOptionBranch and
ModelOptionFromResidual then make the partial parser return
None normally. Otherwise let q\geq1 be the number of exponent
digits consumed. At loop count j\leq q, the index is guarded by the suffix
length and the count increment remains at most L. While the accumulator
a is below 65536, the checked update obeys
10a+d\leq10\cdot65535+9=655359<2^{63}; afterwards the accumulator is left
unchanged. The final optional negation is therefore safe. The result is a
value E with |E|\leq655359 and the suffix beginning at the first
non-exponent-digit byte.isize. Those are the only two branches that advance the index.usize range.u64 cast is
exact, and every split is guarded. If the first retry scan reaches the
10^{18} threshold, its returned suffix precedes the saved end of the
integer digits; their offset_from is a nonnegative count at most
L, so both casts are safe.isize-to-i64 cast produce a retry base in [-F,0].parse_many_digits adds the explicit exponent
to that base. In the nonnegative integer-offset branch, no explicit exponent
gives a base at most L. A negative exponent lowers it by at most 655359.
For a positive explicit exponent with q digits, at least nineteen digits,
the marker, and those q digits lie outside the nonnegative remaining-digit
offset. Thus that offset plus E is at most L-q-20+(10^q-1) for
q\leq5, whose maximum is L+99974, and at most
L-q-20+655359 for q\geq6, whose maximum is L+655333. At
L\leq B both are below M. In the fractional branch the base is -R
with R\leq F. Its positive side is at most 655359, and its negative side
is bounded by the already proved F+|E|\leq2^{63}. Hence every final retry
addition is safe. This exhausts the guarded slices, casts, count arithmetic,
negations, mantissa arithmetic, and signed additions in the functions
num imp dec2flt parse try parse digits,
num imp dec2flt parse parse scientific,
num imp dec2flt parse adjust many digit count,
num imp dec2flt parse try parse 19digits,
num imp dec2flt parse parse many digits, and
num imp dec2flt parse parse partial number.None, num imp dec2flt parse parse number immediately
returns ok none. Otherwise it returns a decimal record together
with a consumed length r\leq L. If r=L, the scanned significand has at
least one digit; any point is in its unique scanned position; and any
exponent has a marker, optional sign, and at least one scanned digit. These
components form a valid lexeme with leadingSign = none, and the
whole-input equality says its rendering is exactly the input. That
contradicts the invalidity premise. Therefore r\ne L, and the final length
comparison in parse_number returns ok none, as claimed.Lean proof
intro s hvalid hnonempty hlen hinvalid
obtain ⟨o, hparse, hpartial⟩ :=
NumberHelperPartialNumberSafeLength s hvalid hnonempty hlen hinvalid
cases o with
| none =>
simpa [num.imp.dec2flt.parse.parse_number, hparse]
| some p =>
rcases p with ⟨d, r⟩
simp [num.imp.dec2flt.parse.parse_number, hparse]
intro heq
apply hpartial d r rfl
apply UScalar.eq_of_val_eq
simpa [Slice.len, Slice.length] using heq
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.Assumptions
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.NumberHelperPartialNumberSafeLength
import Tablet.SourceValidByteSlice
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_parse_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: NumberHelperRejectionSafeLength]
theorem NumberHelperRejectionSafeLength :
forall s : Slice Std.U8,
SourceValidByteSlice s -> s.val != [] ->
s.val.length <= 9223372036854120459 ->
(Not (exists x : DecimalLexeme,
x.leadingSign = none /\
DecimalGoalVocabularyDefault.validNumeric x /\
DecimalGoalVocabularyDefault.bytes s =
DecimalGoalVocabularyDefault.renderNumeric x)) ->
num.imp.dec2flt.parse.parse_number s = ok none := by
-- BODY
intro s hvalid hnonempty hlen hinvalid
obtain ⟨o, hparse, hpartial⟩ :=
NumberHelperPartialNumberSafeLength s hvalid hnonempty hlen hinvalid
cases o with
| none =>
simpa [num.imp.dec2flt.parse.parse_number, hparse]
| some p =>
rcases p with ⟨d, r⟩
simp [num.imp.dec2flt.parse.parse_number, hparse]
intro heq
apply hpartial d r rfl
apply UScalar.eq_of_val_eq
simpa [Slice.len, Slice.length] using heq
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- Assumptions
- DecimalGoalVocabularyDefault
- ModelOptionBranch
- ModelOptionFromResidual
- NumberHelperPartialNumberSafeLength
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
All 18 entries
- Assumptions
- DecimalGoalVocabularyDefault
- ModelOptionBranch
- ModelOptionFromResidual
- NumberHelperPartialNumberSafeLength
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SourceValidByteSlice
- num imp dec2flt common is 8digits
- num imp dec2flt parse MIN 19DIGIT INT
- num imp dec2flt parse adjust many digit count
- num imp dec2flt parse parse 8digits
- num imp dec2flt parse parse many digits
- num imp dec2flt parse parse number
- num imp dec2flt parse parse partial number
- num imp dec2flt parse parse scientific
- num imp dec2flt parse try parse 19digits
- num imp dec2flt parse try parse digits
Inspect related source (69)
- offset_from · dec2flt/common.rs:30 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
More program dependencies (36)
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- adjust_many_digit_count · dec2flt/parse.rs:86 Program Rust
- adjust_many_digit_count_loop · dec2flt/parse.rs:89 Program Rust
- body · dec2flt/parse.rs:89 Program Rust
- parse_8digits · dec2flt/parse.rs:18 Program Rust
- parse_many_digits · dec2flt/parse.rs:104 Program Rust
- parse_number · dec2flt/parse.rs:231 Program Rust
- parse_partial_number · dec2flt/parse.rs:161 Program Rust
- parse_scientific · dec2flt/parse.rs:121 Program Rust
- parse_scientific_loop · dec2flt/parse.rs:142 Program Rust
- body · dec2flt/parse.rs:142 Program Rust
- try_parse_19digits · dec2flt/parse.rs:61 Program Rust
- try_parse_19digits_loop · dec2flt/parse.rs:64 Program Rust
- body · dec2flt/parse.rs:64 Program Rust
- try_parse_digits · dec2flt/parse.rs:30 Program Rust
- try_parse_digits_loop0 · dec2flt/parse.rs:33 Program Rust
- body · dec2flt/parse.rs:33 Program Rust
- try_parse_digits_loop1 · dec2flt/parse.rs:50 Program Rust
- body · dec2flt/parse.rs:50 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (30)
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Dec2Flt.configured_x86_64_numBits
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
All 64 entries
- Binary64Model
- Binary64ModelDefault
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- F64
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- NumberHelperAdjustManySourceLength
- NumberHelperDigitScanSourceLength
- NumberHelperEightDigitWord
- NumberHelperFractionalManyDigitsSourceLength
- NumberHelperIntegralAdjustmentSourceLength
- NumberHelperIntegralManyDigitsSourceLength
- NumberHelperOffsetSourceLength
- NumberHelperParseEightDigitsSafe
- NumberHelperPartialNumberSafeLength
- NumberHelperReadEightBytes
- NumberHelperRejectionSafeLength
- NumberHelperScientificClassificationSourceLength
- NumberHelperScientificPrefixSafeLength
- NumberHelperTryParse19SafeLength
- Preamble
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SourceValidByteSlice
- core num FpCategory
- num imp dec2flt common BiasedFp
- num imp dec2flt common is 8digits
- num imp dec2flt decimal Decimal
- num imp dec2flt parse MIN 19DIGIT INT
- num imp dec2flt parse adjust many digit count
- num imp dec2flt parse parse 8digits
- num imp dec2flt parse parse 8digits MASK
- num imp dec2flt parse parse 8digits MUL1
- num imp dec2flt parse parse 8digits MUL2
- num imp dec2flt parse parse many digits
- num imp dec2flt parse parse number
- num imp dec2flt parse parse partial number
- num imp dec2flt parse parse scientific
- num imp dec2flt parse try parse 19digits
- num imp dec2flt parse try parse digits
Technical checking records
Local closure summary
{
"node": "NumberHelperRejectionSafeLength",
"closure_version": "patch_c_v1",
"active_decl_hash": "d20e1b21aa0cd711102d88ebf8bcccb70409ea5a0e12f051666db60df8f03e37",
"active_statement_hash": "07dcb9e954bf1853468b6068aa899bb4124ea33499f8e169aa72f0c9d899f50f",
"kernel_axioms": [
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-116",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperPartialNumberSafeLength": "e44fde0977cbf188"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "4da7f295a9b85b50",
"DecimalGoalVocabularyDefault": "512f8d0aea894250",
"DecimalLexeme": "c43614ff2149ecf2",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
"num_imp_dec2flt_parse_parse_number": "b8693ec58f01c43c",
"num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:3c14aa0a86f2b89a3a1a37d73ca47bbecb55f9e77eff7b0f4428ea7db2a3691f",
"current_fingerprint": "sound-v2:3c14aa0a86f2b89a3a1a37d73ca47bbecb55f9e77eff7b0f4428ea7db2a3691f",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}