P14_FiniteMagnitudeZero

Lean checked

Statement

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

Lemma

Let a be a binary64 word with raw value below 2047\,2^{52}, so its sign is clear and it is finite. If its exact rational finite-magnitude decoding is zero, then its raw value is zero.

Lean statement

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

import Tablet.F64
import Tablet.Preamble

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 1000000
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: P14_FiniteMagnitudeZero]
theorem P14_FiniteMagnitudeZero (a : F64)
    (_haFinite : a.val < 2047 * 2 ^ 52)
    (hd : (let e : Nat := a.val / 2 ^ 52
      let m : Nat := a.val % 2 ^ 52
      if e = 0 then ((m : Nat) : Rat) / 2 ^ (1074 : Nat)
      else if 1075 <= e then ((2 ^ 52 + m : Nat) : Rat) * 2 ^ (e - 1075)
      else ((2 ^ 52 + m : Nat) : Rat) / 2 ^ (1075 - e)) = 0) : a.val = 0 := 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

Write the raw value as e2^{52}+m, with e its quotient and m its remainder modulo 2^{52}. The standard finite decoding from Binary64ModelDefault is m/2^{1074} when e=0. Its denominator is strictly positive, so a zero decoding forces m=0; the quotient-remainder identity then gives raw value zero. If e\ne0, the decoding is (2^{52}+m)2^{e-1075} when e\ge1075, and (2^{52}+m)/2^{1075-e} otherwise. The numerator 2^{52}+m is strictly positive, and each power of two is strictly positive. Both possible decodings are therefore strictly positive, contradicting the hypothesis. These cases exhaust the finite word and establish the conclusion.

Lean proof


  dsimp only at hd
  split at hd
  · have hm : a.val % 2 ^ 52 = 0 := by
      have h := (div_eq_zero_iff.mp hd).resolve_right (by positivity)
      exact_mod_cast h
    have decomp := Nat.mod_add_div a.val (2 ^ 52)
    omega
  · split at hd
    · have hp : (0 : Rat) < ((2 ^ 52 + a.val % 2 ^ 52 : Nat) : Rat) *
          2 ^ (a.val / 2 ^ 52 - 1075) :=
        mul_pos (by positivity) (pow_pos (by norm_num) _)
      exact False.elim ((ne_of_gt hp) hd)
    · have hp : (0 : Rat) < ((2 ^ 52 + a.val % 2 ^ 52 : Nat) : Rat) /
          2 ^ (1075 - a.val / 2 ^ 52) :=
        div_pos (by positivity) (pow_pos (by norm_num) _)
      exact False.elim ((ne_of_gt hp) hd)

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.F64
import Tablet.Preamble

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 1000000
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: P14_FiniteMagnitudeZero]
theorem P14_FiniteMagnitudeZero (a : F64)
    (_haFinite : a.val < 2047 * 2 ^ 52)
    (hd : (let e : Nat := a.val / 2 ^ 52
      let m : Nat := a.val % 2 ^ 52
      if e = 0 then ((m : Nat) : Rat) / 2 ^ (1074 : Nat)
      else if 1075 <= e then ((2 ^ 52 + m : Nat) : Rat) * 2 ^ (e - 1075)
      else ((2 ^ 52 + m : Nat) : Rat) / 2 ^ (1075 - e)) = 0) : a.val = 0 := by
-- BODY
  dsimp only at hd
  split at hd
  · have hm : a.val % 2 ^ 52 = 0 := by
      have h := (div_eq_zero_iff.mp hd).resolve_right (by positivity)
      exact_mod_cast h
    have decomp := Nat.mod_add_div a.val (2 ^ 52)
    omega
  · split at hd
    · have hp : (0 : Rat) < ((2 ^ 52 + a.val % 2 ^ 52 : Nat) : Rat) *
          2 ^ (a.val / 2 ^ 52 - 1075) :=
        mul_pos (by positivity) (pow_pos (by norm_num) _)
      exact False.elim ((ne_of_gt hp) hd)
    · have hp : (0 : Rat) < ((2 ^ 52 + a.val % 2 ^ 52 : Nat) : Rat) /
          2 ^ (1075 - a.val / 2 ^ 52) :=
        div_pos (by positivity) (pow_pos (by norm_num) _)
      exact False.elim ((ne_of_gt hp) hd)

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": "P14_FiniteMagnitudeZero",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c50563da7668e210419f5e7863ed096eea10763ac17c148a7ab390a298bd959c",
  "active_statement_hash": "698aa917e046758a4e2d2b9d39668323e1d43969a8b52beee1997f9d5586e392",
  "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-60",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4"
  }
}
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:40e3aa8cd6efb7036e29b2a93bc5ca7c93537685f1efde05526bcc266e4ad27d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}