ParserNumericAcceptance__Refutation

Lean checked

Statement

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

Theorem

The following result is false: For every source-valid Rust string whose complete byte sequence is a valid numeric literal, the extracted f64 parser returns normally with Ok of a float.

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.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.ModelSliceFirst
import Tablet.ModelStrAsBytes
import Tablet.ParserNumericSlowPathOverflowWitness
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
import Tablet.ParserNumericOverflowPropagation

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericAcceptance__Refutation]
theorem ParserNumericAcceptance__Refutation : ¬ (∀ (s : Str) (x : DecimalLexeme), DecimalGoalVocabularyDefault.sourceString s -> DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x -> ∃ f : F64,
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f)) := 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

Let K=2147483618. Instantiate ParserNumericSlowPathOverflowWitness, call its body slice b, and regard that same slice carrier as an Aeneas Str; put s=b. The witness statement gives
s.\mathit{val}=[48,46]\mathbin{++}\operatorname{replicate}(11,48) \mathbin{++}\operatorname{bytes}(\texttt{1000000000000000080}) \mathbin{++}\operatorname{replicate}(K,48). \tag{1}
Let x have no leading sign, integer digits [0], fractional digits consisting of eleven zeroes, then [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0], then K zeroes, and no explicit exponent. This is the concrete unsigned witness.
We verify the three hypotheses of the claimed universal property. Every entry of both digit lists is below ten, the integer list is nonempty, and there is no exponent condition. Unfolding DecimalGoalVocabularyDefault therefore gives validNumeric x. Its rendering prepends no sign, maps the integer zero to byte 48, emits byte 46 for the point, maps the displayed fractional digits to the bytes in (1), and emits no exponent; hence bytes s = renderNumeric x.
The length calculation from ParserNumericSlowPathOverflowWitness is |s|=2147483650=2^{31}+2<2^{63}-1. For the UTF-8 clause, take the Lean string obtained with String.ofList from the character list 0., eleven 0 characters, the nineteen characters of 1000000000000000080, and K further 0 characters. Encoding each of 0, ., 1, and 8 produces its one-byte ASCII code. Induction on List.replicate, together with encoding over each of the four list appends, makes its UTF-8 byte list exactly (1). Mapping the Aeneas u8 wrappers to their natural values gives that same list. The length inequality and this explicit string witness prove sourceString s under DecimalGoalVocabularyDefault.
Now follow the extracted public parser. By ModelStrAsBytes, its first bind returns the complete slice (1). The list is nonempty and begins with byte 48, so ModelSliceFirst returns that byte. It is neither 43 nor 45; consequently num imp dec2flt dec2flt with trace takes no sign slice and its body1 is the complete nonempty body from ParserNumericSlowPathOverflowWitness. More explicitly, body1 and the already chosen s=b have the same underlying byte list; extensionality of the Aeneas slice subtype (the carrier proofs are propositions) gives \texttt{body1}=s=b. Thus that lemma gives parse_number = ok (some d) with mantissa 1000000000000000080, exponent -30, negative false, and many-digits true, and gives try_fast_path d = ok none. The dispatcher overwrites the record's sign with the test 48=45, which is false, so its fast-path input remains exactly d and the cited fast-path equation applies.
The dispatcher therefore calls num imp dec2flt lemire compute float on that exponent and mantissa. The witness lemma supplies (448160529771025,983). Since the record has many digits and 983\ge0, the second-computation guard is true. The checked mantissa increment is 1000000000000000081<2^{64}, and the lemma supplies the second result (448160529771026,983). It also supplies that the extracted pair comparison returns false. Thus lines 109--114 of the pinned dispatcher replace the first pair's biased power by -1 and set forced_deferral true. Because -1<0, the slow-path guard is true and the next monadic operation is exactly parse_long_mantissa(body1).
By ParserNumericSlowPathOverflowWitness, that operation is fail integerOverflow: its decimal parser has an empty remainder and a fractional first slice of length 2^{31}, whose truncating cast is i32::MIN; the immediately following checked subtraction 0-\texttt{i32::MIN} overflows. Result binding propagates this failure out of num imp dec2flt dec2flt with trace before word assembly or sign application is evaluated; in particular no purported trace pair is produced. The wrapper num imp dec2flt dec2flt binds the traced call before projecting its first component, so the public parser also equals fail integerOverflow. (2)
Suppose the universal statement in the theorem were true. Apply it to the just-proved source-valid s and valid exactly rendered x. It would give a float f for which the same public call is ok (Result.Ok f). This contradicts (2), since the Result.fail and Result.ok constructors are disjoint. Therefore the universal statement is false.

Lean proof


  intro claim
  obtain ⟨s, x, value_shape, size_shape, decimal_shape, source_ok,
    numeric_ok, rendering_ok, parser_fail⟩ :=
    ParserNumericOverflowPropagation
  obtain ⟨f, parser_ok⟩ := claim s x source_ok numeric_ok rendering_ok
  rw [parser_fail] at parser_ok
  cases parser_ok

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
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.ModelSliceFirst
import Tablet.ModelStrAsBytes
import Tablet.ParserNumericSlowPathOverflowWitness
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
import Tablet.ParserNumericOverflowPropagation

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericAcceptance__Refutation]
theorem ParserNumericAcceptance__Refutation : ¬ (∀ (s : Str) (x : DecimalLexeme), DecimalGoalVocabularyDefault.sourceString s -> DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x -> ∃ f : F64,
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f)) := by
-- BODY
  intro claim
  obtain ⟨s, x, value_shape, size_shape, decimal_shape, source_ok,
    numeric_ok, rendering_ok, parser_fail⟩ :=
    ParserNumericOverflowPropagation
  obtain ⟨f, parser_ok⟩ := claim s x source_ok numeric_ok rendering_ok
  rw [parser_fail] at parser_ok
  cases parser_ok

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 167 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericAcceptance__Refutation",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "461780324d557896b2d4c6b4b490cfcca83fe25c48c67e274cd1555b53e377de",
  "active_statement_hash": "d80a62386d10d86226d548be9f986c8abff6bf397a5e3a1f20109e4ebf1ef23c",
  "kernel_axioms": [
    "Classical.choice",
    "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-126",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ParserNumericOverflowPropagation": "5e19250c1aedc3eb"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "1f42f752b5d22513",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_dec2flt": "f9f7d93449a25efa"
  }
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:4e3c3b67c6cea5f9e25f1f2e80655cd3e82d9b0622bd3ececa061fd58bdd5e2e",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}