P14_NativeMultiplyRounding

Lean checked

Statement

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

Lemma

For every U64 word v\le2^{53} and Usize index i\le22, there exist words a,p,m such that the modeled U64-to-binary64 conversion returns a, the selected extracted power-of-ten lookup at i returns p, and modeled multiplication of a and p returns m, all normally. Moreover m<2^{63} and m satisfies roundsMagnitude of DecimalGoalVocabularyDefault for the real value v10^i.

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.Binary64Pow10FastPathExact
import Tablet.Binary64ExactPositiveMulRounds
import Tablet.Binary64ZeroMulRounds
import Tablet.P14_FiniteMagnitudeZero

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_NativeMultiplyRounding]
theorem P14_NativeMultiplyRounding (v : Std.U64) (i : Std.Usize) (hv : v.val <= 2 ^ 53) (hi : i.val <= 22) :
    exists a p m : F64, ModelF64FromU64 v = ok a /\
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path i = ok p /\
      ModelF64Mul a p = ok m /\ m.val < 2 ^ 63 /\
      DecimalGoalVocabularyDefault.roundsMagnitude
        ((v.val : Real) * (10 : Real) ^ (i.val : Int)) m := 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

By Binary64FromU64Exact, conversion returns a word a<2047\,2^{52} whose exact rational decoding is v. By Binary64Pow10FastPathExact, lookup returns a word p<\mathtt{0x7ff0000000000000}=2047\,2^{52} whose exact rational decoding is 10^i. Since i\le22, 1\le10^i\le10^{22}; in particular this decoding is strictly positive.
If v=0, the exact decoding of a is zero, so P14 FiniteMagnitudeZero gives raw value a=0. Apply Binary64ZeroMulRounds with the finite positive operand p. It gives successful multiplication returning a, the bound a<2^{63}, and rounding of zero. The stated value v10^i is zero, as required.
Otherwise the integer word satisfies 1\le v\le2^{53}. In the rationals, 1\le v10^i\le2^{53}10^{22}<2^{128} and 2^{-1022}\le1. The product upper bound is direct integer arithmetic, and the remaining inequalities follow from positivity and monotonicity of powers. Thus Binary64ExactPositiveMulRounds applies to the two exact decodings. It returns normally with a clear-sign word m<2^{63} rounding the rational product embedded in the reals. Rational inclusion preserves multiplication and natural powers; the natural power agrees with the integer-exponent power at the nonnegative integer i. Hence that embedded product is exactly the stated real v10^i, proving every conclusion.

Lean proof


  obtain ⟨a, ha, haFinite, haDecode, _⟩ := Binary64FromU64Exact v hv
  obtain ⟨p, hp, hpFinite, hpDecode⟩ := Binary64Pow10FastPathExact i hi
  have hpFinite' : p.val < 2047 * 2 ^ 52 := by norm_num at hpFinite ⊢; exact hpFinite
  have tenPositive : (0 : Rat) < 10 ^ i.val := by positivity
  have tenLower : (1 : Rat) <= 10 ^ i.val := one_le_pow₀ (by norm_num)
  have tenUpper : (10 : Rat) ^ i.val <= 10 ^ (22 : Nat) :=
    pow_le_pow_right₀ (by norm_num) hi
  have vUpper : (v.val : Rat) <= 2 ^ (53 : Nat) := by exact_mod_cast hv
  by_cases hvZero : v.val = 0
  · have aZero := P14_FiniteMagnitudeZero a haFinite (by simpa only [hvZero, Nat.cast_zero] using haDecode)
    obtain ⟨hm, hb, hr⟩ := Binary64ZeroMulRounds a p (10 ^ i.val)
      aZero hpFinite' hpDecode tenPositive
    refine ⟨a, p, a, ha, hp, hm, hb, ?_⟩
    rw [hvZero, Nat.cast_zero, zero_mul]
    exact hr
  · have vLower : (1 : Rat) <= v.val := by
      exact_mod_cast (by omega : 1 <= v.val)
    have lo : (2 : Rat) ^ (-1022 : Int) <= (v.val : Rat) * 10 ^ i.val := by
      have unit : (1 : Rat) <= (v.val : Rat) * 10 ^ i.val :=
        one_le_mul_of_one_le_of_one_le vLower tenLower
      have tiny : (2 : Rat) ^ (-1022 : Int) <= 1 := by
        calc
          (2 : Rat) ^ (-1022 : Int) <= (2 : Rat) ^ (0 : Int) :=
            zpow_le_zpow_right₀ (by norm_num) (by norm_num)
          _ = 1 := zpow_zero _
      exact tiny.trans unit
    have hiProduct : (v.val : Rat) * 10 ^ i.val < 2 ^ (128 : Nat) := by
      calc
        (v.val : Rat) * 10 ^ i.val <= (2 ^ (53 : Nat) : Rat) * 10 ^ (22 : Nat) :=
          mul_le_mul vUpper tenUpper (by positivity) (by positivity)
        _ < 2 ^ (128 : Nat) := by norm_num
    obtain ⟨m, hm, hb, hr⟩ := Binary64ExactPositiveMulRounds a p
      (v.val : Rat) (10 ^ i.val) haFinite hpFinite' haDecode hpDecode lo hiProduct
    refine ⟨a, p, m, ha, hp, hm, hb, ?_⟩
    have argEq : (((v.val : Rat) * (10 : Rat) ^ i.val : Rat) : Real) =
        (v.val : Real) * (10 : Real) ^ (i.val : Int) := by
      simp only [Rat.cast_mul, Rat.cast_pow, Rat.cast_natCast, Rat.cast_ofNat, zpow_natCast]
    rw [argEq] at hr
    exact hr

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Binary64FromU64Exact
import Tablet.Binary64Pow10FastPathExact
import Tablet.Binary64ExactPositiveMulRounds
import Tablet.Binary64ZeroMulRounds
import Tablet.P14_FiniteMagnitudeZero

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_NativeMultiplyRounding]
theorem P14_NativeMultiplyRounding (v : Std.U64) (i : Std.Usize) (hv : v.val <= 2 ^ 53) (hi : i.val <= 22) :
    exists a p m : F64, ModelF64FromU64 v = ok a /\
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path i = ok p /\
      ModelF64Mul a p = ok m /\ m.val < 2 ^ 63 /\
      DecimalGoalVocabularyDefault.roundsMagnitude
        ((v.val : Real) * (10 : Real) ^ (i.val : Int)) m := by
-- BODY
  obtain ⟨a, ha, haFinite, haDecode, _⟩ := Binary64FromU64Exact v hv
  obtain ⟨p, hp, hpFinite, hpDecode⟩ := Binary64Pow10FastPathExact i hi
  have hpFinite' : p.val < 2047 * 2 ^ 52 := by norm_num at hpFinite ⊢; exact hpFinite
  have tenPositive : (0 : Rat) < 10 ^ i.val := by positivity
  have tenLower : (1 : Rat) <= 10 ^ i.val := one_le_pow₀ (by norm_num)
  have tenUpper : (10 : Rat) ^ i.val <= 10 ^ (22 : Nat) :=
    pow_le_pow_right₀ (by norm_num) hi
  have vUpper : (v.val : Rat) <= 2 ^ (53 : Nat) := by exact_mod_cast hv
  by_cases hvZero : v.val = 0
  · have aZero := P14_FiniteMagnitudeZero a haFinite (by simpa only [hvZero, Nat.cast_zero] using haDecode)
    obtain ⟨hm, hb, hr⟩ := Binary64ZeroMulRounds a p (10 ^ i.val)
      aZero hpFinite' hpDecode tenPositive
    refine ⟨a, p, a, ha, hp, hm, hb, ?_⟩
    rw [hvZero, Nat.cast_zero, zero_mul]
    exact hr
  · have vLower : (1 : Rat) <= v.val := by
      exact_mod_cast (by omega : 1 <= v.val)
    have lo : (2 : Rat) ^ (-1022 : Int) <= (v.val : Rat) * 10 ^ i.val := by
      have unit : (1 : Rat) <= (v.val : Rat) * 10 ^ i.val :=
        one_le_mul_of_one_le_of_one_le vLower tenLower
      have tiny : (2 : Rat) ^ (-1022 : Int) <= 1 := by
        calc
          (2 : Rat) ^ (-1022 : Int) <= (2 : Rat) ^ (0 : Int) :=
            zpow_le_zpow_right₀ (by norm_num) (by norm_num)
          _ = 1 := zpow_zero _
      exact tiny.trans unit
    have hiProduct : (v.val : Rat) * 10 ^ i.val < 2 ^ (128 : Nat) := by
      calc
        (v.val : Rat) * 10 ^ i.val <= (2 ^ (53 : Nat) : Rat) * 10 ^ (22 : Nat) :=
          mul_le_mul vUpper tenUpper (by positivity) (by positivity)
        _ < 2 ^ (128 : Nat) := by norm_num
    obtain ⟨m, hm, hb, hr⟩ := Binary64ExactPositiveMulRounds a p
      (v.val : Rat) (10 ^ i.val) haFinite hpFinite' haDecode hpDecode lo hiProduct
    refine ⟨a, p, m, ha, hp, hm, hb, ?_⟩
    have argEq : (((v.val : Rat) * (10 : Rat) ^ i.val : Rat) : Real) =
        (v.val : Real) * (10 : Real) ^ (i.val : Int) := by
      simp only [Rat.cast_mul, Rat.cast_pow, Rat.cast_natCast, Rat.cast_ofNat, zpow_natCast]
    rw [argEq] at hr
    exact hr

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 46 entries
Technical checking records
Local closure summary
{
  "node": "P14_NativeMultiplyRounding",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f099b02b2f3df301da9c0f6bc8e65dca1da1c8a672f8425a6a5947f3076d2603",
  "active_statement_hash": "e7542c475c18eee33b896bfe66fa764a299d1fd287c7bc4c28e2cab1ac6d5c41",
  "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-199",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "Binary64ExactPositiveMulRounds": "a05b820da3503675",
    "Binary64FromU64Exact": "f1dc380dae903c52",
    "Binary64Pow10FastPathExact": "93bbdd6f862814f8",
    "Binary64ZeroMulRounds": "c57caade6d34c32a",
    "P14_FiniteMagnitudeZero": "85653a611cd111c5"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "f76c8174a4d58eb5",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path": "c0ce6fdd5caeca22",
    "ModelF64FromU64": "97a26f5bc593ff7a",
    "ModelF64Mul": "ba97971db93c2ae2"
  }
}
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:330dffe035011a7b4c7abf58514bff9795e7d5751df6d10d5dc957b2e3ef807f",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}