DispatchComponentContract

Lean checked

Definition and explanation

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

Definition

A dispatch component contract consists of lexical-number, lexical-special, native-shortcut, integer-conversion, slow-conversion, raw-assembly, and traced-dispatch operations of the extracted binary64 types. The lexical operations accept exactly their unsigned grammars, return bounded decimal records, preserve their accumulated values, and preserve the same binary64 rounding targets for the exact and accumulated values, including when the source's bounded exponent differs from the mathematical exponent. The special operation handles either separate sign. The native operation either defers or returns the correctly signed exact record value and never accepts a many-digit record. The integer operation either returns a negative biased exponent or an exact nonnegative rounding; the slow operation rounds the unsigned literal's full accumulated value; assembly uses the Rust cast/shift/OR word.
The dispatcher returns normally for every string. Its trace obeys the following branch laws. Empty and sign-only inputs return errors without a helper call. Every other trace records the nonempty body obtained by removing at most one leading sign and records whether that sign was minus. The invalid branch records None from both lexical helpers and returns an error. The special branch records numeric rejection and the value returned by the special helper. The native branch records a numeric record with its lexical sign installed and the Some value returned by the native shortcut. An assembly trace records numeric acceptance and native deferral, calls the integer operation first on the parsed exponent and mantissa, and calls it on the incremented mantissa exactly when the record has many digits and the first pair did not defer. Equality of those two pairs retains the first pair; inequality forces biased exponent -1. A negative post-comparison exponent calls the slow operation and selects its replacement, while a nonnegative one selects the post-comparison pair. The selected pair is passed to assembly, the recorded assembly word is that result, and the returned value records the lexical-sign application; when the assembled word has a clear sign bit this application preserves its magnitude bits and sets precisely the recorded sign.

Lean definition

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

import Tablet.Binary64MagnitudeTarget
import Tablet.DecimalLiteral
import Tablet.SpecialLiteral
import Tablet.num_float_parse_ParseFloatError
import Tablet.num_imp_dec2flt_Dec2FltTrace
import Tablet.num_imp_dec2flt_common_BiasedFp
import Tablet.num_imp_dec2flt_decimal_Decimal

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DispatchComponentContract]
structure DispatchComponentContract where
-- BODY
  parseNumber :
    Slice Std.U8 → Result (Option num.imp.dec2flt.decimal.Decimal)
  parseSpecial : Slice Std.U8 → Bool → Result (Option F64)
  native : num.imp.dec2flt.decimal.Decimal → Result (Option F64)
  integer : Std.I64 → Std.U64 →
    Result num.imp.dec2flt.common.BiasedFp
  slow : Slice Std.U8 → Result num.imp.dec2flt.common.BiasedFp
  assemble : num.imp.dec2flt.common.BiasedFp → Result F64
  dispatch : Str → Result ((core.result.Result F64
    num.float_parse.ParseFloatError) × num.imp.dec2flt.Dec2FltTrace F64)
  numeric_acceptance :
    ∀ (s : Slice Std.U8) (n : DecimalLiteral),
      n.bytes = s.val → n.sign = none → s.val ≠ [] →
      ∃ d, parseNumber s = .ok (some d)
  numeric_rejection :
    ∀ (s : Slice Std.U8), s.val ≠ [] →
      (¬ ∃ n : DecimalLiteral, n.bytes = s.val ∧ n.sign = none) →
      parseNumber s = .ok none
  numeric_record :
    ∀ (s : Slice Std.U8) (d : num.imp.dec2flt.decimal.Decimal),
      s.val ≠ [] → parseNumber s = .ok (some d) →
      d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧
      ∃ n : DecimalLiteral, n.bytes = s.val ∧ n.sign = none ∧
        (d.many_digits = false →
          n.accumulatedValue = (d.mantissa.val : Real) * 10 ^ d.exponent.val) ∧
        (d.many_digits = true →
          (d.mantissa.val : Real) * 10 ^ d.exponent.val ≤
            n.accumulatedValue ∧
          n.accumulatedValue < ((d.mantissa.val + 1 : Nat) : Real) *
            10 ^ d.exponent.val)
  numeric_target_preservation :
    ∀ (s : Slice Std.U8) (d : num.imp.dec2flt.decimal.Decimal)
      (n : DecimalLiteral),
      n.bytes = s.val → n.sign = none →
      parseNumber s = .ok (some d) →
      ∀ bits : Nat,
        Binary64MagnitudeTarget |n.exactValue| bits ↔
        Binary64MagnitudeTarget |n.accumulatedValue| bits
  special_contract :
    ∀ (s : Slice Std.U8) (negative : Bool),
      ((∃ k : SpecialLiteral,
          k.bytes = s.val ∧ k.sign = none ∧
          k.isNan = false) →
        ∃ f, parseSpecial s negative = .ok (some f) ∧
          f.val % 2 ^ 63 = 2047 * 2 ^ 52 ∧
          f.val / 2 ^ 63 = if negative then 1 else 0) ∧
      ((∃ k : SpecialLiteral,
          k.bytes = s.val ∧ k.sign = none ∧
          k.isNan = true) →
        ∃ f, parseSpecial s negative = .ok (some f) ∧
          f.val % 2 ^ 63 / 2 ^ 52 = 2047 ∧
          f.val % 2 ^ 52 ≠ 0) ∧
      ((¬ ∃ k : SpecialLiteral, k.bytes = s.val ∧ k.sign = none) →
        parseSpecial s negative = .ok none)
  native_contract :
    ∀ (d : num.imp.dec2flt.decimal.Decimal) (o : Option F64),
      native d = .ok o →
      o = none ∨ ∃ f, o = some f ∧ d.many_digits = false ∧
        Binary64MagnitudeTarget
          ((d.mantissa.val : Real) * 10 ^ d.exponent.val)
          (f.val % 2 ^ 63) ∧
        f.val / 2 ^ 63 = if d.negative then 1 else 0
  integer_contract :
    ∀ (q : Std.I64) (w : Std.U64)
      (fp : num.imp.dec2flt.common.BiasedFp),
      integer q w = .ok fp → fp.p_biased.val < 0 ∨
        Binary64MagnitudeTarget
          ((w.val : Real) * 10 ^ q.val)
          (fp.m.bv ||| (fp.p_biased.bv.signExtend 64 <<< 52)).toNat
  slow_contract :
    ∀ (s : Slice Std.U8) (n : DecimalLiteral)
      (fp : num.imp.dec2flt.common.BiasedFp),
      n.bytes = s.val → n.sign = none → slow s = .ok fp →
      Binary64MagnitudeTarget |n.accumulatedValue|
        (fp.m.bv ||| (fp.p_biased.bv.signExtend 64 <<< 52)).toNat
  assembly_contract :
    ∀ fp : num.imp.dec2flt.common.BiasedFp,
      assemble fp = .ok
        (⟨fp.m.bv ||| (fp.p_biased.bv.signExtend 64 <<< 52)⟩ : F64)
  dispatch_total :
    ∀ s : Str, ∃ (r : core.result.Result F64
      num.float_parse.ParseFloatError) (trace : num.imp.dec2flt.Dec2FltTrace F64),
      dispatch s = .ok (r, trace)
  empty_branch :
    ∀ (s : Str) (r : core.result.Result F64
      num.float_parse.ParseFloatError),
      dispatch s = .ok (r, .EmptyInput) →
      s.val = [] ∧ ∃ e, r = .Err e
  sign_only_branch :
    ∀ (s : Str) (r : core.result.Result F64
      num.float_parse.ParseFloatError) (body : Slice Std.U8) (negative : Bool),
      dispatch s = .ok (r, .SignOnly body negative) →
      body.val = [] ∧
      ((s.val = 45#u8 :: body.val ∧ negative = true) ∨
       (s.val = 43#u8 :: body.val ∧ negative = false)) ∧
      ∃ e, r = .Err e
  invalid_branch :
    ∀ (s : Str) (r : core.result.Result F64
      num.float_parse.ParseFloatError) (body : Slice Std.U8) (negative : Bool)
      (numberResult : Option num.imp.dec2flt.decimal.Decimal)
      (specialResult : Option F64),
      dispatch s = .ok (r,
        .Invalid body negative numberResult specialResult) →
      body.val ≠ [] ∧
      ((s.val = body.val ∧ negative = false) ∨
       (s.val = 45#u8 :: body.val ∧ negative = true) ∨
       (s.val = 43#u8 :: body.val ∧ negative = false)) ∧
      parseNumber body = .ok numberResult ∧ numberResult = none ∧
      parseSpecial body negative = .ok specialResult ∧
      specialResult = none ∧ ∃ e, r = .Err e
  special_branch :
    ∀ (s : Str) (r : core.result.Result F64
      num.float_parse.ParseFloatError) (body : Slice Std.U8) (negative : Bool)
      (numberResult : Option num.imp.dec2flt.decimal.Decimal)
      (specialResult : Option F64) (value : F64),
      dispatch s = .ok (r,
        .Special body negative numberResult specialResult value) →
      body.val ≠ [] ∧
      ((s.val = body.val ∧ negative = false) ∨
       (s.val = 45#u8 :: body.val ∧ negative = true) ∨
       (s.val = 43#u8 :: body.val ∧ negative = false)) ∧
      parseNumber body = .ok numberResult ∧ numberResult = none ∧
      parseSpecial body negative = .ok specialResult ∧
      specialResult = some value ∧ r = .Ok value
  native_branch :
    ∀ (s : Str) (r : core.result.Result F64
      num.float_parse.ParseFloatError) (body : Slice Std.U8) (negative : Bool)
      (numberResult : Option num.imp.dec2flt.decimal.Decimal)
      (fastInput : num.imp.dec2flt.decimal.Decimal)
      (fastResult : Option F64) (value : F64),
      dispatch s = .ok (r,
        .FastPath body negative numberResult fastInput fastResult value) →
      body.val ≠ [] ∧
      ((s.val = body.val ∧ negative = false) ∨
       (s.val = 45#u8 :: body.val ∧ negative = true) ∨
       (s.val = 43#u8 :: body.val ∧ negative = false)) ∧
      parseNumber body = .ok numberResult ∧
      (∃ d, numberResult = some d ∧
        fastInput = { d with negative := negative }) ∧
      native fastInput = .ok fastResult ∧
      fastResult = some value ∧ r = .Ok value
  assembled_branch :
    ∀ (s : Str) (r : core.result.Result F64
      num.float_parse.ParseFloatError)
      (a : num.imp.dec2flt.Dec2FltAssemblyTrace F64),
      dispatch s = .ok (r, .Assembled a) →
      a.body.val ≠ [] ∧
      ((s.val = a.body.val ∧ a.negative = false) ∨
       (s.val = 45#u8 :: a.body.val ∧ a.negative = true) ∨
       (s.val = 43#u8 :: a.body.val ∧ a.negative = false)) ∧
      parseNumber a.body = .ok a.parse_number_result ∧
      ∃ d,
        a.parse_number_result = some d ∧
        a.fast_path_input = { d with negative := a.negative } ∧
        native a.fast_path_input = .ok a.fast_path_result ∧
        a.fast_path_result = none ∧
        a.first_compute_exponent = d.exponent ∧
        a.first_compute_mantissa = d.mantissa ∧
        integer a.first_compute_exponent a.first_compute_mantissa =
          .ok a.first_compute_result ∧
        (a.second_compute_guard = true ↔
          d.many_digits = true ∧ 0 ≤ a.first_compute_result.p_biased.val) ∧
        (a.second_compute_guard = false →
          a.second_compute_exponent = none ∧
          a.second_compute_mantissa = none ∧
          a.second_compute_result = none ∧
          a.second_equals_first = none ∧
          a.forced_deferral = false ∧
          a.post_comparison_pair = a.first_compute_result) ∧
        (a.second_compute_guard = true →
          ∃ (w : Std.U64) (second : num.imp.dec2flt.common.BiasedFp),
            w.val = d.mantissa.val + 1 ∧
            a.second_compute_exponent = some d.exponent ∧
            a.second_compute_mantissa = some w ∧
            integer d.exponent w = .ok second ∧
            a.second_compute_result = some second ∧
            ((a.second_equals_first = some true ∧
              second = a.first_compute_result ∧
              a.forced_deferral = false ∧
              a.post_comparison_pair = a.first_compute_result) ∨
             (a.second_equals_first = some false ∧
              second ≠ a.first_compute_result ∧
              a.forced_deferral = true ∧
              a.post_comparison_pair.m = a.first_compute_result.m ∧
              a.post_comparison_pair.p_biased = (-1)#i32))) ∧
        (a.slow_path_guard = true ↔
          a.post_comparison_pair.p_biased.val < 0) ∧
        (a.slow_path_guard = false →
          a.slow_path_result = none ∧
          a.selected_pair = a.post_comparison_pair) ∧
        (a.slow_path_guard = true →
          ∃ replacement, slow a.body = .ok replacement ∧
            a.slow_path_result = some replacement ∧
            a.selected_pair = replacement) ∧
        assemble a.selected_pair = .ok a.assembly_result ∧
        a.assembled_word = a.assembly_result ∧
        a.lexical_sign_applied = a.negative ∧
        (a.assembly_result.val < 2 ^ 63 →
          a.result.val % 2 ^ 63 = a.assembly_result.val ∧
          a.result.val / 2 ^ 63 =
            if a.lexical_sign_applied then 1 else 0) ∧
        r = .Ok a.result

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

This record states, without supplying an alternate implementation, the lexical, conversion, and operational branch obligations used by the abstract dispatcher argument, including the native, integer, many-digit, slow, sign, and assembly boundaries.

Proof

Each operation field has the type of the corresponding extracted declaration. The totality law rules out vacuous implementations that fail in the outer model, while the six constructor laws distinguish outer normal return, inner Rust success/error, and optional defer/reject. They follow the source dispatcher in order: sign stripping, numeric then special classification, native attempt, first integer attempt, guarded incremented-mantissa attempt, equality or forced deferral, slow fallback, selected-pair assembly, and lexical sign application. The trace fields are observations of those already-computed values, rather than an alternate conversion. The lexical target-preservation law is the explicit component obligation needed to connect the bounded exponent diagnostic to the public exact-value target. The source operations and trace fields supporting these boundaries are recorded in reference/model-evidence/decimal-specification.txt. No function body or end-to-end dispatcher conclusion is postulated by the definition; inhabitation, source compliance, and composition remain proof-bearing claims.

Requirement: parser totality

The totality law supplies a normal traced result for every string.

Requirement: parser numeric acceptance

Numeric helper acceptance excludes the error and special branches, leaving native or assembled success.

Requirement: parser invalid rejection

Lexical rejection selects the empty, sign-only, or invalid error branch.

Requirement: parser nan acceptance

The special branch returns exactly the special helper's NaN value.

Requirement: parser infinity

The special branch returns exactly the helper's signed infinity.

Requirement: parser non nan results

Numeric component targets exclude NaNs, while special helper classification identifies NaN inputs.

Requirement: parser numeric sign

The native contract and final assembly sign application both use the stripped lexical sign.

Requirement: parser signed zero

Magnitude rounding and the separate final sign application retain both signed zeros.

Requirement: parser exact rounding

Lexical target preservation connects exact value to the native, integer, or slow component target.

Requirement: parser selected exponent

The selected integer or slow pair has a target word, from which the exponent bound is derived.

Requirement: parser selected magnitude sign

The selected pair's target word and assembly correspondence imply a clear sign bit.

Requirement: dispatch abstract composition

The final consequence must be derived by exhausting these operational branches and applying their component contracts.

Requirement: dispatch component compliance

Equality of every operation with its extracted declaration makes all branch and helper-call laws obligations about the actual source.

Requirement: parser accumulated rounding

The lexical and slow laws retain accumulated value separately from the public exact target.

Requirement: parser equal target rounding

The record retains both values and the lexical preservation law supplies their common target.

Requirement: number helper acceptance

The lexical-number law preserves the nonempty unsigned domain and Some.

Requirement: number helper rejection

The lexical-number law preserves the nonempty complement and None.

Requirement: number helper record bounds

The record law states false negativity and the strict 10^{19} bound.

Requirement: number helper accumulated value

The record law states both exact and half-open many-digit cases.

Requirement: special helper infinity

The special law quantifies both separate sign values and both unsigned infinity spellings.

Requirement: special helper nan

The special law quantifies both separate sign values for the unsigned NaN keyword.

Requirement: special helper rejection

The special law returns None outside exactly the three unsigned keywords.

Requirement: native correct or defer

The native law covers ordinary and disguised cases uniformly and excludes many digits on Some.

Requirement: integer correct or defer

The integer law retains all i64/u64 inputs and negative-exponent deferral.

Requirement: slow accumulated rounding

The slow law uses the unsigned full-significand accumulated value.

Requirement: assembly correspondence

The assembly law uses the same unrestricted Rust cast/shift/OR word.

Requirement: classification totality

The lexical domains are the numeric and special classification arms.

Requirement: classification determinism

The contract reuses the unique declarative lexical witnesses rather than adding a parser.

Requirement: classification significand digit

The numeric domain is witnessed by a digit-bearing decimal literal.

Requirement: rounding totality

The contract refers to, but does not strengthen, magnitude-target existence.

Requirement: rounding determinism

The contract refers to, but does not strengthen, magnitude-target uniqueness.

Requirement: exponent value agreement

The separate exact and accumulated laws preserve the premise needed for agreement.

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 (21)
More program dependencies (10)
Standard-library dependencies (8)

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 11 entries
Technical checking records
Local closure summary
{
  "node": "DispatchComponentContract",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "7445b48003cf0a64d879501d68ae1d3ce954d5da09e9305ac7280f779652c389",
  "active_statement_hash": "0dfde7919949ac29fa7cbecf86ab39006ff2cc5abc3e5dd768b689a482d6a328",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "b3d2e5a7a57ad9d2abdfb1c60bd76050a5cafa6a2be969c219d3ae71b2a8ade5",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-4",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "Binary64MagnitudeTarget": "9d32ddb247d9dd24",
    "DecimalLiteral": "5fe97b3b5621e328",
    "F64": "ec4e25fbaf4e11d4",
    "SpecialLiteral": "c43614ff2149ecf2",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "2a4d2e4074960bd4",
    "num_imp_dec2flt_Dec2FltTrace": "1cacb7f8b1927ad5",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_Decimal": "b702e549017701b8"
  }
}
Prose assessment
{
  "label": "Prose review has no verdict in this snapshot",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "preservation-v1:a89ef7b40e5ca3a19c535a259e305c37ed6a4233588b23ec5a749cb8994d089a",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}