DecimalSeqPointAgreement

Lean checked

Statement

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

Lemma · Decimal-sequence point agrees with the lexical point

Let a source-valid slice s render a valid unsigned numeric lexeme x, and suppose parse_decimal_seq(s) returns d. Let S be the concatenated integer and fractional digit word, let z be the length of its maximal leading zero run, and put
P=|x.\mathit{integerDigits}|-z, \qquad E=\operatorname{accumulatedExplicitExponent}(x).
If -342\le P+E\le327, then
d.\mathit{decimal\_point}=P+E.
The leading-zero and point quantities are the exact let-bound expressions in Lean.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.DecimalSeqLexicalState

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqPointAgreement]
theorem DecimalSeqPointAgreement :
    forall (s : Slice Std.U8) (x : DecimalLexeme)
      (d : num.imp.dec2flt.decimal_seq.DecimalSeq),
      SourceValidByteSlice s ->
      x.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d ->
      let significand := x.integerDigits ++
        match x.fractionDigits with | none => [] | some ds => ds
      let significant := significand.dropWhile (fun digit => digit == 0)
      let leadingZeros := significand.length - significant.length
      let P : Int := (x.integerDigits.length : Int) - leadingZeros
      let E : Int :=
        DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
      (-342 <= P + E) ->
      (P + E <= 327) ->
      d.decimal_point.val = P + E := 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

Apply DecimalSeqLexicalState with the given source-validity, unsigned-sign, numeric-validity, rendering, and successful-parse hypotheses. Its point-congruence clause supplies an integer k such that
d.\mathit{decimal\_point}=(P+E)+k\,2^{32}. \tag{1}
Here its definitions of the significand, maximal leading-zero run, P, and E are exactly the let-bound definitions in the present statement.
Put q=P+E. The two range hypotheses give -342\le q\le327. Since d.\mathit{decimal\_point} has the I32 carrier, its integer value lies in the interval
-2^{31}\le d.\mathit{decimal\_point}\le2^{31}-1. \tag{2}
If k\ge1, then (1) and the lower bound on q imply
d.\mathit{decimal\_point} \ge -342+2^{32}>2^{31}-1,
contradicting the upper bound in (2). If k\le-1, then (1) and the upper bound on q imply
d.\mathit{decimal\_point} \le327-2^{32}<-2^{31},
contradicting the lower bound in (2). Every integer k is either positive, negative, or zero, so these contradictions force k=0. Substituting this in (1) gives d.\mathit{decimal\_point}=q=P+E, as required.

Lean proof


  intro s x d hsource hsign hvalid hbytes hparse
  dsimp only
  intro hlo hhi
  have hlex := DecimalSeqLexicalState s x d hsource hsign hvalid hbytes hparse
  dsimp only at hlex
  rcases hlex.2 with ⟨k, hk⟩
  let sig : List Nat := x.integerDigits ++
    match x.fractionDigits with | none => [] | some ds => ds
  let q : Int := (x.integerDigits.length : Int) -
      ((sig.length - (sig.dropWhile (fun digit => digit == 0)).length : Nat) : Int) +
      DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
  have hlo' : -342 <= q := by simpa [q, sig] using hlo
  have hhi' : q <= 327 := by simpa [q, sig] using hhi
  have hk' : d.decimal_point.val = q + k * 4294967296 := by
    simpa [q, sig] using hk
  have hb := IScalar.hBounds d.decimal_point
  norm_num at hb
  change d.decimal_point.val = q
  clear_value q
  omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqLexicalState

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqPointAgreement]
theorem DecimalSeqPointAgreement :
    forall (s : Slice Std.U8) (x : DecimalLexeme)
      (d : num.imp.dec2flt.decimal_seq.DecimalSeq),
      SourceValidByteSlice s ->
      x.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d ->
      let significand := x.integerDigits ++
        match x.fractionDigits with | none => [] | some ds => ds
      let significant := significand.dropWhile (fun digit => digit == 0)
      let leadingZeros := significand.length - significant.length
      let P : Int := (x.integerDigits.length : Int) - leadingZeros
      let E : Int :=
        DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
      (-342 <= P + E) ->
      (P + E <= 327) ->
      d.decimal_point.val = P + E := by
-- BODY
  intro s x d hsource hsign hvalid hbytes hparse
  dsimp only
  intro hlo hhi
  have hlex := DecimalSeqLexicalState s x d hsource hsign hvalid hbytes hparse
  dsimp only at hlex
  rcases hlex.2 with ⟨k, hk⟩
  let sig : List Nat := x.integerDigits ++
    match x.fractionDigits with | none => [] | some ds => ds
  let q : Int := (x.integerDigits.length : Int) -
      ((sig.length - (sig.dropWhile (fun digit => digit == 0)).length : Nat) : Int) +
      DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
  have hlo' : -342 <= q := by simpa [q, sig] using hlo
  have hhi' : q <= 327 := by simpa [q, sig] using hhi
  have hk' : d.decimal_point.val = q + k * 4294967296 := by
    simpa [q, sig] using hk
  have hb := IScalar.hBounds d.decimal_point
  norm_num at hb
  change d.decimal_point.val = q
  clear_value q
  omega

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (77)
More program dependencies (44)
Standard-library dependencies (30)

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 57 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqPointAgreement",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "3d73afa985424d1ce29d2c65131b1ac81217fc5f50bb1e98153b255102044e97",
  "active_statement_hash": "49cac8859e6d2c9ab4180799e8f49da9d8caac0c8d1c3b013f1767e0d40018dc",
  "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-171",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalSeqLexicalState": "299de66f6f59538e"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "8ad754cf2c272e73",
    "DecimalSeqLexicalState": "55eb6bce0e8a4131",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "13e3cec939d02f51",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "244cf8318357caab"
  }
}
Prose assessment
{
  "label": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "ReviewerPinnedFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:2e7b365ebeda1f7b3b6911b96bdbc5067b127e4947fa9b1a6f5b03c8f73326c9",
  "current_fingerprint": "sound-v2:a481543e74a55213814bca2ab1efa49292f57c368b8d058c45866caf59b1d139",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}