Definition and explanation
This explanation was written alongside the formalization to describe the statement and its reasoning.
Definition
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
Proof
Requirement: parser totality
Requirement: parser numeric acceptance
Requirement: parser invalid rejection
Requirement: parser nan acceptance
Requirement: parser infinity
Requirement: parser non nan results
Requirement: parser numeric sign
Requirement: parser signed zero
Requirement: parser exact rounding
Requirement: parser selected exponent
Requirement: parser selected magnitude sign
Requirement: dispatch abstract composition
Requirement: dispatch component compliance
Requirement: parser accumulated rounding
Requirement: parser equal target rounding
Requirement: number helper acceptance
Some.Requirement: number helper rejection
None.Requirement: number helper record bounds
Requirement: number helper accumulated value
Requirement: special helper infinity
Requirement: special helper nan
Requirement: special helper rejection
None outside exactly the three unsigned keywords.Requirement: native correct or defer
Some.Requirement: integer correct or defer
i64/u64 inputs and negative-exponent deferral.Requirement: slow accumulated rounding
Requirement: assembly correspondence
Requirement: classification totality
Requirement: classification determinism
Requirement: classification significand digit
Requirement: rounding totality
Requirement: rounding determinism
Requirement: exponent value agreement
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (21)
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:284 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
More program dependencies (10)
- Decimal · dec2flt/decimal.rs:32 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:318 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:67 Program Rust
- FloatExt · traits.rs:168 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (8)
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Add · core/src/ops/arith.rs:76 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
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
- Classical.choice
- Quot.sound
- propext
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": "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"
}