ParserEqualTargetRounding

Lean checked

Statement

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

Theorem

For every accepted source-valid numeric literal, if one binary64 magnitude word is a rounding target of both its exact value and its accumulated-exponent value, the returned word is that common target with the literal's lexical sign.

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.ParserAccumulatedRounding
import Tablet.RoundingDeterminism
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.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: ParserEqualTargetRounding]
theorem ParserEqualTargetRounding :
    ∀ (s : Str) (x : DecimalLexeme) (f target : F64), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
      DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.exactMagnitude x) target ->
      DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target ->
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ->
      DecimalGoalVocabularyDefault.signedMagnitude (DecimalGoalVocabularyDefault.lexicalNegative x) target 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.

Earlier prose review

An earlier review questioned the prose argument. Lean subsequently checked the formal proof. Review of the statement’s intended meaning is a separate judgment.

Proof

Fix a source string s, a numeric lexeme x, a returned word f, and a word \mathit{target} satisfying all the hypotheses. Apply ParserAccumulatedRounding to the source-validity of s, the validity of x, the equality between the bytes of s and the rendering of x, and the successful public-parser result. Its conclusion supplies a binary64 word m such that
\operatorname{roundsMagnitude} (\operatorname{accumulatedMagnitude}(x),m) \quad\text{and}\quad \operatorname{signedMagnitude} (\operatorname{lexicalNegative}(x),m,f). \tag{1}
The assumed accumulated-value rounding assertion says that the same real \operatorname{accumulatedMagnitude}(x) rounds to \mathit{target}. Unfold only the roundsMagnitude field of DecimalGoalVocabularyDefault in this assertion. The first conjunct in that field is nonnegativity of the real being rounded, so it gives
0\leq \operatorname{accumulatedMagnitude}(x). \tag{2}
Now apply RoundingDeterminism to this real, to the two words m and \mathit{target}, to (2), to the first assertion in (1), and to the assumed accumulated-value rounding assertion. It follows that m=\mathit{target}. Substitution of this equality into the second assertion in (1) gives
\operatorname{signedMagnitude} (\operatorname{lexicalNegative}(x),\mathit{target},f),
which is the required conclusion.
The hypothesis that the exact magnitude also rounds to \mathit{target} is not needed after it identifies \mathit{target} as the common target named by the theorem. The argument proves the stronger accumulated-target bridge, so retaining that additional premise in the stated implication is valid.

Lean proof


  intro s x f target hsource hvalid hrender _hexact htarget hparse
  obtain ⟨m, hm, hsigned⟩ :=
    ParserAccumulatedRounding s x f hsource hvalid hrender hparse
  have hnonnegative :
      0 <= DecimalGoalVocabularyDefault.accumulatedMagnitude x := by
    change 0 <= DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧ _ at htarget
    exact htarget.1
  have heq : m = target :=
    RoundingDeterminism
      (DecimalGoalVocabularyDefault.accumulatedMagnitude x) m target
      hnonnegative hm htarget
  simpa [heq] using hsigned

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ParserAccumulatedRounding
import Tablet.RoundingDeterminism
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.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: ParserEqualTargetRounding]
theorem ParserEqualTargetRounding :
    ∀ (s : Str) (x : DecimalLexeme) (f target : F64), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
      DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.exactMagnitude x) target ->
      DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target ->
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ->
      DecimalGoalVocabularyDefault.signedMagnitude (DecimalGoalVocabularyDefault.lexicalNegative x) target f := by
-- BODY
  intro s x f target hsource hvalid hrender _hexact htarget hparse
  obtain ⟨m, hm, hsigned⟩ :=
    ParserAccumulatedRounding s x f hsource hvalid hrender hparse
  have hnonnegative :
      0 <= DecimalGoalVocabularyDefault.accumulatedMagnitude x := by
    change 0 <= DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧ _ at htarget
    exact htarget.1
  have heq : m = target :=
    RoundingDeterminism
      (DecimalGoalVocabularyDefault.accumulatedMagnitude x) m target
      hnonnegative hm htarget
  simpa [heq] using hsigned

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 335 entries
Technical checking records
Local closure summary
{
  "node": "ParserEqualTargetRounding",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "a3cca14bb79ece2f8cca0bbdd859b30edb7995f26557836e7c7030407acb0fa9",
  "active_statement_hash": "a3607106ee7cb1326b4854ee0de431ebf313b7e71a9b6e7f5855e413993a84b4",
  "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": "revalidate-cycle-202",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "ParserAccumulatedRounding": "34c5e0fa4f99bb54",
    "RoundingDeterminism": "6500074d31847e13"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "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": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "ReviewerPinnedFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:77ba7dd7c968a45469d534483a5f52f325197eebf9ca5a446a4144199315bdf4",
  "current_fingerprint": "sound-v2:af92464c2dd5d1fa07ba758867ded0eaf6dc0a8ac034cd0b6a3d68e6c14618b9",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}