P661_T1_ProductApproximationExecution

Lean checked

Statement

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

Lemma · Cached-product approximation returns normally

For every I64 q with -342\le q\le308 and every U64 w, the extracted product approximation at Usize precision 55 returns normally with a pair of U64 words. There is no normalized-input or successful-call hypothesis, and w=0 is included.

Lean statement

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

import Tablet.P661_T1_FullMultiplicationExecution
import Tablet.IntegerPowerTableCertificate
import Tablet.num_imp_dec2flt_lemire_compute_product_approx

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_ProductApproximationExecution]
theorem P661_T1_ProductApproximationExecution (q : Std.I64) (w : Std.U64)
    (hqlo : -342 <= q.val) (hqhi : q.val <= 308) :
    exists lo hi : Std.U64,
      num.imp.dec2flt.lemire.compute_product_approx q w 55#usize = ok (lo, hi) := 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

Use the existing 64-bit platform assumption of Assumptions. Unfold num imp dec2flt lemire compute product approx. The endpoint literals are -342,308 by num imp dec2flt table SMALLEST POWER OF FIVE and num imp dec2flt table LARGEST POWER OF FIVE. Their total I32-to-I64 casts preserve -342,308, so the first two assertions are exactly the hypotheses. The precision assertion is 55\le64. Its strict test is true; the shift by 55 is legal and shifts 2^{64}-1 to 2^9-1=511. IntegerPowerTableCertificate supplies the actual checked difference q-(-342), its Usize cast, and the actual table access, with returned U64 entries a,b. Repeated endpoint casts give the same -342. Thus all operations through that access return normally with these operands.
FullMultiplicationExecution on w,a supplies the normal first pair (l,h) and h=\lfloor wa/B\rfloor, where B=2^{64}. The lifted bitwise AND is total. If h\mathbin{\&}511\ne511, the source immediately returns this normal pair. If w=0, the full-product equation and nonnegativity force h=l=0, so this is the branch taken: the refinement guard is false. No positive-w bound is used at zero.
Otherwise apply FullMultiplicationExecution to w,b to construct the second normal pair, with high word k. The lifted wrapping addition is total and returns t=(l+k)\bmod B. If the carry test k>t is false, the final pair (t,h) is already normal. If it is true, the only additional checked operation is h+1. For 0<w<B and a<B one has wa<wB, hence \lfloor wa/B\rfloor<w. Therefore h+1\le w<B, proving the increment fits U64. Equivalently, the uniform bound wa\le(B-1)^2 gives h\le B-2, including zero; this is the bound used in the Lean proof. Thus the increment succeeds and the source returns (t,h+1). This checks every assertion, cast, shift, table access, multiplication, lifted bit operation, wrapping sum, and checked increment in its source order. No conclusion of an on-normal rounding theorem is used to supply execution.

Lean proof


  obtain ⟨q32, p, delta, index, a, b, hq32, hp, hpval,
    hdelta, hindex, htable, hcert⟩ := IntegerPowerTableCertificate q hqlo hqhi
  unfold num.imp.dec2flt.lemire.compute_product_approx
  have hsmall : lift (IScalar.cast .I64
      num.imp.dec2flt.table.SMALLEST_POWER_OF_FIVE) = ok (-342)#i64 := by
    rw [num.imp.dec2flt.table.SMALLEST_POWER_OF_FIVE.eq_def]
    rfl
  have hlarge : lift (IScalar.cast .I64
      num.imp.dec2flt.table.LARGEST_POWER_OF_FIVE) = ok 308#i64 := by
    rw [num.imp.dec2flt.table.LARGEST_POWER_OF_FIVE.eq_def]
    rfl
  have hmask : 18446744073709551615#u64 >>> 55#usize = ok 511#u64 := by rfl
  rw [hsmall]
  simp only [bind_tc_ok, ge_iff_le, IScalar.le_equiv,
    show ((-342)#i64).val = -342 from rfl, hqlo, massert_True]
  rw [hlarge]
  simp only [bind_tc_ok, IScalar.le_equiv, show (308#i64).val = 308 from rfl,
    hqhi, massert_True, UScalar.le_equiv, UScalar.lt_equiv,
    UScalar.ofNatCore_val_eq, Nat.reduceLeDiff, Nat.reduceLT, if_true]
  rw [hmask]
  simp only [bind_tc_ok]
  rw [hdelta]
  simp only [bind_tc_ok]
  rw [hindex]
  simp only [bind_tc_ok]
  rw [htable]
  simp only [bind_tc_ok, uncurry_apply_pair]
  obtain ⟨firstLo, firstHi, hfirst, hfirstProd, hfirstHi⟩ :=
    P661_T1_FullMultiplicationExecution w a
  rw [hfirst]
  simp only [bind_tc_ok, uncurry_apply_pair, lift]
  by_cases hrefine : firstHi &&& 511#u64 = 511#u64
  · rw [if_pos hrefine]
    obtain ⟨secondLo, secondHi, hsecond, hsecondProd, hsecondHi⟩ :=
      P661_T1_FullMultiplicationExecution w b
    rw [hsecond]
    simp only [bind_tc_ok, uncurry_apply_pair, lift]
    let added := core.num.U64.wrapping_add firstLo secondHi
    by_cases hcarry : added.val < secondHi.val
    · rw [if_pos hcarry]
      have hw64 : w.val < 2 ^ 64 := w.bv.isLt
      have ha64 : a.val < 2 ^ 64 := a.bv.isLt
      have hprod := Nat.mul_le_mul (Nat.le_pred_of_lt hw64)
        (Nat.le_pred_of_lt ha64)
      norm_num at hprod
      have hincBound : firstHi.val + (1#u64).val <= UScalar.max .U64 := by
        rw [hfirstHi]
        norm_num [UScalar.max, U64.max_eq, UScalarTy.numBits]
        omega
      obtain ⟨next, hnext, hnextval⟩ := WP.spec_imp_exists
        (UScalar.add_spec (x := firstHi) (y := 1#u64) hincBound)
      rw [hnext]
      exact ⟨added, next, rfl⟩
    · rw [if_neg hcarry]
      exact ⟨added, firstHi, rfl⟩
  · rw [if_neg hrefine]
    exact ⟨firstLo, firstHi, rfl⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P661_T1_FullMultiplicationExecution
import Tablet.IntegerPowerTableCertificate
import Tablet.num_imp_dec2flt_lemire_compute_product_approx

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_ProductApproximationExecution]
theorem P661_T1_ProductApproximationExecution (q : Std.I64) (w : Std.U64)
    (hqlo : -342 <= q.val) (hqhi : q.val <= 308) :
    exists lo hi : Std.U64,
      num.imp.dec2flt.lemire.compute_product_approx q w 55#usize = ok (lo, hi) := by
-- BODY
  obtain ⟨q32, p, delta, index, a, b, hq32, hp, hpval,
    hdelta, hindex, htable, hcert⟩ := IntegerPowerTableCertificate q hqlo hqhi
  unfold num.imp.dec2flt.lemire.compute_product_approx
  have hsmall : lift (IScalar.cast .I64
      num.imp.dec2flt.table.SMALLEST_POWER_OF_FIVE) = ok (-342)#i64 := by
    rw [num.imp.dec2flt.table.SMALLEST_POWER_OF_FIVE.eq_def]
    rfl
  have hlarge : lift (IScalar.cast .I64
      num.imp.dec2flt.table.LARGEST_POWER_OF_FIVE) = ok 308#i64 := by
    rw [num.imp.dec2flt.table.LARGEST_POWER_OF_FIVE.eq_def]
    rfl
  have hmask : 18446744073709551615#u64 >>> 55#usize = ok 511#u64 := by rfl
  rw [hsmall]
  simp only [bind_tc_ok, ge_iff_le, IScalar.le_equiv,
    show ((-342)#i64).val = -342 from rfl, hqlo, massert_True]
  rw [hlarge]
  simp only [bind_tc_ok, IScalar.le_equiv, show (308#i64).val = 308 from rfl,
    hqhi, massert_True, UScalar.le_equiv, UScalar.lt_equiv,
    UScalar.ofNatCore_val_eq, Nat.reduceLeDiff, Nat.reduceLT, if_true]
  rw [hmask]
  simp only [bind_tc_ok]
  rw [hdelta]
  simp only [bind_tc_ok]
  rw [hindex]
  simp only [bind_tc_ok]
  rw [htable]
  simp only [bind_tc_ok, uncurry_apply_pair]
  obtain ⟨firstLo, firstHi, hfirst, hfirstProd, hfirstHi⟩ :=
    P661_T1_FullMultiplicationExecution w a
  rw [hfirst]
  simp only [bind_tc_ok, uncurry_apply_pair, lift]
  by_cases hrefine : firstHi &&& 511#u64 = 511#u64
  · rw [if_pos hrefine]
    obtain ⟨secondLo, secondHi, hsecond, hsecondProd, hsecondHi⟩ :=
      P661_T1_FullMultiplicationExecution w b
    rw [hsecond]
    simp only [bind_tc_ok, uncurry_apply_pair, lift]
    let added := core.num.U64.wrapping_add firstLo secondHi
    by_cases hcarry : added.val < secondHi.val
    · rw [if_pos hcarry]
      have hw64 : w.val < 2 ^ 64 := w.bv.isLt
      have ha64 : a.val < 2 ^ 64 := a.bv.isLt
      have hprod := Nat.mul_le_mul (Nat.le_pred_of_lt hw64)
        (Nat.le_pred_of_lt ha64)
      norm_num at hprod
      have hincBound : firstHi.val + (1#u64).val <= UScalar.max .U64 := by
        rw [hfirstHi]
        norm_num [UScalar.max, U64.max_eq, UScalarTy.numBits]
        omega
      obtain ⟨next, hnext, hnextval⟩ := WP.spec_imp_exists
        (UScalar.add_spec (x := firstHi) (y := 1#u64) hincBound)
      rw [hnext]
      exact ⟨added, next, rfl⟩
    · rw [if_neg hcarry]
      exact ⟨added, firstHi, rfl⟩
  · rw [if_neg hrefine]
    exact ⟨firstLo, firstHi, rfl⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (50)
More program dependencies (17)
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 11 entries
Technical checking records
Local closure summary
{
  "node": "P661_T1_ProductApproximationExecution",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "8891621102c37b83fadb3ef3479f1ead5c9e4d091e286306235d1de29cfa1f63",
  "active_statement_hash": "61a562ac14fd100407e55655269ffc15da5efe1e7270c7229cb054066d34339d",
  "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-146",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "IntegerPowerTableCertificate": "c4b148e6d8bda215",
    "P661_T1_FullMultiplicationExecution": "3285270eabb1c0d2",
    "num_imp_dec2flt_lemire_compute_product_approx": "c004de0227baca74",
    "num_imp_dec2flt_table_LARGEST_POWER_OF_FIVE": "2532cbe447dc07c7",
    "num_imp_dec2flt_table_SMALLEST_POWER_OF_FIVE": "8a9e3dfa7e9aa5ec"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_lemire_compute_product_approx": "af91b9cbef7779f3",
    "num_imp_dec2flt_lemire_full_multiplication": "46682dcb8efbf576",
    "num_imp_dec2flt_lemire_power": "56b7c3bd69ca3c6a",
    "num_imp_dec2flt_table_LARGEST_POWER_OF_FIVE": "133d9b18714defd6",
    "num_imp_dec2flt_table_POWER_OF_FIVE_128": "bdd28e83b60fa362",
    "num_imp_dec2flt_table_SMALLEST_POWER_OF_FIVE": "5394ae3df8a14bc9"
  }
}
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:253a3697fdf9a5e3a74bb6ea8a3dd2c60389cc6fd0f73e22a016b3933ab03461",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}