Binary64EncoderCarryArithmetic

Lean checked

Statement

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

Helper

Let 1\leq e\leq2045 and 2^{52}\leq q<2^{53}. For either choice between q and q+1, encode the chosen significand in exponent field e, carrying a significand 2^{53} into field e+1. The resulting raw word is the lower word e2^{52}+(q-2^{52}) plus one exactly when q+1 was selected, and it is strictly below the infinity word 2047\,2^{52}. Moreover, the lower word has the parity of q, and its successor has the parity of q+1.

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

set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: Binary64EncoderCarryArithmetic]
theorem Binary64EncoderCarryArithmetic :
    ∀ (e q : Nat) (P : Prop) [Decidable P],
      1 ≤ e → e ≤ 2045 → 2 ^ 52 ≤ q → q < 2 ^ 53 →
      let rounded := if P then q + 1 else q
      let lowBits := e * 2 ^ 52 + (q - 2 ^ 52)
      let bits := if rounded = 2 ^ 53 then (e + 1) * 2 ^ 52
        else e * 2 ^ 52 + (rounded - 2 ^ 52)
      bits = (if P then lowBits + 1 else lowBits) ∧
        bits < 2047 * 2 ^ 52 ∧
        lowBits % 2 = q % 2 ∧ (lowBits + 1) % 2 = (q + 1) % 2 := 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

If q is selected, the strict upper bound excludes a carry and the displayed encoding is exactly the lower word. If q+1 is selected and is below 2^{53}, subtraction of 2^{52} commutes with adding one, so its word is the lower word plus one. If q+1=2^{53}, then q=2^{53}-1 and the same lower word plus one is (e+1)2^{52}, exactly the carry encoding. Finally the largest possible carried exponent is 2046, which remains strictly below the infinity field 2047; the non-carried cases are no larger. Since 2^{52} and every exponent-field multiple of it are even, subtracting 2^{52} does not change the parity of q, proving the two parity formulas.

Lean proof


  intro e q P _ he0 he1 hq0 hq1
  dsimp only
  by_cases hP : P
  · rw [if_pos hP]
    split <;> omega
  · rw [if_neg hP]
    split <;> omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault

set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: Binary64EncoderCarryArithmetic]
theorem Binary64EncoderCarryArithmetic :
    ∀ (e q : Nat) (P : Prop) [Decidable P],
      1 ≤ e → e ≤ 2045 → 2 ^ 52 ≤ q → q < 2 ^ 53 →
      let rounded := if P then q + 1 else q
      let lowBits := e * 2 ^ 52 + (q - 2 ^ 52)
      let bits := if rounded = 2 ^ 53 then (e + 1) * 2 ^ 52
        else e * 2 ^ 52 + (rounded - 2 ^ 52)
      bits = (if P then lowBits + 1 else lowBits) ∧
        bits < 2047 * 2 ^ 52 ∧
        lowBits % 2 = q % 2 ∧ (lowBits + 1) % 2 = (q + 1) % 2 := by
-- BODY
  intro e q P _ he0 he1 hq0 hq1
  dsimp only
  by_cases hP : P
  · rw [if_pos hP]
    split <;> omega
  · rw [if_neg hP]
    split <;> omega

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (44)
More program dependencies (11)
Standard-library dependencies (30)

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": "Binary64EncoderCarryArithmetic",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "73bc323143f79efd8511fef38ae3c56801010b00641d12f83b8c41ba43da1322",
  "active_statement_hash": "c88a779ed33360364edd2e453578d29276595a3efd7313957cdfdbf4ba866f81",
  "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-68",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:5680e491a46f854196b21060f3398110dc1e4882d7fa3caa3046aac8bf0b2397",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}