SpecialHelperRejection

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Theorem

For every Rust byte slice that is none of the unsigned inf, infinity, and nan keywords, and either separate sign argument, the specialized parse_inf_nan returns 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.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ParserSpecialRejectionSafeLength
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: SpecialHelperRejection]
theorem SpecialHelperRejection :
    ∀ (s : Slice Std.U8) (negative : Bool),
      SourceValidByteSlice s ->
      (¬ DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) none false) ->
      (¬ DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) none true) ->
      num.imp.dec2flt.parse.parse_inf_nan
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative = 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

Fix a slice s and a Boolean negative satisfying the three hypotheses. Write L for the length of s and b_j for the unsigned natural value of its byte at index j. The first hypothesis is exactly the Rust-slice length condition of SourceValidByteSlice; no content or UTF-8 condition is being used. The other hypotheses, after unfolding DecimalGoalVocabularyDefault, say respectively that the complete byte list is neither an ASCII-case variant of inf or infinity, nor an ASCII-case variant of nan. Indeed, with sign argument none, the sign-byte prefix is empty, so the body in specialLiteral is the complete byte list.
Unfold num imp dec2flt parse parse inf nan. Its first test is L=8. If that is false, its second and only remaining length test is L=3. Consequently, when L is neither eight nor three, both tests are false and the displayed final branch is immediately ok none; no index, cast, shift, bit operation, floating-point constant, or negation is evaluated.
Suppose first that L=8. In SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64, the range request self[..8] is in bounds because 8=L. The destination array also has exactly eight entries, so copy_from_slice has equal source and destination lengths and succeeds. The final from_le_bytes therefore returns the word
r=\sum_{j=0}^{7} b_j2^{8j},
with b_0 in the least significant byte. Thus this entire bind returns normally.
The next operation ANDs r with M=\mathtt{0xdfdfdfdfdfdfdfdf}. By ModelU64BitAnd, it succeeds and acts independently on corresponding bits. Every byte of M is 0xdf, whose binary form has every bit set except the ASCII case bit 0x20. Hence byte b_j of r\mathbin{\&}M is b_j\mathbin{\&}\mathtt{0xdf}. For any uppercase-letter byte u occurring below, the equality b_j\mathbin{\&}\mathtt{0xdf}=u holds exactly when b_j=u or b_j=u+\mathtt{0x20}: equality fixes all seven retained bits, while the one cleared bit may be zero or one. These are precisely the uppercase and lowercase forms of that letter.
The eight-byte match has only one branch returning some: its decimal constant 6436850368004902473 is 0x5954494e49464e49, whose little-endian bytes are 49 4e 46 49 4e 49 54 59, namely INFINITY. Equality with this masked word therefore says that the complete eight input bytes are, position by position, uppercase or lowercase forms of infinity. The body equal to the complete byte list then satisfies the eight-letter alternative of specialLiteral with sign none and kind false, contradicting the unsigned-infinity hypothesis. This match branch is impossible. The branches for the two other displayed constants and the default branch each return ok none directly, so every possible eight-byte execution has the required result.
It remains to consider L=3. The indices 0, 1, and 2 are all strictly below L, so each of the three extracted indexing binds succeeds and returns the corresponding byte. Each such value lies in 0,\ldots,255; its checked cast from u8 to u64 is therefore in range, succeeds, and preserves its value exactly. These two extracted shifts are specifically c <<< 16#i32 and b <<< 8#i32: their right operands are signed i32 values, not unsigned u32 values. The Aeneas UScalar-by-IScalar left-shift operation first checks that the signed count is nonnegative, converts it to a natural number, and then checks that number against the bit width of the unsigned left operand; on success it returns the zero-filled 64-bit shift, and either failed check returns integer overflow. Here the literal counts have signed values 16 and 8, so both are nonnegative, their natural conversions remain 16 and 8, and both are strictly below the u64 width 64. Thus both shifts succeed.
They also have no high-bit truncation. Since each input came from a byte, 0\leq b_2,b_1\leq255, whence
b_2 2^{16}\leq255\cdot2^{16}<256\cdot2^{16}=2^{24}<2^{64} \quad\hbox{and}\quad b_1 2^8\leq255\cdot2^8<256\cdot2^8=2^{16}<2^{64}.
Consequently the checked 64-bit results are exactly b_2 2^{16} and b_1 2^8, rather than reductions modulo 2^{64}. Their occupied bit ranges are respectively 16--23 and 8--15; the widened b_0 occupies bits 0--7. They are disjoint. Therefore both operations described by ModelU64BitOr succeed, and the two extracted ORs assemble exactly the little-endian word
r=b_0+b_1 2^8+b_2 2^{16}<2^{24}.
The subsequent AND with M succeeds by ModelU64BitAnd; its low three bytes clear exactly the same case bit as above, and its upper five bytes remain zero.
There are now only two potentially successful matches. The constant 4607561=\mathtt{0x464e49} has little-endian bytes 49 4e 46, namely INF. Equality after masking says exactly that the three input bytes are a case variant of inf; choosing the complete byte list as the empty-prefix body establishes specialLiteral (bytes s) none false, contradicting the first grammar negation. Similarly, 5128526=\mathtt{0x4e414e} has little-endian bytes 4e 41 4e, namely NAN. Its match would establish specialLiteral (bytes s) none true, contradicting the second grammar negation. The remaining displayed constant 6436850368004902473 cannot equal this masked word because that word is below 2^{24}, and in any event its branch returns ok none; the default branch also returns ok none. Thus every possible three-byte execution returns ok none.
Finally, in the extracted definition the infinity/NaN constant lookup, the test of the separate negative argument, and the possible negation all occur only after one of the successful word matches. The grammar-negation hypotheses excluded every such match at lengths eight and three. Hence none of that sign-dependent code is reached, for either Boolean value, and the three exhaustive length cases prove the result.

Lean proof


  intro s negative _ hnotInf hnotNan
  exact ParserSpecialRejectionSafeLength s negative hnotInf hnotNan

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ParserSpecialRejectionSafeLength
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: SpecialHelperRejection]
theorem SpecialHelperRejection :
    ∀ (s : Slice Std.U8) (negative : Bool),
      SourceValidByteSlice s ->
      (¬ DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) none false) ->
      (¬ DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) none true) ->
      num.imp.dec2flt.parse.parse_inf_nan
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s negative = ok none := by
-- BODY
  intro s negative _ hnotInf hnotNan
  exact ParserSpecialRejectionSafeLength s negative hnotInf hnotNan

end dec2flt_model

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
Standard-library dependencies (39)

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

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 83 entries
Technical checking records
Local closure summary
{
  "node": "SpecialHelperRejection",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c2f0205b1b1f45a722960ae7ebe74646cf4dd712883a4e8de0016176f5780db6",
  "active_statement_hash": "a68d1482ac66762b418de8666fefd0718f1065c435ede987c920ac1d4d740f37",
  "kernel_axioms": [
    "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-123",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ParserSpecialRejectionSafeLength": "1edbaca00e34bed4"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "1696fb9af4405e6e",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_parse_parse_inf_nan": "85655c19a8791b54"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:cb9daf031a29ee94f0c40e1668451f78028f651211f72e2162b192ead365d498",
  "current_fingerprint": "sound-v2:cb9daf031a29ee94f0c40e1668451f78028f651211f72e2162b192ead365d498",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}