Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Theorem · Uniform safe-length numeric acceptance
parse_number return
normally with Some of a decimal record.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.NumberHelperPartialAcceptanceSafeLength
import Tablet.NumberHelperScientificExponentBounds
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SourceValidByteSlice
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: NumberHelperAcceptanceSafeLength]
theorem NumberHelperAcceptanceSafeLength :
forall (s : Slice Std.U8) (x : DecimalLexeme),
SourceValidByteSlice s -> s.val != [] -> x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x ->
DecimalGoalVocabularyDefault.bytes s =
DecimalGoalVocabularyDefault.renderNumeric x ->
s.val.length <= 9223372036854120458 ->
exists d, num.imp.dec2flt.parse.parse_number s = ok (some d) := 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 nonnegative isize ranges.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. Acceptance says that in
every byte the high bit of both resulting words is zero, since 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. In particular
v'<\texttt{0x1000000000000000}=2^{60}. The checked multiplication by ten
is below 10\cdot2^{60}<2^{64}, and the checked right shift by eight is
defined because 8<64 and gives a value below 2^{52}. Their checked sum is
therefore below 10\cdot2^{60}+2^{52}<2^{64}. The later right shifts by
16 and 32 are likewise defined because both counts are below 64; the
intervening masks, multiplications, and addition are explicitly wrapping.
Whatever wrapped word w<2^{64} those operations produce, its final shift
w\mathbin{\mathtt{>>}}32 is at most 2^{32}-1. The checked cast to
u32 therefore succeeds, and the final widening back to u64
is exact.u64, and increments the count to a value at most that
length. Its final slice begins at that bounded count. Hence both digit-scan
invocations terminate normally at the first nondigit. By
SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from,
their offsets cast the lengths of a slice and one of its suffixes to
isize and take the checked difference. Both casts are exact at
length at most L, and each difference is a nonnegative value at most L.split_first; the
second digit scan has the same safety argument. Its fractional count is at
most L, its checked negation lies in the signed range, and the cast to
i64 is exact because isize and i64 are both
64-bit. The checked addition of integer and fractional digit counts is the
number of significand digits and is at most L. Validity makes that number
positive, so the extracted zero-digit rejection is not taken.e or E byte. Let q\geq1 be the number of exponent digits.
The rendering premise says that the saved suffix is an optional sign followed
by exactly those q digit bytes, with no further byte. We now establish the
normal result and full consumption directly, rather than obtaining either from
the conditional statement of
NumberHelperScientificExponentBounds.split_first either removes the unique optional plus or minus
sign, or observes the first digit and retains the original suffix. In every
case the resulting slice consists of exactly the q digits. It is nonempty,
so the index at zero is in bounds, and its first byte passes
is_ascii_digit. Induct on j=0,\ldots,q in the scientific loop.
At the start of iteration j, the count is j, the first j exponent digits
have been visited, and the accumulator a lies in [0,655359]. If j<q,
the guarded index reads exponent digit j and wrapping subtraction by 48
gives its value d\in[0,9]. When a<65536, the checked operations compute
10a+d\leq10\cdot65535+9=655359<2^{63}; when a\geq65536, no arithmetic
update is made. The checked count increment gives j+1\leq q\leq L<C<2^{63},
so it also lies in the configured usize range. Thus every one of the
q digit iterations succeeds, including iterations after the accumulator has
stopped changing. At count q the length guard is false. Slicing the
digit-only suffix at the in-bounds index q leaves the empty slice. Finally,
the optional checked negation is safe on [0,655359]. Hence
parse_scientific returns normally with Some of a value E
and an empty remainder, and the option-branch in the partial parser takes its
Continue case.i64 addition succeeds, including equality at i64::MIN.
The offset of the remaining suffix from the original input is again between
zero and L, and its cast through isize to usize succeeds.u64 casts and
guarded splits are also safe. If the threshold is reached before a point,
the retry base exponent is the nonnegative number of remaining integer
digits. With no explicit exponent it is at most L-19. With q exponent
digits it is at most L-q-20, since the spelling also contains the marker.
Adding a nonnegative E is therefore at most L+99974 for q\leq5, and at
most L+655333 for q\geq6; the latter maximum occurs at q=6. At
L\leq C this is at most M-16, so the cast and checked addition succeed.
Adding a negative E only lowers a nonnegative base by at most 655359 and
cannot underflow.s1 (the
int_end argument) as the suffix beginning with that point. The retry
scan starts at the original slice, classifies the same integer digit prefix,
and, since it did not reach the threshold, stops exactly at that same point.
Its returned slice is consequently equal to int_end, is nonempty,
and has point byte first. The extracted slice at index one is therefore
in-bounds and is exactly the suffix immediately after the point.isize-to-i64 cast, and the final checked addition.Some of a record and with its consumed-length field
equal to L: the rendering premise says the valid numeric spelling occupies
the whole input, so its final suffix is empty. The length comparison in
num imp dec2flt parse parse number therefore succeeds and that
function returns the same record in Some, as required.Lean proof
intro s x hsource hne hsign hvalid hbytes hlen
obtain ⟨d, hd⟩ := NumberHelperPartialAcceptanceSafeLength s x hsource hne
hsign hvalid hbytes hlen
refine ⟨d, ?_⟩
simp [num.imp.dec2flt.parse.parse_number, hd]
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.Assumptions
import Tablet.DecimalGoalVocabularyDefault
import Tablet.NumberHelperPartialAcceptanceSafeLength
import Tablet.NumberHelperScientificExponentBounds
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SourceValidByteSlice
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: NumberHelperAcceptanceSafeLength]
theorem NumberHelperAcceptanceSafeLength :
forall (s : Slice Std.U8) (x : DecimalLexeme),
SourceValidByteSlice s -> s.val != [] -> x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x ->
DecimalGoalVocabularyDefault.bytes s =
DecimalGoalVocabularyDefault.renderNumeric x ->
s.val.length <= 9223372036854120458 ->
exists d, num.imp.dec2flt.parse.parse_number s = ok (some d) := by
-- BODY
intro s x hsource hne hsign hvalid hbytes hlen
obtain ⟨d, hd⟩ := NumberHelperPartialAcceptanceSafeLength s x hsource hne
hsign hvalid hbytes hlen
refine ⟨d, ?_⟩
simp [num.imp.dec2flt.parse.parse_number, hd]
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- Assumptions
- DecimalGoalVocabularyDefault
- NumberHelperPartialAcceptanceSafeLength
- NumberHelperScientificExponentBounds
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
All 17 entries
- Assumptions
- DecimalGoalVocabularyDefault
- NumberHelperPartialAcceptanceSafeLength
- NumberHelperScientificExponentBounds
- 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)
- 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
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 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 68 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
- NumberHelperAcceptanceSafeLength
- NumberHelperAdjustManySafeLength
- NumberHelperDigitScanSafeLength
- NumberHelperEightDigitWord
- NumberHelperFractionalManyDigitsSafeLength
- NumberHelperIntegralAdjustment
- NumberHelperIntegralManyDigitsSafeLength
- NumberHelperOffsetSafeLength
- NumberHelperParseEightDigitsSafe
- NumberHelperPartialAcceptanceSafeLength
- NumberHelperReadEightBytes
- NumberHelperScientificRenderedSuffixSafeLength
- NumberHelperScientificShortSuffixSafeLength
- NumberHelperScientificSignedSuffixSafeLength
- NumberHelperScientificSuffixSafeLength
- NumberHelperScientificSuffixSharpSafeLength
- NumberHelperSplitExponentSuffix
- 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": "NumberHelperAcceptanceSafeLength",
"closure_version": "patch_c_v1",
"active_decl_hash": "37ce1c73397564da8ffda50bef17f1683df26ee4d6a1934836ea5c96fffa44fd",
"active_statement_hash": "f10e30fc768033e84fdcaa72d4abb65f95ffa76fe2c15839182c3a8745b8901a",
"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-109",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperPartialAcceptanceSafeLength": "8932d60be6df1417"
},
"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:7b67986355e19604b5dcd2bde32859af164ca9ce9312e667dd670c8cdecd6384",
"current_fingerprint": "sound-v2:7b67986355e19604b5dcd2bde32859af164ca9ce9312e667dd670c8cdecd6384",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}