Binary64ZeroDivRounds

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 division 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.ModelF64Div

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

namespace dec2flt_model

-- [TABLET NODE: Binary64ZeroDivRounds]
theorem Binary64ZeroDivRounds :
    ∀ (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 → ModelF64Div 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. Its zero-rounding certificate follows from the zero case of Binary64FromU64Exact. For p, the finite raw bound excludes NaN and infinity and clears its sign bit. Positivity of the exact decoding excludes the zero category: zero exponent and fraction fields would reconstruct raw word zero and decode to zero.
Unfold ModelF64Div and Binary64ModelDefault. The numerator has the zero category, the denominator is positive finite and nonzero, and both signs are clear. Hence the modeled IEEE zero-numerator branch returns positive zero, namely z itself. Its raw bound is immediate, and the cited conversion certificate supplies the required global nearest-even relation 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 [ModelF64Div, 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 = 1) ∨ ((2 : Nat) = 2 ∧ cp = 2) then _ else
    if (2 : Nat) = 1 ∨ cp = 2 then _ else
    if cp = 1 ∨ (2 : Nat) = 2 then _ else _) = _
  simp only [cp0, cp1, cp2, false_or, true_and, true_or, if_false, if_true]
  have hneg : decide (((0 : Nat) != 0) = true) = false := rfl
  rw [hneg]
  simp only [Bool.false_eq_true, if_false, Nat.add_zero]
  exact congrArg ok 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.ModelF64Div

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

namespace dec2flt_model

-- [TABLET NODE: Binary64ZeroDivRounds]
theorem Binary64ZeroDivRounds :
    ∀ (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 → ModelF64Div 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 [ModelF64Div, 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 = 1) ∨ ((2 : Nat) = 2 ∧ cp = 2) then _ else
    if (2 : Nat) = 1 ∨ cp = 2 then _ else
    if cp = 1 ∨ (2 : Nat) = 2 then _ else _) = _
  simp only [cp0, cp1, cp2, false_or, true_and, true_or, if_false, if_true]
  have hneg : decide (((0 : Nat) != 0) = true) = false := rfl
  rw [hneg]
  simp only [Bool.false_eq_true, if_false, Nat.add_zero]
  exact congrArg ok 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": "Binary64ZeroDivRounds",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "eb3c2993acd689a886a84cf4e43166c44b1b1a38973c5a9c3034338bf7b40ef1",
  "active_statement_hash": "87e385e79c1b9d42758c758836489dabe0685a3707fe56e8deee46938fb8e256",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "Binary64FromU64Exact": "f1dc380dae903c52",
    "Binary64ModelDefault": "c722a2c00805b545"
  },
  "strict_definition_deps": {
    "Binary64Model": "c98c2c511cf0ced6",
    "Binary64ModelDefault": "47013ebe5c83894c",
    "DecimalGoalVocabulary": "f76c8174a4d58eb5",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "F64": "ec4e25fbaf4e11d4",
    "ModelF64Div": "f8da2e585a4f4183",
    "ModelF64FromU64": "97a26f5bc593ff7a",
    "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:fe38df2229e55a0f1b0552ad5b5bc7ab07d8e58546c76644e3a74479c3743fd3",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}