AssemblyCorrespondence

Lean checked

Statement

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

Theorem

For every unrestricted BiasedFp, biased_fp_to_float returns normally with a raw f64 word equal to its mantissa bitwise-OR the Rust-semantics i32-to-u64 cast of its biased exponent shifted left by 52; this is exactly the raw-pair word interpretation used by the other obligations, with no well-formedness hypothesis.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64_from_u64_bits
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.ModelF64FromBits
import Tablet.ModelF64MantissaDigits
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_common_BiasedFp
import Tablet.num_imp_traits_Float_SIG_BITS_default

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: AssemblyCorrespondence]
theorem AssemblyCorrespondence :
    ∀ fp : num.imp.dec2flt.common.BiasedFp, ∃ f : F64,
      num.imp.dec2flt.biased_fp_to_float
        F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64 fp = ok f ∧
      DecimalGoalVocabularyDefault.assembledWord fp f := by
Proof

Natural-language proof

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.

Proof

Fix an arbitrary BiasedFp value fp. By num imp dec2flt common BiasedFp, its two fields are precisely an unrestricted 64-bit unsigned scalar fp.m and an unrestricted 32-bit signed scalar fp.p\_biased; in particular, we impose no exponent range, mantissa mask, or nonoverlap hypothesis. Write
p=fp.p\_biased.val\in[-2^{31},2^{31}-1] \quad\hbox{and}\quad q=(p\mathbin{\mathrm{emod}}2^{64}).\mathit{toNat}.
We evaluate the extracted program in num imp dec2flt biased fp to float one bind at a time.
Its first operation is lift (IScalar.hcast .U64 fp.p_biased). The pinned Aeneas scalar semantics in the Preamble define this widening signed-to-unsigned cast by sign-extending the source bit vector from 32 to 64 bits. This hcast is a total pure constructor, not a checked operation, and lift is definitionally the successful Result.ok injection. Thus the first bind cannot fail. Since 32\leq64, sign extension retains all source bits and adds rather than truncates bits. If p\geq0, it leaves the numeric value p, so the resulting U64 has unsigned value p=q. If p<0, the sign-extended two's-complement word has unsigned value 2^{64}+p; Euclidean remainder gives p\mathbin{\mathrm{emod}}2^{64}=2^{64}+p, so its value is again q. Thus the same formula q covers both signs, including every negative or otherwise assembly-ill-formed exponent, and the first bind produces a U64 scalar c with c.val=q.
Next we determine the shift count. Unfolding the concrete FloatExt instance F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 selects as its FloatInst the instance F64 Insts Dec2flt modelNumImpTraitsFloatU64. That instance defines SIG_BITS by num imp traits Float SIG BITS default. The default first binds SIG_TOTAL_BITS; the concrete field is F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS, which in turn is the source f64::MANTISSA_DIGITS binding ModelF64MantissaDigits. The latter returns the U32 value 53. Hence this bind succeeds. The remaining default operation is the checked U32 subtraction 53-1. Since 1\leq53 and both operands and the result are in [0,2^{32}-1], it has no underflow and returns the U32 value 52. Consequently the extracted SIG_BITS bind returns 52.
The next extracted bind computes c\mathbin{\texttt{<<<}}52. By ModelU64Shl, a U64 left shift succeeds exactly when the full U32 count is below 64. Here 52<64, so this bind returns a U64 scalar s. The same cited semantics identify its unsigned value as mathematical left shift with a 64-bit result, namely
s.val=(q\,2^{52})\bmod 2^{64} =\bigl((p\mathbin{\mathrm{emod}}2^{64}).\mathit{toNat}\,2^{52}\bigr) \bmod 2^{64}.
This reduction modulo 2^{64} is essential: it discards every bit shifted above bit 63. Thus the calculation is valid without assuming that p is nonnegative or that its shifted representation fits without truncation.
The following operation is lift (fp.m ||| s). By ModelU64BitOr, U64 bitwise OR has no failure case and returns the unique 64-bit word whose bits are the pointwise disjunction of the operand bits. Its unsigned observation is therefore exactly
w.val=\operatorname{Nat.lor}\! \left(fp.m.val, \bigl((p\mathbin{\mathrm{emod}}2^{64}).\mathit{toNat}\,2^{52}\bigr) \bmod2^{64}\right).
The surrounding lift consequently succeeds and the fourth bind produces this word w.
It remains to evaluate the final method call. The concrete FloatExt instance cited above chooses exactly F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 from u64 bits for from_u64_bits. Unfolding that extracted wrapper leaves one monadic call to core.f64.F64.from_bits. The bound operation is ModelF64FromBits, which succeeds on every U64 word and returns the F64 carrier having exactly the same raw 64 bits. Let f be that returned carrier. The final call therefore returns ok f, and f.val=w.val.
Finally unfold the assembledWord field of DecimalGoalVocabularyDefault. For this same unrestricted fp and f, it asks literally for
f.val=\operatorname{Nat.lor}\! \left(fp.m.val, \bigl((fp.p\_biased.val\mathbin{\mathrm{emod}}2^{64}).\mathit{toNat} \,2^{52}\bigr)\bmod2^{64}\right).
This is the equality for w.val=f.val obtained above. Choosing the returned carrier f as the existential witness establishes both normal return and the required assembled-word relation. Since fp was arbitrary and no field invariant was used, the conclusion holds for every unrestricted BiasedFp.

Lean proof


  intro fp
  let shifted : Std.U64 :=
    ⟨BitVec.shiftLeft (BitVec.signExtend UScalarTy.U64.numBits fp.p_biased.bv) 52⟩
  let word : Std.U64 := fp.m ||| shifted
  refine ⟨word, ?_, ?_⟩
  · simp only [word, shifted, num.imp.dec2flt.biased_fp_to_float,
      F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.from_u64_bits,
      num.imp.traits.Float.SIG_BITS.default,
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS,
      core.f64.F64.MANTISSA_DIGITS, ModelF64MantissaDigits,
      ModelU64Shl, ModelU64BitOr, ModelF64FromBits,
      core.f64.F64.from_bits, Binary64ModelDefault,
      lift, HShiftLeft.hShiftLeft, UScalar.shiftLeft_UScalar,
      UScalar.shiftLeft, IScalar.hcast, HSub.hSub, UScalar.sub,
      UScalar.val, IScalar.val]
    have arithmetic : Sub.sub 53 1 = 52 := by decide
    have count : (52#u32).val = 52 := by decide
    have directCount :
        (UScalar.mk (BitVec.ofNat 32 52) : Std.U32).val = 52 := by
      simp [UScalar.val, BitVec.toNat_ofNat]
    simp [UScalar.sub, UScalar.shiftLeft, arithmetic, count,
      directCount, BitVec.toNat_ofNat, UScalarTy.numBits]
  · simp only [word, shifted, DecimalGoalVocabularyDefault]
    change
      (fp.m.bv ||| (BitVec.signExtend UScalarTy.U64.numBits fp.p_biased.bv).shiftLeft 52).toNat =
        Nat.lor fp.m.bv.toNat
          (((fp.p_biased.bv.toInt.emod (2 ^ 64)).toNat * 2 ^ 52) % 2 ^ 64)
    simp only [BitVec.toNat_or, BitVec.shiftLeft, BitVec.toNat_ofNat,
      BitVec.signExtend, BitVec.toNat_ofInt, Nat.shiftLeft_eq,
      UScalarTy.numBits]
    rfl

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64_from_u64_bits
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.ModelF64FromBits
import Tablet.ModelF64MantissaDigits
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_common_BiasedFp
import Tablet.num_imp_traits_Float_SIG_BITS_default

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: AssemblyCorrespondence]
theorem AssemblyCorrespondence :
    ∀ fp : num.imp.dec2flt.common.BiasedFp, ∃ f : F64,
      num.imp.dec2flt.biased_fp_to_float
        F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64 fp = ok f ∧
      DecimalGoalVocabularyDefault.assembledWord fp f := by
-- BODY
  intro fp
  let shifted : Std.U64 :=
    ⟨BitVec.shiftLeft (BitVec.signExtend UScalarTy.U64.numBits fp.p_biased.bv) 52⟩
  let word : Std.U64 := fp.m ||| shifted
  refine ⟨word, ?_, ?_⟩
  · simp only [word, shifted, num.imp.dec2flt.biased_fp_to_float,
      F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.from_u64_bits,
      num.imp.traits.Float.SIG_BITS.default,
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS,
      core.f64.F64.MANTISSA_DIGITS, ModelF64MantissaDigits,
      ModelU64Shl, ModelU64BitOr, ModelF64FromBits,
      core.f64.F64.from_bits, Binary64ModelDefault,
      lift, HShiftLeft.hShiftLeft, UScalar.shiftLeft_UScalar,
      UScalar.shiftLeft, IScalar.hcast, HSub.hSub, UScalar.sub,
      UScalar.val, IScalar.val]
    have arithmetic : Sub.sub 53 1 = 52 := by decide
    have count : (52#u32).val = 52 := by decide
    have directCount :
        (UScalar.mk (BitVec.ofNat 32 52) : Std.U32).val = 52 := by
      simp [UScalar.val, BitVec.toNat_ofNat]
    simp [UScalar.sub, UScalar.shiftLeft, arithmetic, count,
      directCount, BitVec.toNat_ofNat, UScalarTy.numBits]
  · simp only [word, shifted, DecimalGoalVocabularyDefault]
    change
      (fp.m.bv ||| (BitVec.signExtend UScalarTy.U64.numBits fp.p_biased.bv).shiftLeft 52).toNat =
        Nat.lor fp.m.bv.toNat
          (((fp.p_biased.bv.toInt.emod (2 ^ 64)).toNat * 2 ^ 52) % 2 ^ 64)
    simp only [BitVec.toNat_or, BitVec.shiftLeft, BitVec.toNat_ofNat,
      BitVec.signExtend, BitVec.toNat_ofInt, Nat.shiftLeft_eq,
      UScalarTy.numBits]
    rfl

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
Standard-library dependencies (39)

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 83 entries
Technical checking records
Local closure summary
{
  "node": "AssemblyCorrespondence",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "7c8229ca24e541baac9a6dfd3bf47d9d4eae525633674c342502a5797f1b1b12",
  "active_statement_hash": "29739c8bad82a3d1a4cb8316003439aaea725a2b43d07700f51503466b218326",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "sidecar-sc-20260929-134210-e45b16-AssemblyCorrespondence-cycle-67",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "Binary64ModelDefault": "c722a2c00805b545",
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "c1391b605f3cfebb",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "Binary64Model": "c98c2c511cf0ced6",
    "Binary64ModelDefault": "47013ebe5c83894c",
    "DecimalGoalVocabulary": "c43614ff2149ecf2",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "8127b3eaeae00dd2",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64_from_u64_bits": "8b3f2b83c312275b",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelF64FromBits": "ff88211b2f4e3b25",
    "ModelF64MantissaDigits": "9ceb415358831f73",
    "ModelU64BitOr": "9fa839002e65deb5",
    "ModelU64Shl": "f8169f3bd8c380fc",
    "Preamble": "1f712bede6a5dae6",
    "core_num_FpCategory": "f500de642a5d5148",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_traits_Float": "02acccb9db3e30f2",
    "num_imp_traits_FloatExt": "8614e6c535b457f6"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:28c634c27246ed5fbe73303b7bbe5ea5d114fb3707eb04eedcacb978c73ad9e0",
  "current_fingerprint": "sound-v2:28c634c27246ed5fbe73303b7bbe5ea5d114fb3707eb04eedcacb978c73ad9e0",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}