Binary64MagnitudeTarget

Lean checked

Definition and explanation

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

Definition

For a nonnegative real x, a binary64 magnitude target is a raw word below the sign bit whose exponent and fraction fields encode the round-to-nearest, ties-to-even result. Finite words are interpreted with the standard binary64 normal and subnormal value formulas. Below the overflow midpoint 2^{1024}-2^{970}, a target is a closest finite encoded value, with an even low significand bit whenever another finite value is equally close. At or above that midpoint the target is the positive-infinity word. No signed word, NaN word, or noncanonical infinity word is a magnitude target.

Lean definition

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

import Tablet.Preamble
import Mathlib.Data.Real.Basic

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: Binary64MagnitudeTarget]
def Binary64MagnitudeTarget (x : Real) (bits : Nat) : Prop :=
-- BODY
  let signBit := 2 ^ 63
  let infinityBits := 2047 * 2 ^ 52
  let finiteValue := fun b : Nat =>
    let e : Nat := b / 2 ^ 52
    let m : Nat := b % 2 ^ 52
    if e = 0
    then (m : Real) * 2 ^ (-1074 : Int)
    else (((2 ^ 52 : Nat) + m : Nat) : Real) * 2 ^ ((e : Int) - 1075)
  let overflowThreshold : Real := 2 ^ (1024 : Int) - 2 ^ (970 : Int)
  0 ≤ x ∧ bits < signBit ∧
    if bits = infinityBits then
      overflowThreshold ≤ x
    else
      bits < infinityBits ∧ x < overflowThreshold ∧
      (∀ candidate < infinityBits,
        |x - finiteValue bits| ≤ |x - finiteValue candidate|) ∧
      ((∃ candidate < infinityBits,
          candidate ≠ bits ∧
          |x - finiteValue bits| = |x - finiteValue candidate|) →
        bits % 2 = 0)

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 relation is exactly IEEE-754 binary64 round-to-nearest, ties-to-even for nonnegative real magnitudes, including subnormals, zero, and overflow to infinity, stated over the complete raw-word carrier.

Proof

The exponent width, 52 stored significand bits, sign bit, and raw-word interpretation are fixed by the binary64 source implementation. The finite value formula separates exponent zero (subnormal and zero) from normal values. Nearest-distance minimization gives round-to-nearest; requiring the low stored bit to be even at a midpoint gives ties-to-even. The displayed overflow midpoint is halfway from the largest finite value to the next power-of-two spacing and therefore rounds upward to infinity on the even tie. The source field facts are recorded in reference/model-evidence/decimal-specification.txt.

Requirement: parser totality

The relation constrains returned words but adds no termination assumption.

Requirement: parser numeric acceptance

Acceptance is independent of which magnitude word is the rounding target.

Requirement: parser invalid rejection

Errors contain no magnitude target.

Requirement: parser nan acceptance

NaN words are intentionally outside this numeric magnitude relation.

Requirement: parser infinity

The relation identifies positive infinity as the overflowing magnitude; lexical sign is observed separately.

Requirement: parser non nan results

Every magnitude target is non-NaN by construction.

Requirement: parser numeric sign

The relation omits the sign bit so the lexical sign remains an independent observation.

Requirement: parser signed zero

Magnitude zero and the separate sign observation retain both signed zeros.

Requirement: parser exact rounding

Applying the relation to absolute exact value states precisely the requested rounding.

Requirement: parser selected exponent

Raw-pair exponent bounds precede numerical target interpretation.

Requirement: parser selected magnitude sign

Every target word has a clear sign bit by definition.

Requirement: dispatch abstract composition

Component contracts can share one exact classification, rounding, and overflow relation.

Requirement: dispatch component compliance

Actual component words can be checked directly against this raw-word relation.

Requirement: parser accumulated rounding

Applying the relation to absolute accumulated value states the diagnostic target.

Requirement: parser equal target rounding

Equality of targets is equality of words satisfying the same relation for both values.

Requirement: number helper acceptance

The lexical helper returns no binary64 word.

Requirement: number helper rejection

The lexical helper returns no binary64 word.

Requirement: number helper record bounds

Decimal-record bounds are independent of binary64 rounding.

Requirement: number helper accumulated value

This goal establishes an interval before binary64 rounding and is not strengthened by the relation.

Requirement: special helper infinity

The positive-infinity magnitude word is explicit; the separate sign selects either infinity.

Requirement: special helper nan

NaN classification is deliberately expressed separately from numeric rounding.

Requirement: special helper rejection

A None result contains no rounding target.

Requirement: native correct or defer

A Some word can state exact native-path rounding without abstract float equality.

Requirement: integer correct or defer

The assembled raw word can be related directly to the exact nonnegative value.

Requirement: slow accumulated rounding

The assembled raw word can be related directly to the full-significand accumulated value.

Requirement: assembly correspondence

The relation consumes the same raw word whose construction that theorem specifies.

Requirement: classification totality

Literal classification is independent of numerical rounding.

Requirement: classification determinism

Literal classification is independent of numerical rounding.

Requirement: classification significand digit

The grammar property is independent of numerical rounding.

Requirement: rounding totality

Existence of a related word is exactly rounding totality.

Requirement: rounding determinism

Uniqueness of a related word is exactly rounding determinism.

Requirement: exponent value agreement

Agreement is stated by equivalence of this relation for the two values.

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
Technical checking records
Local closure summary
{
  "node": "Binary64MagnitudeTarget",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "9943be30c27046cf9172a51009e8bd1c9e852f175b444d825297feb010a3eef7",
  "active_statement_hash": "76fd4606597fbd79ea87b580c79bfa973dddf141def315594aff7df46ed1fbb6",
  "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-3",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
Prose assessment
{
  "label": "Prose review has no verdict in this snapshot",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "preservation-v1:5abd2e88457e855a7947e2d70d507c8eee2d95c307f4307dfd11722e6a251785",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}