P435_T1_PartialLexicalCertificateA

Lean checked

Statement

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

Lemma · On-normal partial lexical certificate and consumed length

Let s be any nonempty byte slice with |s|\le A=3458764513820540928. Suppose the actual partial-number function returns \texttt{ok}(o). For every o=\texttt{some}(d,k) there are an unsigned valid numeric lexeme x and a byte list R such that
\texttt{bytes}(s)=\texttt{renderNumeric}(x)++\operatorname{map}(\mathit{val},R), \qquad k.\mathit{val}=|\texttt{renderNumeric}(x)|.
The residual R is empty or nondigit-headed. If x has no exponent, its residual head, if present, is neither 69 nor 101, and is also not 46 when x has no fractional part. Conversely, for every x,R satisfying exactly these conditions, the given normal result is \texttt{some}(d,k) for some d,k, with that same consumed-length equation. Validity and rendering here are those of DecimalGoalVocabularyDefault, and unsigned means no leading sign. This is a prefix certificate, including its maximality guards, not a normality theorem and not a claim about the Decimal's numerical fields. In particular, after an exponent is present the residual may start with another marker or point, provided it is a nondigit.

Lean statement

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

import Tablet.P435_T1_RenderedDigitBlocks
import Tablet.P435_T1_DigitDecoding
import Tablet.P435_T1_DigitPrefixUnique
import Tablet.P435_T1_SignificandScanA
import Tablet.P364_T1_NumberHelperDigitPrefix
import Tablet.Assumptions
import Tablet.ModelSliceSplitFirst
import Tablet.P367_T1_NumberHelperScientificScan
import Tablet.P364_T1_NumberHelperOffsetSourceLength
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.P835_T1_PartialRunForwardA
import Tablet.P835_T1_PartialRunReverseA

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P435_T1_PartialLexicalCertificateA]
theorem P435_T1_PartialLexicalCertificateA (s : Slice Std.U8)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928)
    (result : Option (num.imp.dec2flt.decimal.Decimal × Std.Usize))
    (hnormal : num.imp.dec2flt.parse.parse_partial_number s = ok result) :
    (forall d consumed, result = some (d, consumed) ->
      exists (x : DecimalLexeme) (tail : List Std.U8),
        x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x ++ tail.map (fun b => b.val) /\
        (forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) /\
        (x.exponent = none -> forall b rest, tail = b :: rest ->
          b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length) /\
    (forall (x : DecimalLexeme) (tail : List Std.U8),
      x.leadingSign = none -> DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x ++ tail.map (fun b => b.val) ->
      (forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) ->
      (x.exponent = none -> forall b rest, tail = b :: rest ->
        b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) ->
      exists d consumed, result = some (d, consumed) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).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.

Proof

We first identify the source's lexical path independently of the Decimal record it eventually selects. Apply NumberHelperDigitPrefix to the source contents to obtain their maximal integer digit run I and remaining list T_1. If T_1 starts with 46, remove that head and apply the same theorem to the remaining list to obtain F,T_2; mark the fraction present. Otherwise set F=[], T_2=T_1, and mark the fraction absent. In this latter case a nonempty T_2 has head different from 46. These lists satisfy every hypothesis of SignificandScanA: the source decomposition, integer/fraction digit ranges, nondigit-headed T_2, the absent-point guard, and the original A bound. That theorem gives the actual normal scan and optional-fraction-block equations, the saved integer end, the significand end with contents T_2, and exact count D=|I|+|F|. It also gives the base exponent -|F|. The initial nonempty assertion succeeds because of the hypothesis s.\mathit{val}\ne[]; it imposes no grammar condition.
Substitute these equations in num imp dec2flt parse parse partial number. If D=0, the source returns None, so a given Some output is impossible. Otherwise ModelSliceSplitFirst either finds an empty T_2, exposes a head other than 69 and 101, or exposes one of those markers. In the first two cases choose no exponent and final residual R=T_2. In the marker case remove the marker and apply NumberHelperScientificScan to its actual suffix slice. It provides optional sign \sigma, maximal digit run J, final residual R, and a normal optional exponent. The exponent is None exactly when J=[]. By ModelOptionBranch and ModelOptionFromResidual, this case returns None from the partial parser; otherwise it continues with the returned exponent. The scientific theorem validates the entire maximal digit run, with no digit-count restriction, even after the pre-update 2^{59} fold stops changing its value. These steps describe both and only the syntactic None exits of the partial source: zero significand count and a present marker without any exponent digit.
Every remaining source arm computes the offset of its final residual from the original s, casts that offset to Usize, and then selects a record. The residual is a suffix by the decompositions just obtained, so its length is at most |s|\le A<2^{63}-1. NumberHelperOffsetSourceLength supplies the actual offset with value |s|-|R|. This lies between zero and A. The selected 64-bit binding in Assumptions identifies Usize's maximum as 2^{64}-1; therefore the signed-to-unsigned reinterpreting cast is exact on this nonnegative in-range value. Consequently every continued record has k.\mathit{val}=|s|-|R|. Inspection of all four source suffix arms (empty, lowercase marker, uppercase marker, other head) shows the same saved length in each retained and retry constructor. Adjustment and retry only select and compute record fields. They have Result-valued outputs, not optional outputs, and do not supply an additional None constructor.
This last observation uses the given normal result correctly: if a reached checked arithmetic operation, adjustment, or retry failed or diverged, the Result bind would propagate that outcome, contradicting \texttt{ok}(o). On any normal continuation, their outputs lead to one of the explicit Some constructors, preserving the saved length. We do not infer normality from valid grammar, nor assume a mantissa bound. Normality is a separate obligation; here it is the premise that makes this purely lexical, on-normal certificate applicable.
For the forward assertion, a Some output therefore has D>0 and a nonempty J whenever a marker was scanned. Use DigitDecoding on I,F,J. Their decoded natural lists have digits below ten, and reencoding recovers exactly their byte-value maps. Construct x from those lists, with no leading sign, fraction present exactly when the point was consumed, and exponent present exactly when a marker was consumed, retaining its upper/lower case and optional sign. The positive count makes at least one of I,F nonempty; their decoded lengths are unchanged. The exponent list, when present, is nonempty. Thus all four validity clauses in DecimalGoalVocabularyDefault hold, including the allowed empty integer or empty fraction alternatives. Map the source decomposition to values and use the reencoding equations to obtain \texttt{bytes}(s)=\texttt{renderNumeric}(x)++ \operatorname{map}(\mathit{val},R). Its length equation gives |\texttt{renderNumeric}(x)|=|s|-|R|=k.\mathit{val}. The residual is nondigit-headed by the scan theorems. With no exponent, its marker guards are exactly the source's nonmarker branch conditions; with neither exponent nor fraction its point guard is the earlier absent-point branch condition. This proves every forward clause.
For the reverse assertion, take any stated x,R. Apply RenderedDigitBlocks to the given prefix-rendering equality, with B=s.\mathit{val} and remainder R, to obtain actual byte blocks for its integer, fraction, and exponent digits. Its integer block is maximal: the next byte is 46 when a fraction is present, 69 or 101 when only an exponent follows, or the nondigit head of R or end otherwise. By DigitPrefixUnique it is exactly the actual I. When the fraction is absent there cannot be a guarded point: an exponent marker is not 46, and with no exponent the hypothesized residual point guard excludes 46. When present, the forced 46 is consumed and its fractional block is maximal, since its following byte is an exponent marker or the nondigit head of R or end. The uniqueness lemma identifies that block with the actual F. Thus the actual point-presence choice and both digit runs match x. Validity gives D>0, so the zero-count None exit is excluded.
If x has no exponent, the identified significand end has contents T_2=R. By ModelSliceSplitFirst, an empty R takes the empty arm; otherwise its head is neither 101 nor 69 by the given residual marker guards, so it takes the other-head arm. Neither arm makes a scientific call, and both use that same residual slice.
If x has an exponent, write c for its rendered marker and \sigma_x for its rendered optional sign. The byte-block equation from RenderedDigitBlocks, together with the integer and fraction identifications above, gives the actual significand-end contents
T_2=[c]++\operatorname{signBytes}(\sigma_x)++J++R.
Here c=101 for lower case and c=69 for upper case. Applying ModelSliceSplitFirst to this actual slice returns precisely c and a suffix slice u with
u.\mathit{val}=\operatorname{signBytes}(\sigma_x)++J++R.
Thus the lowercase branch of num imp dec2flt parse parse partial number calls the scientific parser on u when c=101; when c=69, the first comparison fails and the uppercase branch makes the identical call on u. The sign bytes in this equation are empty, [43], or [45] for absent, plus, or minus respectively, exactly as rendered in DecimalGoalVocabularyDefault.
We check the scientific-prefix hypotheses on these specified bytes. Every byte of J lies in [48,57], by the digit-range conclusion of RenderedDigitBlocks. Its value-map equation is the encoding of the exponent digits of x. Taking lengths of that equation gives |J| equal to their length; validity in DecimalGoalVocabularyDefault makes this length positive, so J\ne[]. The assumed condition on R says separately that its head, if present, lies outside [48,57]. Consequently J is a maximal digit prefix of J++R, including when R is nonempty. Finally the displayed equation for u.\mathit{val} is the required exact slice decomposition, not just an equality of byte values or lengths. Apply NumberHelperScientificPrefixSafeLength to this actual u, sign \sigma_x, digit list J, and tail R. Its statement supplies an I64 exponent e and slice r such that
\texttt{parse\_scientific}(u)=\texttt{ok}(\texttt{some}(e),r), \qquad r.\mathit{val}=R.
This application covers both leading signs and every allowed nondigit-headed R; no empty-tail or exponent-digit-count restriction has been added, and no unbounded exponent-fold exactness is used. If the earlier application of NumberHelperScientificScan names its result (v,r_0), equate its normal-return equation for this same u with the displayed equation. Injectivity of ok and of pairs gives v=\texttt{some}(e) and r_0=r. The None alternative is impossible by disjointness of option constructors; in the Some alternative, injectivity of Some identifies its exponent with e. Thus its residual contents are also exactly R; we need not identify its existential sign witness. By ModelOptionBranch, the actual Some exponent takes Continue with e, not Break, so the marker-without-digits None exit is excluded in both marker cases.
We already have D>0, so neither syntactic None exit remains. Keep the original premise \texttt{parse\_partial\_number}(s) =\texttt{ok}(o): any reached checked exponent addition, adjustment, or retry must return normally, since failure or divergence would propagate through its Result bind and contradict that premise. Every normal continuation in the exhaustive source arms returns Some (d,k) with the saved length; it does not introduce another optional rejection. In all cases its final residual has contents R, whose length is at most |s|\le A. Applying NumberHelperOffsetSourceLength to the original slice and this residual gives offset value |s|-|R|. The exact in-range Usize cast justified above therefore gives k.\mathit{val}=|s|-|R|, and the given normal result is this Some. Taking lengths of the original prefix-rendering equality yields |s|=|\texttt{renderNumeric}(x)|+|R| because both value maps preserve length. Hence k.\mathit{val}=|\texttt{renderNumeric}(x)|, proving the reverse assertion without asserting termination of the partial parser.

Lean proof


  constructor
  · obtain ⟨integer, intTail, hsplit, hd, ht⟩ :=
      P364_T1_NumberHelperDigitPrefix s.val
    cases intTail with
    | nil =>
      exact P835_T1_PartialRunForwardA s integer [] [] false hne hlen
        (by simpa using hsplit) (by simp) hd (by simp) (by simp) (by simp)
        result hnormal
    | cons b bs =>
      by_cases hp : b = 46#u8
      · obtain ⟨fraction, tail, hfrac, hf, htail⟩ :=
          P364_T1_NumberHelperDigitPrefix bs
        exact P835_T1_PartialRunForwardA s integer fraction tail true hne hlen
          (by simpa [hp, hfrac] using hsplit) (by simp) hd hf htail (by simp)
          result hnormal
      · exact P835_T1_PartialRunForwardA s integer [] (b :: bs) false hne hlen
          (by simpa using hsplit) (by simp) hd (by simp) ht
          (by intro _ c cs h; cases h; exact hp) result hnormal
  · intro x tail hsign hvalid hrender htail hguards
    exact P835_T1_PartialRunReverseA s hne hlen result hnormal
      x tail hsign hvalid hrender htail hguards

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P435_T1_RenderedDigitBlocks
import Tablet.P435_T1_DigitDecoding
import Tablet.P435_T1_DigitPrefixUnique
import Tablet.P435_T1_SignificandScanA
import Tablet.P364_T1_NumberHelperDigitPrefix
import Tablet.Assumptions
import Tablet.ModelSliceSplitFirst
import Tablet.P367_T1_NumberHelperScientificScan
import Tablet.P364_T1_NumberHelperOffsetSourceLength
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.P835_T1_PartialRunForwardA
import Tablet.P835_T1_PartialRunReverseA

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P435_T1_PartialLexicalCertificateA]
theorem P435_T1_PartialLexicalCertificateA (s : Slice Std.U8)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928)
    (result : Option (num.imp.dec2flt.decimal.Decimal × Std.Usize))
    (hnormal : num.imp.dec2flt.parse.parse_partial_number s = ok result) :
    (forall d consumed, result = some (d, consumed) ->
      exists (x : DecimalLexeme) (tail : List Std.U8),
        x.leadingSign = none /\ DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x ++ tail.map (fun b => b.val) /\
        (forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) /\
        (x.exponent = none -> forall b rest, tail = b :: rest ->
          b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length) /\
    (forall (x : DecimalLexeme) (tail : List Std.U8),
      x.leadingSign = none -> DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x ++ tail.map (fun b => b.val) ->
      (forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57)) ->
      (x.exponent = none -> forall b rest, tail = b :: rest ->
        b ≠ 69#u8 /\ b ≠ 101#u8 /\ (x.fractionDigits = none -> b ≠ 46#u8)) ->
      exists d consumed, result = some (d, consumed) /\
        consumed.val = (DecimalGoalVocabularyDefault.renderNumeric x).length) := by
-- BODY
  constructor
  · obtain ⟨integer, intTail, hsplit, hd, ht⟩ :=
      P364_T1_NumberHelperDigitPrefix s.val
    cases intTail with
    | nil =>
      exact P835_T1_PartialRunForwardA s integer [] [] false hne hlen
        (by simpa using hsplit) (by simp) hd (by simp) (by simp) (by simp)
        result hnormal
    | cons b bs =>
      by_cases hp : b = 46#u8
      · obtain ⟨fraction, tail, hfrac, hf, htail⟩ :=
          P364_T1_NumberHelperDigitPrefix bs
        exact P835_T1_PartialRunForwardA s integer fraction tail true hne hlen
          (by simpa [hp, hfrac] using hsplit) (by simp) hd hf htail (by simp)
          result hnormal
      · exact P835_T1_PartialRunForwardA s integer [] (b :: bs) false hne hlen
          (by simpa using hsplit) (by simp) hd (by simp) ht
          (by intro _ c cs h; cases h; exact hp) result hnormal
  · intro x tail hsign hvalid hrender htail hguards
    exact P835_T1_PartialRunReverseA s hne hlen result hnormal
      x tail hsign hvalid hrender htail hguards

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (68)
More program dependencies (35)
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 72 entries
Technical checking records
Local closure summary
{
  "node": "P435_T1_PartialLexicalCertificateA",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "42006316f2162975036e96f144b47df90c032f079e97233309d5a0f3a81e0191",
  "active_statement_hash": "bde154fd4f5de4a84004b3d0283f7bae0e63c5bd94eca930e6a62e3c63557825",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-194",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P364_T1_NumberHelperDigitPrefix": "3426b4efc0d98c81",
    "P835_T1_PartialRunForwardA": "67db19ca9c2c1eeb",
    "P835_T1_PartialRunReverseA": "17f2f4dbfdf122ab"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "4da7f295a9b85b50",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "8127b3eaeae00dd2",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:dbf0638acda35fa5abcaff86b2cb8a0e801fa0b518bdaf84803740705a99616c",
  "current_fingerprint": "sound-v2:dbf0638acda35fa5abcaff86b2cb8a0e801fa0b518bdaf84803740705a99616c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}