DecimalSeqReconstruction

Lean checked

Statement

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

Lemma · Exact decimal-sequence reconstruction

Let a source-valid slice s render a valid unsigned numeric lexeme x, and suppose parse_decimal_seq(s) returns d. Concatenate the integer and fractional digit lists, delete their maximal leading zero run, and then delete the maximal trailing zero run; call the resulting complete digit word C' and let N=|C'|. Then
d.\mathit{num\_digits}=\min(N,768),
the value list of the first d.\mathit{num\_digits} array cells is exactly the corresponding prefix of C', and
d.\mathit{truncated}=\mathrm{true}\quad\Longleftrightarrow\quad N>768.
Here the two deletions are exactly the dropWhile/reverse operations shown 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: DecimalSeqReconstruction]
theorem DecimalSeqReconstruction :
    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 trimmed :=
        (significant.reverse.dropWhile (fun digit => digit == 0)).reverse
      d.num_digits.val = min trimmed.length 768 /\
        (d.digits.val.take d.num_digits.val).map (fun z => z.val) =
          trimmed.take d.num_digits.val /\
        (d.truncated = true <-> 768 < trimmed.length) := 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 to the source-validity, unsigned-sign, validity, rendering, and successful-parse hypotheses. Its S is the concatenation of the integer digits with the optional fractional digits, and its R is obtained from S by the same leading-zero deletion followed by reverse, leading-zero deletion, and reverse operations used in this statement. The first conjunct of that theorem therefore says directly that the returned count is \min(|R|,768), that the values of the retained array prefix are the corresponding prefix of R, and that truncation is true exactly when 768<|R|. These are precisely the three required conclusions; the theorem's additional decimal-point congruence is not needed here.

Lean proof


  intro s x d hsource hsign hvalid hbytes hparse
  exact (DecimalSeqLexicalState s x d hsource hsign hvalid hbytes hparse).1

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: DecimalSeqReconstruction]
theorem DecimalSeqReconstruction :
    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 trimmed :=
        (significant.reverse.dropWhile (fun digit => digit == 0)).reverse
      d.num_digits.val = min trimmed.length 768 /\
        (d.digits.val.take d.num_digits.val).map (fun z => z.val) =
          trimmed.take d.num_digits.val /\
        (d.truncated = true <-> 768 < trimmed.length) := by
-- BODY
  intro s x d hsource hsign hvalid hbytes hparse
  exact (DecimalSeqLexicalState s x d hsource hsign hvalid hbytes hparse).1

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": "DecimalSeqReconstruction",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "0c3989c14dcfb31fad95ea3595545c6116b351442f32355efe4cc7d613705db4",
  "active_statement_hash": "28a7195590ca754138f5b8e3e30e319f627826845f63e97c23b237baee090a04",
  "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-169",
  "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:bdbd937b8aabd84276bf3ca93bf58297f8264fc0daae3b0c8b1574a162bcb97b",
  "current_fingerprint": "sound-v2:7de1818a5f1194c580e1095437f35b5ad74ab5fb0554cd79aa93cdca59557de0",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}