ModelSliceSplitFirst

Lean checked

Definition and explanation

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

Definition

\mathsf{ModelSliceSplitFirst}(s) successfully returns the first element and remaining suffix of s when present and \mathsf{none} when s is empty.

Lean definition

Trellis authored this Lean model for an operation outside the mechanical extraction. Modeling choices explains its behavior and review.

import Aeneas
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: ModelSliceSplitFirst]
def ModelSliceSplitFirst {T : Type}
    (s : Slice T) : Result (Option (T × Slice T)) :=
-- BODY
  match h : s.val with
  | [] => ok none
  | x :: xs => ok (some (x, ⟨xs, by
      have p := s.property
      rw [h] at p
      have p' : 1 + xs.length ≤ Usize.max := by
        simpa [Nat.add_comm] using p
      exact Nat.le_trans (Nat.le_add_left xs.length 1) p'⟩))
end dec2flt_model
Preservation and explanation

Natural-language argument

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.

Preservation argument

Claim

For every Aeneas Slice Std.U8 satisfying SourceValidByteSlice and representing a configured Rust &[u8], this binding returns normally with ok none exactly for the empty slice, and otherwise with ok (some (x, xs)). Here x is the source's first byte and xs its complete ordered tail, which again satisfies SourceValidByteSlice. There is no UTF-8, lexical-validity, A/B, or public-reachability premise. The binding preserves the immutable head/tail observation at every current bound call, including scientific parsing reached through the slow helper.

Proof

The configured domain of SourceValidByteSlice bounds length by \mathtt{isize::MAX}=9223372036854775807 and permits arbitrary bytes, by reference/model-evidence/source-valid-byte-slice.txt. The historical representation and core-body evidence is retained, explicitly as predecessor evidence, in reference/model-evidence/aeneas-slice-observations.txt. The current identities, exact raw declaration and Rust symbol, binding digest, and complete call inventory are independently reconciled in reference/model-evidence/P89_T1_PrimitiveApplicability.txt. The unchanged core body returns None on the empty slice and shared references to precisely the head and tail on a nonempty slice. Aeneas represents slices as complete ordered lists with a \mathtt{Usize.max} length proof and immutable shared borrows as values. Thus ModelSliceSplitFirst's two list cases give the identical option, byte and suffix, with normal return and no memory change.
For x :: xs, the Lean tail constructor is legal because |\mathit{xs}|\leq 1+|\mathit{xs}|=|\mathit{x::xs}| \leq\mathtt{Usize.max}. The source-domain hypothesis also gives |\mathit{xs}|\leq|\mathit{x::xs}|\leq\mathtt{isize::MAX}, so that tail is source-valid. Every current bound call infers T = Std.U8. The calls copy/read the head and use the tail as another immutable slice; none observes reference identity or mutates either returned borrow. The four calls are scientific sign inspection at generated.lean:1734, nineteen-digit scanning at 4094, and point/exponent-marker inspection at 4347,4369, with source counterparts crate/dec2flt/parse.rs:127,65,180,197. Original upstream split observations rewritten to guarded indexing are identified separately in the current evidence, not counted as bound calls.
Here is the shared scientific application, independent of any GOAL conclusion. At parse_scientific, the exact head sets negative precisely when it is -; + or - consumes exactly the returned tail, while any other head retains the original slice. Empty input retains the empty slice and a false flag. This is the exponent's independent sign, not a leading significand sign. The unchanged guarded digit-entry test reads that same post-sign first byte only when it exists. The original upstream/dec2flt/parse.rs:86 uses first; the audited crate/dec2flt/parse.rs:134-137 uses nonemptiness then index zero. Their empty and nonempty observations agree, but neither is an additional current bound first call.
In the unchanged scientific loop, each state sees the same byte at the same count and hence the same digit test and accumulator argument. With T=2^{59}=576460752303423488 (the cutoff shift has count 59<64 and its result fits in i64), the source updates E to 10E+d only when the pre-update E<T. Starting from zero, 0\leq E\leq10T-1 is maintained: an updating state has E\leq T-1 and 0\leq d\leq9, so 10E+d\leq10T-1=5764607523034234879<\mathtt{i64::MAX}; otherwise E is unchanged. The product, byte-to-i64 cast and sum fit, and negating this final nonnegative magnitude fits as well. One update may overshoot T; there is no clamp to T. The count is incremented for every exponent digit even after updates stop. At an increment, \mathit{count}<|s| implies \mathit{count}+1\leq|s|\leq\mathtt{isize::MAX}<\mathtt{Usize.max}. Guarded indexing and the final suffix starting at count are therefore in bounds. The same maximal digit prefix is consumed, and the same first nondigit and all later bytes remain in the residual. A normally returned Some has the same signed accumulator and exact residual; a missing digit, including an empty or sign-only suffix, normally gives None and the same post-sign residual. No lexical acceptance or rounding result is used in this argument.
The current slow chain is parse_long_mantissa:3941 to parse_decimal_seq, whose eight e/E branches at 2084/2094,2156/2166,2224/2234,2281/2292 call this scientific parser, and hence split-first at 1734. Each exponent suffix is an ordered suffix of the original source-valid slice; the claim applies without any A/B or dispatcher-reachability bound. The slow caller ignores the residual only after the call and applies unwrap_or(0) only to the normally returned option: Some e contributes e, while normal None contributes zero. As pinned in the current evidence, Result.bind propagates fail and div; neither becomes zero, a normal None, or a Rust parsing error. This is unwrap_or, not Option Try/residual conversion. The later zero-significand test at 3942 cannot bypass the earlier scientific call.
Finally, hold all other operations and the audited source adaptations fixed. Equal normally returned primitive observations give identical continuation inputs at each call. Induction on any finite execution prefix therefore preserves every subsequent branch and state. A normal value or an outer failure is unchanged, and an infinite execution remains infinite. This contextual argument does not prove termination or correctness of parse_number, parse_long_mantissa, or dispatch, and does not assume an inhabited component package. The following separate applications use only this extensional replacement. Where the original GOAL imposes a bound, write A=3458764513820540928 and B=576460752303421440 bytes; public bounds concern the complete string before leading-sign removal.

Requirement: assembly correspondence

The direct unrestricted biased_fp_to_float subject takes a raw pair, not a slice, and has no transitive bound split call in the current inventory. Its required normal return and cast/shift/OR word equation are unaffected.

Requirement: classification determinism

This mathematical relation concerns all finite byte strings and executes no source primitive. No source-validity or UTF-8 restriction is added.

Requirement: classification significand digit

The mathematical grammar statement executes no split; its unrestricted finite-byte domain and digit obligation are unchanged.

Requirement: classification totality

Classification is mathematical, not a source execution. It retains all finite byte strings, including those longer than a Rust slice, and its existence conclusion is not supplied by this binding.

Requirement: dispatch abstract composition

The source-valid complete-string domain through A and its sign-stripped body are unchanged. The shared claim preserves concrete numeric and slow primitive observations used to interpret components; abstract component operations are not themselves calls to this external. Lexical A and exact-transport B slice bounds remain as stated, while the slow contract retains every source-valid unsigned literal without either bound. Package inhabitability, abstract normal output existence and conditional value/sign conclusions remain obligations.

Requirement: dispatch component compliance

The shared tail bound applies to every reached concrete split and to slow scientific suffixes, not just to completed traces. It preserves primitive observations and any outer outcome at these calls. Lexical normal-return requirements through A, exact transport through B, complete-string reached-call realization through A, unrestricted on-normal slow refinement, and genuinely inhabited compatible-package existence are not assumed or weakened.

Requirement: exponent value agreement

This mathematical comparison uses the unchanged exact and accumulated value definitions, not an executed split. No source length or UTF-8 bound is added to its conditional agreement statement.

Requirement: integer correct or defer

The direct integer tier takes every i64/u64 input and has no split callee. Its on-normal deferral/rounding alternative is unchanged.

Requirement: native correct or defer

The direct native tier takes every Decimal, not a slice, and has no split callee. Ordinary and disguised on-normal alternatives are unaffected.

Requirement: number helper acceptance

For nonempty source-valid unsigned numeric slices through A, the exact splits and shared scientific observation preserve every continuation and outer outcome. The exponent may have its own sign and arbitrarily many digits within A. Normal Some is the GOAL's required conclusion, not a premise of this preservation argument.

Requirement: number helper accumulated value

On source-valid unsigned numeric slices through A, the same significand bytes, independent exponent sign, pre-update fold, complete digit consumption and residual preserve any normally returned record. Thus its many_digits flag and represented value are unaltered; the exact/half-open interval laws for the full significand remain to be established.

Requirement: number helper record bounds

Every nonempty source-valid slice is allowed, with arbitrary byte contents, no UTF-8 condition and no A/B bound. Exact splits preserve any returned record, including its fields; the false-sign and 10^{19} bounds are not assumed. Failure or divergence is not recast as a returned record.

Requirement: number helper rejection

For every nonempty source-valid arbitrary-byte slice through A outside the whole unsigned grammar, the exact scientific residual and consumed length are retained even after numerical updates stop. Trailing malformed bytes therefore remain visible to the unchanged whole-input check. Required normal None, including with overflow checks, is not presumed.

Requirement: parser accumulated rounding

On accepted numeric source strings of complete length through A, exact numeric and slow splits preserve the full-significand bytes, signed bounded exponent, returned word and trace. Failure/divergence behavior is also unchanged; the accepted-result rounding and lexical-sign conclusion is not used here.

Requirement: parser equal target rounding

For accepted numeric complete strings through A, both value interpretations and the common-target premise stay intact. Exact numeric and slow split observations preserve any returned word without deriving the bridge.

Requirement: parser exact rounding

The input is a Rust string with its complete byte length through B, not merely a shortened body. Sign removal only shortens the source-valid helper slice. The shared claim applies to numeric and slow scientific calls, preserving the execution and any accepted word without assuming exact rounding.

Requirement: parser infinity

On every source-valid infinity spelling, numeric split observations are preserved before any special branch. The special helper itself has no split callee. This preserves whichever branches/outcomes occur, without assuming numeric None or the required normal signed-infinity result.

Requirement: parser invalid rejection

For invalid source strings of complete length through A, exact heads, tails and scientific residuals retain all trailing bytes for whole-input validation, including after exponent updates stop. Branches and outer outcomes are unchanged; normal Rust Err without panic remains the conclusion.

Requirement: parser nan acceptance

For every source-valid NaN spelling, any numeric splits preserve their observations; if execution selects the special helper, it receives the same body. Neither that branch nor the required normal NaN acceptance is assumed.

Requirement: parser non nan results

For every source-valid non-NaN input, exact numeric and slow splits preserve branch selection and any successful returned word. The no-spurious-NaN conclusion is not a preservation premise.

Requirement: parser numeric acceptance

For numeric complete strings through A, exact numeric and slow splits preserve all states and outcomes, including checked arithmetic. They do not restrict the independent exponent sign or digit count. Normal Rust Ok without panic is still required, not assumed.

Requirement: parser numeric sign

The dispatcher records the leading lexical sign before these calls. Scientific parsing separately reads the exponent sign, which is retained exactly. Preserving both numeric and slow continuations preserves any successful result word, without presuming its lexical-sign property.

Requirement: parser selected exponent

On successful numeric parses, exact numeric and slow split observations preserve every selected raw pair and trace. No range condition on that pair is used to justify the primitive; the selected-exponent range remains a GOAL.

Requirement: parser selected magnitude sign

On successful numeric parses, exact numeric and slow continuations preserve the selected raw pair and assembled word. A clear sign bit is not assumed.

Requirement: parser signed zero

For accepted numeric zero literals, exact splits preserve all digit/exponent bytes and any returned word, including the slow scientific call before its zero test. Leading lexical-sign application is unchanged; its signed-zero conclusion is not used.

Requirement: parser totality

For every Rust string of complete byte length through A, every reached split returns normally with the same observation and source-valid tail. All remaining branches, outer failures or divergence are preserved. This introduces no primitive failure but does not assume that the complete parser terminates normally; that remains the required totality conclusion.

Requirement: rounding determinism

This mathematical real-number statement executes no split and gains no uniqueness assumption from the binding.

Requirement: rounding totality

This mathematical existence statement executes no split and keeps every nonnegative real in its domain.

Requirement: slow accumulated rounding

For every source-valid unsigned numeric literal, not just public fallback inputs and with no A/B bound, the slow-to-decimal-to-scientific chain in the shared proof contains the exponent split; every such call receives the exact observation proved above. Runs that fail or diverge before that call are also unchanged, since all preceding operations are fixed. No reachability hypothesis is imposed on the input. Its independent sign, pre-update fold with possible one-update overshoot, consumption of every exponent digit, and exact residual are retained. Residual erasure and normal None-to-zero occur only after the call; outer failure/divergence propagates, even for a zero significand. The complete significand and any normally returned raw pair are unchanged. Only such normal results are the diagnostic's subjects; their accumulated-value rounding is not assumed by primitive preservation.

Requirement: special helper infinity

The direct helper has no split callee. Every source-valid arbitrary-byte slice and either separate sign remain allowed, without UTF-8 or A/B restrictions; the required normal signed-infinity option is unaffected.

Requirement: special helper nan

The direct helper has no split callee. Its full arbitrary-byte source-valid domain and either separate sign are unchanged; no normal NaN result is assumed.

Requirement: special helper rejection

The direct helper has no split callee. Its whole-keyword rejection requirement retains every source-valid arbitrary-byte slice and either sign, with no UTF-8 condition. Required normal None is not supplied by this binding.

Download Lean source · Download TeX source

Proof structure

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

Explore this dependency tree

Inspect related source (1)

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
Technical checking records
Local closure summary
{
  "node": "ModelSliceSplitFirst",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f2b66ed1eafca9de7351e962dd2a28ef015b982da6ac255c70d5e9623e05199e",
  "active_statement_hash": "763bf8c37d808420d7fa7e74c84fccbd7ad86fb1abe6b4106e147a95d594e02c",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "d5c04ffa333d9b33b238a527f5beaa2be82e021d3e9c0bbe01b1310280f7f55a",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-68",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "preservation-v1:f05a5cfad8eb1c5c3f09eb3958815c5bfd33ed8638cf924a1d78649befb3f783",
  "current_fingerprint": "preservation-v1:f05a5cfad8eb1c5c3f09eb3958815c5bfd33ed8638cf924a1d78649befb3f783",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}