Definition and explanation
This explanation was written alongside the formalization to describe the statement and its reasoning.
Definition
u64 succeeds with this exact rounding when the input is at most
2^{53} and reports assertion failure otherwise.Lean definition
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.Binary64Model
import Mathlib.Data.Rat.Defs
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 4096
namespace dec2flt_model
-- [TABLET NODE: Binary64ModelDefault]
def Binary64ModelDefault : Binary64Model :=
-- BODY
let signBit : Nat := 2 ^ 63
let fractionUnit : Nat := 2 ^ 52
let infinityBits : Nat := 2047 * fractionUnit
let quietNanBits : Nat := infinityBits + 2 ^ 51
let word := fun n : Nat => (⟨BitVec.ofNat 64 n⟩ : Std.U64)
let sign := fun w : F64 => w.val / signBit
let magnitude := fun w : F64 => w.val % signBit
let exponent := fun w : F64 => magnitude w / fractionUnit
let fraction := fun w : F64 => magnitude w % fractionUnit
let categoryCode := fun w : F64 =>
if exponent w = 2047 then
if fraction w = 0 then 1 else 0
else if exponent w = 0 then
if fraction w = 0 then 2 else 3
else 4
let category := fun w : F64 =>
match categoryCode w with
| 0 => core.num.FpCategory.Nan
| 1 => core.num.FpCategory.Infinite
| 2 => core.num.FpCategory.Zero
| 3 => core.num.FpCategory.Subnormal
| _ => core.num.FpCategory.Normal
let finiteMagnitudeValue := fun bits : Nat =>
let e := bits / fractionUnit
let m := bits % fractionUnit
if e = 0 then
(m : Rat) / ((2 : Rat) ^ (1074 : Nat))
else if 1075 <= e then
((fractionUnit + m : Nat) : Rat) * ((2 : Rat) ^ (e - 1075))
else
((fractionUnit + m : Nat) : Rat) / ((2 : Rat) ^ (1075 - e))
let roundEvenNat := fun x : Rat =>
let q := x.num.natAbs / x.den
let r := x.num.natAbs % x.den
if x.den < 2 * r ∨ (x.den = 2 * r ∧ q % 2 = 1) then q + 1 else q
let normalExponent := fun x : Rat =>
(List.range 2046).foldl (fun (old : Nat) (i : Nat) =>
let e : Nat := i + 1
if ((2 : Rat) ^ ((e : Int) - 1023)) ≤ x then e else old) 1
let overflowThreshold : Rat :=
((2 : Rat) ^ (1024 : Nat)) - ((2 : Rat) ^ (970 : Nat))
let roundMagnitude := fun x : Rat =>
if overflowThreshold <= x then infinityBits
else if x < ((2 : Rat) ^ (-1022 : Int)) then
roundEvenNat (x * ((2 : Rat) ^ (1074 : Nat)))
else
let e := normalExponent x
let significand := roundEvenNat (x * ((2 : Rat) ^ ((1075 : Int) - (e : Int))))
if significand = 2 ^ 53 then (e + 1) * fractionUnit
else e * fractionUnit + (significand - fractionUnit)
let signedWord := fun negative : Bool => fun mag : Nat =>
word (mag + if negative then signBit else 0)
let negativeResult := fun a b : F64 => decide (sign a != sign b)
let mulImpl := fun a b : F64 =>
let ca := categoryCode a
let cb := categoryCode b
let negResult := negativeResult a b
if ca = 0 ∨ cb = 0 then ok (word quietNanBits)
else if (ca = 1 ∧ cb = 2) ∨ (ca = 2 ∧ cb = 1) then
ok (word quietNanBits)
else if ca = 1 ∨ cb = 1 then
ok (signedWord negResult infinityBits)
else
let x := finiteMagnitudeValue (magnitude a)
let y := finiteMagnitudeValue (magnitude b)
ok (signedWord negResult (roundMagnitude (x * y)))
let divImpl := fun a b : F64 =>
let ca := categoryCode a
let cb := categoryCode b
let negResult := negativeResult a b
if ca = 0 ∨ cb = 0 then ok (word quietNanBits)
else if (ca = 1 ∧ cb = 1) ∨ (ca = 2 ∧ cb = 2) then
ok (word quietNanBits)
else if ca = 1 ∨ cb = 2 then
ok (signedWord negResult infinityBits)
else if cb = 1 ∨ ca = 2 then
ok (signedWord negResult 0)
else
let x := finiteMagnitudeValue (magnitude a)
let y := finiteMagnitudeValue (magnitude b)
ok (signedWord negResult (roundMagnitude (x / y)))
{
clone := fun x => ok x
mantissaDigits := ok 53#u32
nan := ok (word quietNanBits)
infinity := ok (word infinityBits)
negInfinity := ok (word (signBit + infinityBits))
exponentMask := ok (word infinityBits)
mantissaMask := ok (word (fractionUnit - 1))
classify := fun x => ok (category x)
toBits := fun x => ok x
fromBits := fun x => ok x
mul := mulImpl
div := divImpl
neg := fun x => ok ⟨x.bv ^^^ BitVec.ofNat 64 signBit⟩
fromU64 := fun x =>
if x.val <= 2 ^ 53 then
ok (word (roundMagnitude (x.val : Rat)))
else fail .assertionFailure
}
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
from_u64 debug
assertion and its exact cast result on the asserted domain.Proof
word uses
BitVec.ofNat 64, so it takes the low 64 bits exactly. Division and
remainder by 2^{63} split bit 63 from the lower 63 bits. Division and
remainder of that magnitude by 2^{52} then split the eleven exponent bits
from the 52 fraction bits. Consequently exponent field 2047 with zero
fraction is infinity and with nonzero fraction is NaN; exponent zero with zero
fraction is zero and with nonzero fraction is subnormal; every other exponent
is normal. These are exactly the five arms of the pinned source
classify body.clone returns its input word. This is the exact frozen scalar
Clone::clone body, *self.
2. mantissaDigits returns 53, the pinned
f64::MANTISSA_DIGITS declaration.
3. nan returns \mathtt{0x7ff8000000000000}. The retained probe on
the pinned toolchain and target gives exactly that word for
f64::NAN. This is an exact claim about that constant, not about
NaNs produced by arbitrary arithmetic.
4. infinity returns \mathtt{0x7ff0000000000000}, exactly the probed
source constant.
5. negInfinity adds bit 63 to that word and therefore returns
\mathtt{0xfff0000000000000}, exactly the probed negative-infinity
constant.
6. exponentMask is the pinned eleven-bit mask
\mathtt{0x7ff0000000000000}.
7. mantissaMask is 2^{52}-1, namely the pinned mask
\mathtt{0x000fffffffffffff}.
8. By the initial field split, classify's nested tests are exactly
the five source match arms, for every one of the 2^{64} words.
9. toBits is the identity on the raw-word carrier, matching the
source transmutation for every word, including every NaN payload.
10. fromBits is the same identity in the other direction, matching
the inverse source transmutation and preserving every input bit.SIG_TOTAL_BITS to f64::MANTISSA_DIGITS, then derive
SIG_BITS as 53-1=52, EXP_BITS as 64-52-1=11,
EXP_SAT and INFINITE_POWER as 2047,
EXP_BIAS as 1023, and EXP_MIN as -1022. The
Lemire default similarly derives
MAX_MANTISSA_FAST_PATH as 1\ll53=2^{53}. Thus the same
preserved field fixes the precision, exponent, overflow, native-cast guard,
and final-assembly shift used by the frozen generic bodies.finiteMagnitudeValue's three exponent-sign cases.roundEvenNat's disjunction selects the
nearest integer, choosing the even integer on every tie. The r=0 case
returns q unchanged.overflowThreshold. Below
it, exponent 2046 rounds at most to the maximum finite significand. At the
boundary and above it, the pinned Rust round-to-even overflow rule specifies
infinity. Thus the explicit comparison implements the source rule on both
sides and at the midpoint.mul, let N, I, Z, and F denote NaN, infinity, zero, and
finite nonzero. If either operand is N, the exact result class is NaN.
I times Z (in either order) is also NaN. I times I or F is infinity.
Otherwise both operands are finite; the package multiplies their exact
nonnegative rational magnitudes and applies the proved encoder. This last
row includes Z times Z or F and hence returns zero. Every non-NaN row
applies the xor of operand sign bits, so infinity, ordinary results,
underflowed results, and zero all have the Rust-prescribed sign.
12. For div, either NaN operand gives NaN; I divided by I and Z
divided by Z give NaN. I divided by Z or F, and F divided by Z, give
signed infinity. F divided by F uses the exact rational quotient and the
proved encoder. F or Z divided by I, and Z divided by F, give signed
zero. These cases are exhaustive and occur in exactly the order of the
definition, so the denominator reaches rational division only in the
finite-nonzero row. Again every non-NaN row uses the xor sign.can_use_fast_path guard and call body in
reference/model-evidence/binary64-boundary.txt, with the field-2
derivation above, give the ordinary path a from_u64 argument at
most 2^{53} and a table index in 0\ldots22: a negative exponent lies in
-22\ldots-1 and is negated for the index, while a nonnegative exponent is at
most 22. On the disguised path the checked integer product must pass the
explicit \leq2^{53} test before from_u64, and the table index is
exactly 22. Only after deriving those hypotheses from the source guards do
we apply Binary64NativeCallDomain: each cast operand and table word
is finite and non-NaN, every table word is positive and nonzero, and hence an
executed division has a nonzero divisor. Therefore the actual native calls
use only fields 11 and 12's exact rational, signed-zero, or infinity rows.
The support theorem is conditional and is not itself cited as a source
reachability assertion.neg xors bit 63 and leaves all other 63 bits fixed. Rust lists
unary negation as a non-arithmetic bitwise operation that preserves a NaN
payload exactly except for sign, so this agrees on all words, not merely
non-NaNs.
14. Finally, fromU64 tests the exact source debug assertion
v\leq2^{53}. In that branch every integer is exactly representable, and
the proved encoder returns its exact cast word. Above the bound, both the
frozen debug build and the model report assertion failure before a cast.Requirement: parser totality
from_u64
debug assertion. For an ordinary native call, the frozen guard gives the
original mantissa \leq2^{53}; for a disguised call, the checked product must
pass the same bound before the cast. Applying the conditional first clause of
Binary64NativeCallDomain then makes each actual cast succeed. Field
2 fixes both this bound and all precision constants used by the integer, slow,
and assembly routes, whose relevant operations are total at this boundary.
Thus this model introduces no additional panic or divergence into the source
executions quantified by the goal. This application concerns preservation,
not whether other source checked arithmetic makes the positive GOAL true.Requirement: parser numeric acceptance
Requirement: parser invalid rejection
parse_number on the unsigned body, and calls parse_inf_nan
only when parse_number returns None. If the special helper
also returns None, the dispatcher returns Err before any
native call, raw-pair production, from_bits, arithmetic, or negation.
On the two successful branches, fields 3--4 and 13 reproduce the special
constant and conditional negation, while fields 2 and 10--14 reproduce the
numeric boundary operations after dispatch. This establishes only
operation-level preservation along every dispatcher branch; it does not infer
the positive invalid-rejection conclusion from this package model.Requirement: parser nan acceptance
NAN and then conditionally applies
unary negation, as recorded in
reference/model-evidence/binary64-boundary.txt. Field 3 supplies
the pinned NaN word, field 13 changes only its sign bit, and field 8 recognizes
either word as NaN. No arithmetic-NaN bit claim is used.Requirement: parser infinity
INFINITY and conditionally
negates it; it does not select NEG_INFINITY directly. Fields 4 and
13 therefore give exactly the infinity with the lexical sign. The source
route is copied in
reference/model-evidence/binary64-boundary.txt.Requirement: parser non nan results
Requirement: parser numeric sign
from_u64, table from_bits, arithmetic,
and conditional negation in their source order. On the integer and slow
paths, field 2 fixes SIG_BITS, EXP_MIN, and
INFINITE_POWER while producing the raw pair; field 10 reproduces
from_bits on its unrestricted assembled word, and field 13 reproduces
the subsequent conditional sign-bit toggle. Those exact routes are recorded
in reference/model-evidence/binary64-boundary.txt. No field fact
shows that an integer- or slow-selected word already has a clear sign bit; that
is precisely the still-unresolved parser_selected_magnitude_sign
obligation, so it is not used here to conclude the positive numeric-sign GOAL.Requirement: parser signed zero
parser_selected_magnitude_sign. Accordingly this application does
not derive the positive signed-zero GOAL from boundary preservation alone.Requirement: parser exact rounding
compute_float
and parse_long_mantissa; their selected raw pair is assembled by
field 10 and optionally negated by field 13. This covers the boundary
operations on every route while leaving the source parser's positive exactness
claim, including its known counterexamples, unchanged.Requirement: parser selected exponent
BiasedFp. Before
that selection, compute_float and any invoked
parse_long_mantissa execute SIG_BITS,
EXP_MIN, and INFINITE_POWER; field 2 and the exact trait
defaults derive their values 52, -1022, and 2047. Field 10 then
interprets the selected pair's assembled word and field 13 may negate it.
These source bodies are copied in
reference/model-evidence/binary64-boundary.txt, so the model
preserves the constants that can affect the selected exponent without
assuming that the positive range claim holds.Requirement: parser selected magnitude sign
SIG_BITS value 52 before field 10 interprets the OR/shift word;
identity from_bits preserves its sign bit, and later lexical
negation is a separate field-13 operation. This ordering and the executed
constant uses are recorded in
reference/model-evidence/binary64-boundary.txt, so the model does
not assume that the selected magnitude is well formed. In particular, none of
these operation-equivalence facts proves that the selected pre-negation word's
sign bit is clear; that remains exactly the positive GOAL obligation.Requirement: dispatch abstract composition
Requirement: dispatch component compliance
MAX_MANTISSA_FAST_PATH for those guards and supplies
SIG_BITS, EXP_MIN, and INFINITE_POWER to both
the integer and slow pair producers. Field 2's shift value and field 10 cover
final assembly, followed by conditional field 13. Finally, the special
component selects field 3 or 4 for NAN or INFINITY and may
apply field 13, with field 8 preserving the resulting category observation.
Thus the package supplies the operation meanings for native,
integer, slow, assembly, and special components without assuming that the
broader positive compliance theorem is true.Requirement: parser accumulated rounding
Requirement: parser equal target rounding
Requirement: number helper acceptance
parse_number helper returns an optional
Decimal; it has no type parameter or float operation, as recorded in
reference/model-evidence/binary64-boundary.txt. This entire
binary64 package is therefore noninterfering with helper acceptance.Requirement: number helper rejection
parse_number
performs no binary64 constant, conversion, classification, or arithmetic call.
The package cannot affect its None results, without implying that all
source-invalid slices return normally.Requirement: number helper record bounds
Decimal record before any dispatcher
float conversion. Its exact source boundary is recorded in
reference/model-evidence/binary64-boundary.txt; consequently no
field of this package can alter its Boolean, mantissa, or exponent fields.Requirement: number helper accumulated value
parse_number,
whose source boundary uses no float operation; see
reference/model-evidence/binary64-boundary.txt. Binary64
rounding occurs only after the helper returns, so this package is genuinely
noninterfering with the stated helper value relation.Requirement: special helper infinity
INFINITY and conditionally negates it.
Fields 4 and 13 reproduce those exact calls and bits for either sign argument;
the source excerpt is in
reference/model-evidence/binary64-boundary.txt.Requirement: special helper nan
NAN constant and conditionally negates
it. Fields 3, 13, and 8 ensure either returned word is classified NaN. This
uses the exact bitwise NaN rules, not an assertion about arithmetic NaN bits;
see reference/model-evidence/binary64-boundary.txt.Requirement: special helper rejection
None from its unmatched branch before selecting a
float constant or invoking negation. The exact match and return structure is
in reference/model-evidence/binary64-boundary.txt. Thus no field
of this package is invoked on that branch; this operation-level fact does not
itself characterize which byte slices reach the unmatched branch.Requirement: native correct or defer
MAX_MANTISSA_FAST_PATH as 2^{53}. On the ordinary path, the
guard bounds the original mantissa by that value and bounds the negated or
nonnegative exponent table index by 22. On the disguised path, checked
integer multiplication occurs first, the resulting mantissa must pass the
2^{53} comparison, and the table index is exactly 22. Applying the two
conditional clauses of Binary64NativeCallDomain after these source
derivations gives a successful finite cast, a finite nonzero table word, and
hence a nonzero divisor. Fields 14 and 10 then reproduce the cast and table
from_bits; fields 11 or 12 reproduce multiplication or division;
and field 13 reproduces the final optional negation. The exact guards and
calls are in reference/model-evidence/binary64-boundary.txt.Requirement: integer correct or defer
compute_float operation produces a raw
BiasedFp; it does not call from_u64, multiplication,
division, or negation, but it does execute SIG_BITS,
EXP_MIN, and INFINITE_POWER while computing that pair.
Field 2 plus the exact trait defaults give these constants as 52, -1022,
and 2047. If the pair is later assembled, the field-2-derived shift 52
forms its word and identity field 10 preserves the unrestricted result. The
exact body is recorded in
reference/model-evidence/binary64-boundary.txt; no false native
cast-domain claim is used for this GOAL.Requirement: slow accumulated rounding
parse_long_mantissa body uses
INFINITE_POWER, EXP_MIN, and SIG_BITS in its
overflow tests, scaling, rounding, and returned pair. Field 2 and the trait
defaults fix them as 2047, -1022, and 52. Final assembly uses the same
derived shift, then invokes field 10 on the unrestricted word and field 13 for
the conditional sign-bit toggle. These operations are copied in
reference/model-evidence/binary64-boundary.txt; this application
preserves their meanings without assuming a clear pre-negation sign bit or the
positive rounding conclusion.Requirement: assembly correspondence
F::SIG_BITS, ORs it with the mantissa, and passes the low-64-bit word
to from_bits. Field 2, SIG_TOTAL_BITS, and the exact
trait default derive this shift as 52; field 10 is the identity on every
word, with no field-validity precondition. The exact body in
reference/model-evidence/binary64-boundary.txt therefore agrees
with the goal's unrestricted Rust cast/shift/OR operation for all field values.Requirement: classification totality
Requirement: classification determinism
Requirement: classification significand digit
Requirement: rounding totality
Real. Neither that relation nor the principal theorem statement
calls this package's rational encoder. The model computation is
therefore noninterfering with the full real domain; the rational proof above is
not substituted for the GOAL.Requirement: rounding determinism
Requirement: exponent value agreement
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Used by
- Binary64ApplySign
- Binary64ExactPositiveDivRounds
- Binary64ExactPositiveMulRounds
- Binary64FromU64Exact
- Binary64NormalEncoderRounds
- Binary64Pow10FastPathExact
All 27 entries
- Binary64ApplySign
- Binary64ExactPositiveDivRounds
- Binary64ExactPositiveMulRounds
- Binary64FromU64Exact
- Binary64NormalEncoderRounds
- Binary64Pow10FastPathExact
- Binary64ZeroDivRounds
- Binary64ZeroMulRounds
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- NativeCorrectOrDefer
- ParserExactRoundingFastPath
- ParserExactRoundingWitness
- ParserExactRounding Refutation
- ParserSignedZero
Inspect related source (1)
- FpCategory · core/src/num/mod.rs:1522 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": "Binary64ModelDefault",
"closure_version": "patch_c_v1",
"active_decl_hash": "03ae48fb631e6242bd21bf95d0481b66acae05f8cab343c7ab279b3c116538a3",
"active_statement_hash": "646e60050e85c5587e7ae1ac08e9779d603b648cb98d6549fea7489a2c07c53d",
"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-15",
"boundary_theorems": {},
"strict_theorem_deps": {},
"strict_definition_deps": {
"Binary64Model": "c43614ff2149ecf2",
"F64": "ec4e25fbaf4e11d4",
"core_num_FpCategory": "f500de642a5d5148"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "preservation-v1:509a3c9fe29f53bdecca0d3d8aa3fc464c68ada9690e16b24f661c262782548e",
"current_fingerprint": "preservation-v1:509a3c9fe29f53bdecca0d3d8aa3fc464c68ada9690e16b24f661c262782548e",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}