ModelSliceFirst

Lean checked

Definition and explanation

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

Definition

\mathsf{ModelSliceFirst}(s) successfully returns the first element 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: ModelSliceFirst]
def ModelSliceFirst {T : Type} (s : Slice T) : Result (Option T) :=
-- BODY
  ok s.val.head?
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 for the empty slice and otherwise with ok (some x), where x is the same first byte returned by the source's shared reference. It leaves the complete ordered input unchanged and requires no UTF-8, lexical-validity, A/B, or termination premise.

Proof

The configured arbitrary-byte slice domain and target length bound are SourceValidByteSlice and reference/model-evidence/source-valid-byte-slice.txt. Historical Aeneas representation, borrow translation and Rust-body evidence is retained as predecessor evidence in reference/model-evidence/aeneas-slice-observations.txt. Current applicability, exact signatures and Rust symbols, raw declaration digests, support bindings and the complete generated call inventory are checked in reference/model-evidence/P89_T1_PrimitiveApplicability.txt. The same Aeneas slice representation is a complete ordered list subtype. On [], the Rust body and ModelSliceFirst both return None; on x :: xs, both return the identical head, by shared reference in Rust and as the immutable value x in Aeneas. Both cases return normally, do not change the input, and inspect no length or content condition beyond the empty/head distinction.
The only current generated bound first call is generated.lean:4568, in dec2flt_with_trace, immediately after as_bytes at 4567; its source counterpart is crate/dec2flt/mod.rs:365. Here T = Std.U8 and the head is copied to test + and -; no reference identity, lifetime, or mutation is observed. The fixed dispatcher frame of DispatchFrame retains this same first-byte operation even with abstract helper components, as recorded in the current evidence. On a Rust string, the complete UTF-8 bytes satisfy the slice length predicate of SourceValidByteSlice; on arbitrary source-valid helper slices the primitive claim needs no UTF-8 condition. If a leading sign is consumed, the nonempty case justifies taking the tail, whose length is no greater than the original slice's. The original complete string length is not replaced by this shortened length in any GOAL premise.
Absence from the bound-call inventory is not absence of the original source observation. In particular, upstream/dec2flt/parse.rs:86 uses first in the scientific digit-entry test. Its audited replacement at crate/dec2flt/parse.rs:134-137 first tests nonemptiness and then reads index zero for is_ascii_digit. On an empty post-exponent-sign slice both tests are false and read no byte; on x :: xs both test the same x. Index zero is in bounds because 0<1+|\mathit{xs}|. The current extraction at 1747-1753 therefore implements that upstream first observation without calling this bound external. The distinction also applies transitively through parse_number and through the slow-to-decimal-to-scientific path recorded in the evidence. This binding does not implement or remove their indexed tests; the already audited adaptation remains fixed.
Holding all other operations and adaptations fixed, the binding's exact normally returned option feeds the same dispatcher continuation. The empty branch, leading sign flag, optional one-byte sign removal, sign-only branch and all later helper inputs consequently stay identical. Every finite execution prefix is unchanged; any normal Rust result and trace, outer failure or divergence is preserved. This is extensional primitive preservation, not lexical acceptance, full-parser termination, rounding correctness, or component-package existence. In the applications below the original constants are A=3458764513820540928 and B=576460752303421440 bytes; their public uses always bound the complete Rust string.

Requirement: assembly correspondence

The direct assembly subject takes every unrestricted raw pair and has no transitive bound first call. Its required normal return and cast/shift/OR equation are unchanged.

Requirement: classification determinism

This is a mathematical relation on all finite byte strings and executes no first call. No source-validity or UTF-8 bound is added.

Requirement: classification significand digit

The mathematical grammar statement executes no first call. Its unrestricted domain and significand-digit obligation remain unchanged.

Requirement: classification totality

Classification retains all finite byte strings, including those longer than Rust slices. This source primitive supplies no total-classification premise.

Requirement: dispatch abstract composition

On source-valid complete strings through A, the fixed frame observes exactly the same empty/head option and lexical sign, including with abstract components. Lexical component domains through A, exact transport through B and the full unbounded source-valid slow domain are unchanged. Inhabited-package existence, abstract normal output existence and conditional rounding/sign conclusions remain obligations, not consequences of primitive infallibility alone.

Requirement: dispatch component compliance

The claim applies to each complete source-valid string before any component call and gives the same sign-stripped body to the concrete frame. Complete-string A/B bounds are retained, not transferred to a shorter replacement premise. Required normal realization at every reached A-bounded call, unrestricted on-normal slow refinement and compatible-package existence are not assumed by first-byte preservation.

Requirement: exponent value agreement

This mathematical conditional comparison has no source execution, so its value meanings and unrestricted lexical domain are not altered by first.

Requirement: integer correct or defer

The direct integer tier ranges over every i64/u64 input and has no first callee. Its on-normal alternatives are unaffected.

Requirement: native correct or defer

The direct native tier ranges over every Decimal, including the disguised path, and has no first callee. Its on-normal contract is unchanged.

Requirement: number helper acceptance

The current direct helper and its callees have no call to this bound first external; their upstream scientific first observation is the indexed test distinguished in the shared proof. Thus this binding does not change the nonempty source-valid unsigned-slice domain through A, impose UTF-8 or an exponent digit limit, or assume the required normal Some.

Requirement: number helper accumulated value

The helper's scientific digit-entry observation uses the audited indexed replacement, not this bound first. Its source-valid unsigned slices through A, full-significand accumulated value and returned-record qualifications are unchanged; equality and interval conclusions are not presumed.

Requirement: number helper record bounds

Every nonempty source-valid arbitrary-byte slice is retained, without A/B or UTF-8 restriction. There is no transitive bound first call in the current helper; the original scientific observation uses the indexed replacement. Neither a normal record nor its field bounds are assumed.

Requirement: number helper rejection

The current helper uses the indexed scientific test, not this bound first. Its nonempty arbitrary-byte source-valid domain through A, entire-slice grammar check and required normal None remain unchanged, including malformed tails after exponent updates stop.

Requirement: parser accumulated rounding

For accepted numeric complete strings through A, identical initial empty/head observations preserve lexical sign, the full helper body and all subsequent execution and result words. The accumulated-rounding conclusion is not used.

Requirement: parser equal target rounding

For accepted numeric complete strings through A, the initial byte and all subsequent outcomes are preserved. Both value interpretations and the common-target premise remain as stated, without assuming the bridge.

Requirement: parser exact rounding

The bound is B on the complete source-valid Rust string. Returning its identical first byte preserves optional leading-sign removal and the full remaining body; any accepted word is unchanged without assuming exact rounding.

Requirement: parser infinity

For every source-valid infinity spelling, the initial byte preserves the lexical sign and unchanged unsigned keyword body. All later outcomes are preserved, without assuming normal signed-infinity acceptance or imposing A/B.

Requirement: parser invalid rejection

For invalid complete strings through A, the same empty/head and sign-only branches and helper inputs are retained. The required normal Rust error, rather than failure/divergence, is not a premise of preservation.

Requirement: parser nan acceptance

For every source-valid NaN spelling, the same copied sign byte and unsigned body preserve the execution. The required normal NaN result is not assumed and no A/B bound is added.

Requirement: parser non nan results

For every source-valid non-NaN input, identical initial observations preserve branch selection and any successful word. Whether it is non-NaN remains the separate conclusion.

Requirement: parser numeric acceptance

For numeric complete strings through A, identical initial observations keep the leading sign and all body bytes, including the independently signed exponent. Normal Rust Ok without panic remains required, not presumed.

Requirement: parser numeric sign

For every successful numeric parse, the same copied leading byte preserves the lexical sign flag; it is distinct from the exponent sign tested later. The final word is unchanged, without using the lexical-sign conclusion.

Requirement: parser selected exponent

For successful numeric parses, the same initial observation and helper inputs preserve every selected raw pair and trace. The selected-exponent range is not assumed by this argument.

Requirement: parser selected magnitude sign

For successful numeric parses, the initial observation preserves the selected raw pair and its assembly word. No clear-sign-bit premise is introduced.

Requirement: parser signed zero

For accepted numeric zero literals, the same first byte preserves the lexical sign flag and entire subsequent execution. Any returned word is unchanged; the signed-zero conclusion is not used.

Requirement: parser totality

For every Rust string of complete length through A, first itself returns normally in both cases. Its exact observation preserves every later branch, including empty/sign-only, any outer failure and divergence. This introduces no first-boundary panic but does not prove parser termination or normal output, which remain the GOAL's required conclusion.

Requirement: rounding determinism

This mathematical real-number goal executes no first call and gains no uniqueness assumption from the primitive.

Requirement: rounding totality

This mathematical existence goal executes no first call and retains every nonnegative real.

Requirement: slow accumulated rounding

For every source-valid unsigned numeric literal, without A/B or public reachability restrictions, the slow scientific callee retains the upstream first observation via guarded indexing, not this bound first external. Changing this binding therefore changes no slow execution or normal raw pair. The independent exponent sign, full digit scan and full-significand diagnostic are untouched; no slow termination or on-normal rounding is assumed.

Requirement: special helper infinity

The direct helper and its callees have no first call. Every source-valid arbitrary-byte slice and either separate sign remain allowed, without UTF-8 or A/B restrictions; the normal signed-infinity requirement is unchanged.

Requirement: special helper nan

The direct helper has no first callee. Its complete arbitrary-byte source-valid domain and either separate sign are unchanged, without assuming a normal NaN.

Requirement: special helper rejection

The direct helper has no first callee. Its whole-keyword rejection on every source-valid arbitrary-byte slice and either sign is unchanged, with no UTF-8 condition and no assumed normal None.

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": "ModelSliceFirst",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f38dbcad0a84ab884eec3f16d86eb111712b828a19dccf0bf5974d6d1e02bd18",
  "active_statement_hash": "335139a4afbfb70e58bb0bcb1244b046933cf859037e19598e254e40a3e50024",
  "kernel_axioms": [
    "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:aedbbbd4a7880b1356e415074ee4bd3935090ad3bbe1ef542efe4966b1047b47",
  "current_fingerprint": "preservation-v1:aedbbbd4a7880b1356e415074ee4bd3935090ad3bbe1ef542efe4966b1047b47",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}