P14_NativeDivideRounding

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 division of a by 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.Binary64ExactPositiveDivRounds
import Tablet.Binary64ZeroDivRounds
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_NativeDivideRounding]
theorem P14_NativeDivideRounding (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 /\
      ModelF64Div 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. Its decoding satisfies 1\le10^i\le10^{22} and is strictly positive, so it is never a zero divisor.
If v=0, P14 FiniteMagnitudeZero applied to the exact decoding gives raw value a=0. Apply Binary64ZeroDivRounds with the finite positive operand p. It gives successful division returning a, the clear-sign bound and rounding of zero. Here v10^{-i}=0.
Otherwise 1\le v\le2^{53}. In the rationals, 2^{-1022}\le2^{-100}\le10^{-22}\le v/10^i\le v\le2^{53}<2^{128}. The first inequality is monotonicity of powers of two. The second is the integer inequality 10^{22}\le2^{100} with positive denominators inverted. The third uses v\ge1 and 10^i\le10^{22}, and the fourth uses 10^i\ge1. Apply Binary64ExactPositiveDivRounds to the exact positive operand decodings with these normal-range bounds. It supplies a successful division, the bound m<2^{63} and rounding of the embedded rational quotient. Rational inclusion preserves division and powers; since 10\ne0, 10^{-i}=(10^i)^{-1}. This quotient is therefore the stated real v10^{-i}, establishing all conclusions.

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⟩ := Binary64ZeroDivRounds 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 vPositive : (0 : Rat) < v.val := lt_of_lt_of_le (by norm_num) vLower
    have lo : (2 : Rat) ^ (-1022 : Int) <= (v.val : Rat) / 10 ^ i.val := by
      calc
        (2 : Rat) ^ (-1022 : Int) <= (2 : Rat) ^ (-100 : Int) :=
          zpow_le_zpow_right₀ (by norm_num) (by norm_num)
        _ <= 1 / 10 ^ (22 : Nat) := by norm_num [zpow_neg]
        _ <= (v.val : Rat) / 10 ^ i.val :=
          div_le_div₀ (by norm_num) vLower tenPositive tenUpper
    have hiQuotient : (v.val : Rat) / 10 ^ i.val < 2 ^ (128 : Nat) := by
      calc
        (v.val : Rat) / 10 ^ i.val <= (v.val : Rat) :=
          div_le_self vPositive.le tenLower
        _ <= 2 ^ (53 : Nat) := vUpper
        _ < 2 ^ (128 : Nat) := by norm_num
    obtain ⟨m, hm, hb, hr⟩ := Binary64ExactPositiveDivRounds a p
      (v.val : Rat) (10 ^ i.val) haFinite hpFinite' haDecode hpDecode
      vPositive tenPositive lo hiQuotient
    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_inv, Rat.cast_pow, Rat.cast_natCast, Rat.cast_ofNat,
        zpow_neg, zpow_natCast, div_eq_mul_inv]
    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.Binary64ExactPositiveDivRounds
import Tablet.Binary64ZeroDivRounds
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_NativeDivideRounding]
theorem P14_NativeDivideRounding (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 /\
      ModelF64Div 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⟩ := Binary64ZeroDivRounds 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 vPositive : (0 : Rat) < v.val := lt_of_lt_of_le (by norm_num) vLower
    have lo : (2 : Rat) ^ (-1022 : Int) <= (v.val : Rat) / 10 ^ i.val := by
      calc
        (2 : Rat) ^ (-1022 : Int) <= (2 : Rat) ^ (-100 : Int) :=
          zpow_le_zpow_right₀ (by norm_num) (by norm_num)
        _ <= 1 / 10 ^ (22 : Nat) := by norm_num [zpow_neg]
        _ <= (v.val : Rat) / 10 ^ i.val :=
          div_le_div₀ (by norm_num) vLower tenPositive tenUpper
    have hiQuotient : (v.val : Rat) / 10 ^ i.val < 2 ^ (128 : Nat) := by
      calc
        (v.val : Rat) / 10 ^ i.val <= (v.val : Rat) :=
          div_le_self vPositive.le tenLower
        _ <= 2 ^ (53 : Nat) := vUpper
        _ < 2 ^ (128 : Nat) := by norm_num
    obtain ⟨m, hm, hb, hr⟩ := Binary64ExactPositiveDivRounds a p
      (v.val : Rat) (10 ^ i.val) haFinite hpFinite' haDecode hpDecode
      vPositive tenPositive lo hiQuotient
    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_inv, Rat.cast_pow, Rat.cast_natCast, Rat.cast_ofNat,
        zpow_neg, zpow_natCast, div_eq_mul_inv]
    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_NativeDivideRounding",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "b506a36b94731d1dbf570623d7b3ad8dbad406ec6033ef0ccfd4a94218e95cc4",
  "active_statement_hash": "2dbd142112d9b1ed8f9bad2047d5537d11b58ce46329ee7d103f8d2f73463ceb",
  "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": {
    "Binary64ExactPositiveDivRounds": "976564ebe4044467",
    "Binary64FromU64Exact": "f1dc380dae903c52",
    "Binary64Pow10FastPathExact": "93bbdd6f862814f8",
    "Binary64ZeroDivRounds": "dbd86a5562b82095",
    "P14_FiniteMagnitudeZero": "85653a611cd111c5"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "f76c8174a4d58eb5",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path": "c0ce6fdd5caeca22",
    "ModelF64Div": "f8da2e585a4f4183",
    "ModelF64FromU64": "97a26f5bc593ff7a"
  }
}
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:9d237efa5856a809812d1243a288da45b093c2ee0762e3e89cb18c1fabb123a8",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}