Binary64ZeroMulRounds

Lean checked

Statement

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

Lemma

Let z be the clear-sign zero word and let a finite clear-sign word p decode exactly to a positive rational. Modeled multiplication of z by p returns z, whose raw word is below 2^{63} and which satisfies roundsMagnitude at 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.Binary64FromU64Exact
import Tablet.Binary64ModelDefault
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelF64Mul

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

namespace dec2flt_model

-- [TABLET NODE: Binary64ZeroMulRounds]
theorem Binary64ZeroMulRounds :
    ∀ (z p : F64) (y : Rat), z.val = 0 → p.val < 2047 * 2 ^ 52 →
      (let bits := p.val
       let e := bits / (2 ^ 52 : Nat)
       let m := bits % (2 ^ 52 : Nat)
       if e = 0 then (m : Rat) / (2 : Rat) ^ (1074 : Nat)
       else if 1075 ≤ e then (((2 ^ 52 : Nat) + m : Nat) : Rat) * (2 : Rat) ^ (e - 1075)
       else (((2 ^ 52 : Nat) + m : Nat) : Rat) / (2 : Rat) ^ (1075 - e)) = y →
      0 < y → ModelF64Mul z p = ok z ∧ z.val < 2 ^ 63 ∧
        DecimalGoalVocabularyDefault.roundsMagnitude (0 : Real) z := 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

The raw equation identifies z with the all-zero word, and the zero case of Binary64FromU64Exact supplies its global nearest-even certificate. The finite raw bound on p excludes NaN and infinity and clears its sign bit. If p had the zero category, its exponent and fraction fields would both be zero, so its raw word and exact decoding would be zero, contradicting the assumed positivity.
Unfold ModelF64Mul and Binary64ModelDefault. The operand categories are therefore zero and positive finite, so no NaN or infinity case applies. Their decoded product is zero. In the magnitude encoder the overflow test is false, the subnormal test is true, and nearest-even applied to 0\cdot2^{1074} returns raw magnitude zero. Both operand signs are clear, so the sign combination also returns zero, namely z. Its raw bound is immediate, and the cited conversion certificate proves roundsMagnitude at zero.

Lean proof


  intro z p y hz hp hpy hy
  have z_eq : z = (⟨BitVec.ofNat 64 0⟩ : F64) := by
    apply UScalar.eq_of_val_eq
    rw [hz]
    rfl
  obtain ⟨fz, hfz, hfz_bound, hfz_decode, hfz_round⟩ :=
    Binary64FromU64Exact 0#u64 (by norm_num)
  have fz_eq : fz = z := by
    have hzero : ModelF64FromU64 0#u64 = ok (⟨BitVec.ofNat 64 0⟩ : F64) := by
      set_option exponentiation.threshold 2048 in
        norm_num [ModelF64FromU64, Binary64ModelDefault, zpow_neg]
    rw [hzero] at hfz
    cases hfz
    exact z_eq.symm
  subst fz
  have hpexp : p.val / (2 ^ 52 : Nat) < 2047 := by
    apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < (2 ^ 52 : Nat))).2
    simpa [Nat.mul_comm] using hp
  have hpsign : p.val / (2 ^ 63 : Nat) = 0 := Nat.div_eq_of_lt (by omega)
  have hpmag : p.val % (2 ^ 63 : Nat) = p.val := Nat.mod_eq_of_lt (by omega)
  have hp2047 : p.val / (2 ^ 52 : Nat) ≠ 2047 := by omega
  let cp := if p.val / 4503599627370496 = 0 then
    if p.val % 4503599627370496 = 0 then 2 else 3 else 4
  have cp0 : cp ≠ 0 := by
    dsimp [cp]
    by_cases h : p.val / 4503599627370496 = 0
    · rw [if_pos h]; split <;> omega
    · rw [if_neg h]; omega
  have cp1 : cp ≠ 1 := by
    dsimp [cp]
    by_cases h : p.val / 4503599627370496 = 0
    · rw [if_pos h]; split <;> omega
    · rw [if_neg h]; omega
  have cp2 : cp ≠ 2 := by
    intro hcp
    have he : p.val / 4503599627370496 = 0 := by
      dsimp [cp] at hcp
      split at hcp <;> omega
    have hm : p.val % 4503599627370496 = 0 := by
      dsimp [cp] at hcp
      rw [if_pos he] at hcp
      split at hcp <;> omega
    have hpz : p.val = 0 := by
      have hdecomp := Nat.mod_add_div p.val 4503599627370496
      omega
    simp [hpz] at hpy
    linarith
  change DecimalGoalVocabularyDefault.roundsMagnitude (((0#u64).val : Nat) : Real) z at hfz_round
  rw [show (0#u64).val = 0 by rfl] at hfz_round
  norm_num at hfz_round
  refine ⟨?_, by omega, hfz_round⟩
  simp only [ModelF64Mul, Binary64ModelDefault, hz, Nat.zero_mod, Nat.zero_div,
    Nat.cast_zero, zero_div, hpmag, hpsign, hp2047, if_false]
  change (if (2 : Nat) = 0 ∨ cp = 0 then _ else
    if ((2 : Nat) = 1 ∧ cp = 2) ∨ ((2 : Nat) = 2 ∧ cp = 1) then _ else
    if (2 : Nat) = 1 ∨ cp = 1 then _ else _) = _
  simp only [cp0, cp1, false_or, false_and, true_and, if_false]
  have hneg : decide (((0 : Nat) != 0) = true) = false := rfl
  rw [hneg]
  simp only [Bool.false_eq_true, if_false, Nat.add_zero]
  set_option exponentiation.threshold 2048 in
    norm_num [zpow_neg]
  exact z_eq.symm

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Binary64FromU64Exact
import Tablet.Binary64ModelDefault
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelF64Mul

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

namespace dec2flt_model

-- [TABLET NODE: Binary64ZeroMulRounds]
theorem Binary64ZeroMulRounds :
    ∀ (z p : F64) (y : Rat), z.val = 0 → p.val < 2047 * 2 ^ 52 →
      (let bits := p.val
       let e := bits / (2 ^ 52 : Nat)
       let m := bits % (2 ^ 52 : Nat)
       if e = 0 then (m : Rat) / (2 : Rat) ^ (1074 : Nat)
       else if 1075 ≤ e then (((2 ^ 52 : Nat) + m : Nat) : Rat) * (2 : Rat) ^ (e - 1075)
       else (((2 ^ 52 : Nat) + m : Nat) : Rat) / (2 : Rat) ^ (1075 - e)) = y →
      0 < y → ModelF64Mul z p = ok z ∧ z.val < 2 ^ 63 ∧
        DecimalGoalVocabularyDefault.roundsMagnitude (0 : Real) z := by
-- BODY
  intro z p y hz hp hpy hy
  have z_eq : z = (⟨BitVec.ofNat 64 0⟩ : F64) := by
    apply UScalar.eq_of_val_eq
    rw [hz]
    rfl
  obtain ⟨fz, hfz, hfz_bound, hfz_decode, hfz_round⟩ :=
    Binary64FromU64Exact 0#u64 (by norm_num)
  have fz_eq : fz = z := by
    have hzero : ModelF64FromU64 0#u64 = ok (⟨BitVec.ofNat 64 0⟩ : F64) := by
      set_option exponentiation.threshold 2048 in
        norm_num [ModelF64FromU64, Binary64ModelDefault, zpow_neg]
    rw [hzero] at hfz
    cases hfz
    exact z_eq.symm
  subst fz
  have hpexp : p.val / (2 ^ 52 : Nat) < 2047 := by
    apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < (2 ^ 52 : Nat))).2
    simpa [Nat.mul_comm] using hp
  have hpsign : p.val / (2 ^ 63 : Nat) = 0 := Nat.div_eq_of_lt (by omega)
  have hpmag : p.val % (2 ^ 63 : Nat) = p.val := Nat.mod_eq_of_lt (by omega)
  have hp2047 : p.val / (2 ^ 52 : Nat) ≠ 2047 := by omega
  let cp := if p.val / 4503599627370496 = 0 then
    if p.val % 4503599627370496 = 0 then 2 else 3 else 4
  have cp0 : cp ≠ 0 := by
    dsimp [cp]
    by_cases h : p.val / 4503599627370496 = 0
    · rw [if_pos h]; split <;> omega
    · rw [if_neg h]; omega
  have cp1 : cp ≠ 1 := by
    dsimp [cp]
    by_cases h : p.val / 4503599627370496 = 0
    · rw [if_pos h]; split <;> omega
    · rw [if_neg h]; omega
  have cp2 : cp ≠ 2 := by
    intro hcp
    have he : p.val / 4503599627370496 = 0 := by
      dsimp [cp] at hcp
      split at hcp <;> omega
    have hm : p.val % 4503599627370496 = 0 := by
      dsimp [cp] at hcp
      rw [if_pos he] at hcp
      split at hcp <;> omega
    have hpz : p.val = 0 := by
      have hdecomp := Nat.mod_add_div p.val 4503599627370496
      omega
    simp [hpz] at hpy
    linarith
  change DecimalGoalVocabularyDefault.roundsMagnitude (((0#u64).val : Nat) : Real) z at hfz_round
  rw [show (0#u64).val = 0 by rfl] at hfz_round
  norm_num at hfz_round
  refine ⟨?_, by omega, hfz_round⟩
  simp only [ModelF64Mul, Binary64ModelDefault, hz, Nat.zero_mod, Nat.zero_div,
    Nat.cast_zero, zero_div, hpmag, hpsign, hp2047, if_false]
  change (if (2 : Nat) = 0 ∨ cp = 0 then _ else
    if ((2 : Nat) = 1 ∧ cp = 2) ∨ ((2 : Nat) = 2 ∧ cp = 1) then _ else
    if (2 : Nat) = 1 ∨ cp = 1 then _ else _) = _
  simp only [cp0, cp1, false_or, false_and, true_and, if_false]
  have hneg : decide (((0 : Nat) != 0) = true) = false := rfl
  rw [hneg]
  simp only [Bool.false_eq_true, if_false, Nat.add_zero]
  set_option exponentiation.threshold 2048 in
    norm_num [zpow_neg]
  exact z_eq.symm

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (45)
More program dependencies (12)
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
All 42 entries
Technical checking records
Local closure summary
{
  "node": "Binary64ZeroMulRounds",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "5668e768a9cc9259912386efda0327fbd2642b7c4566407730f133db500a423b",
  "active_statement_hash": "d6a719cfae93b5337d3ed35b703f21700e9422e9ac3f6a307bb5889ef3beee7b",
  "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": "worker-result-local-closure-issuance-cycle-131",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "Binary64FromU64Exact": "f1dc380dae903c52",
    "Binary64ModelDefault": "c722a2c00805b545"
  },
  "strict_definition_deps": {
    "Binary64Model": "c98c2c511cf0ced6",
    "Binary64ModelDefault": "dc548d1e27696ba4",
    "DecimalGoalVocabulary": "f76c8174a4d58eb5",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "F64": "ec4e25fbaf4e11d4",
    "ModelF64FromU64": "97a26f5bc593ff7a",
    "ModelF64Mul": "ba97971db93c2ae2",
    "core_num_FpCategory": "f500de642a5d5148"
  }
}
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:b4df276b3fbe8249b640f23842db9b4ffd769e96120acb6806bb4a24c7ac0718",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}