Binary64Pow10FastPathExact

Lean checked

Statement

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

Lemma

For every platform index i\leq22, the extracted binary64 pow10_fast_path call returns normally with a finite positive raw word whose binary64 finite-magnitude decoding is exactly the rational number 10^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.Binary64ModelDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path
import Tablet.ModelF64FromBits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 100000

namespace dec2flt_model

-- [TABLET NODE: Binary64Pow10FastPathExact]
theorem Binary64Pow10FastPathExact :
    ∀ i : Std.Usize, i.val ≤ 22 →
      ∃ p : F64,
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path i = ok p ∧
        p.val < 0x7ff0000000000000 ∧
        (let bits := p.val
         let e := bits / (2 ^ 52 : Nat)
         let m := bits % (2 ^ 52 : Nat)
         let decoded : Rat := 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)
         decoded = (10 : Rat) ^ i.val) := 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

Unfold F64 Insts Dec2flt modelNumImpDec2fltLemireU64 pow10 fast path. Since i<32, masking the index by 31 leaves it unchanged. There are then exactly the 23 displayed branches numbered 0 through 22. In each branch, ModelF64FromBits returns the displayed raw word without alteration. Direct quotient and remainder by 2^{52} split that constant into its binary64 exponent and fraction fields. Substitution in the normal finite decoder gives respectively 1,10,100,\ldots,10^{22}; these are exact integer calculations. Every displayed word is also strictly below the infinity word 0x7ff0000000000000, proving finiteness.

Lean proof


  intro i hi
  unfold F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path
  have mask_eq : i &&& 31#usize = i := by
    apply UScalar.eq_of_val_eq
    simp only [UScalar.val_and]
    change i.val &&& 31 = i.val
    rw [show (31 : Nat) = 2 ^ 5 - 1 by norm_num, Nat.and_two_pow_sub_one_eq_mod]
    exact Nat.mod_eq_of_lt (by omega)
  have cases :
      i.val = 0 ∨ i.val = 1 ∨ i.val = 2 ∨ i.val = 3 ∨ i.val = 4 ∨
      i.val = 5 ∨ i.val = 6 ∨ i.val = 7 ∨ i.val = 8 ∨ i.val = 9 ∨
      i.val = 10 ∨ i.val = 11 ∨ i.val = 12 ∨ i.val = 13 ∨ i.val = 14 ∨
      i.val = 15 ∨ i.val = 16 ∨ i.val = 17 ∨ i.val = 18 ∨ i.val = 19 ∨
      i.val = 20 ∨ i.val = 21 ∨ i.val = 22 := by omega
  rcases cases with h | h | h | h | h | h | h | h | h | h | h | h | h | h | h |
    h | h | h | h | h | h | h | h <;>
    simp [h, Aeneas.Std.lift, mask_eq, core.f64.F64.from_bits,
      ModelF64FromBits] <;>
    refine ⟨_, rfl, by norm_num, ?_⟩ <;>
    norm_num

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Binary64ModelDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path
import Tablet.ModelF64FromBits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 100000

namespace dec2flt_model

-- [TABLET NODE: Binary64Pow10FastPathExact]
theorem Binary64Pow10FastPathExact :
    ∀ i : Std.Usize, i.val ≤ 22 →
      ∃ p : F64,
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path i = ok p ∧
        p.val < 0x7ff0000000000000 ∧
        (let bits := p.val
         let e := bits / (2 ^ 52 : Nat)
         let m := bits % (2 ^ 52 : Nat)
         let decoded : Rat := 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)
         decoded = (10 : Rat) ^ i.val) := by
-- BODY
  intro i hi
  unfold F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path
  have mask_eq : i &&& 31#usize = i := by
    apply UScalar.eq_of_val_eq
    simp only [UScalar.val_and]
    change i.val &&& 31 = i.val
    rw [show (31 : Nat) = 2 ^ 5 - 1 by norm_num, Nat.and_two_pow_sub_one_eq_mod]
    exact Nat.mod_eq_of_lt (by omega)
  have cases :
      i.val = 0 ∨ i.val = 1 ∨ i.val = 2 ∨ i.val = 3 ∨ i.val = 4 ∨
      i.val = 5 ∨ i.val = 6 ∨ i.val = 7 ∨ i.val = 8 ∨ i.val = 9 ∨
      i.val = 10 ∨ i.val = 11 ∨ i.val = 12 ∨ i.val = 13 ∨ i.val = 14 ∨
      i.val = 15 ∨ i.val = 16 ∨ i.val = 17 ∨ i.val = 18 ∨ i.val = 19 ∨
      i.val = 20 ∨ i.val = 21 ∨ i.val = 22 := by omega
  rcases cases with h | h | h | h | h | h | h | h | h | h | h | h | h | h | h |
    h | h | h | h | h | h | h | h <;>
    simp [h, Aeneas.Std.lift, mask_eq, core.f64.F64.from_bits,
      ModelF64FromBits] <;>
    refine ⟨_, rfl, by norm_num, ?_⟩ <;>
    norm_num

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 31 entries
Technical checking records
Local closure summary
{
  "node": "Binary64Pow10FastPathExact",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f3fdd0b5992913a5864e4a91b1a8afd7c62e39064cc03f6bb8e3794f32e2cf00",
  "active_statement_hash": "cb20446aa6d238f63658dabafafc12c3cca03db3169ced003b1e73e695950e4b",
  "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": {
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path": "440c195c8d8c288d"
  },
  "strict_definition_deps": {
    "Binary64Model": "6a9c5e87dde4352b",
    "Binary64ModelDefault": "47013ebe5c83894c",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path": "7494bd35549bb33e",
    "ModelF64FromBits": "ff88211b2f4e3b25",
    "Preamble": "365e22a97907c302"
  }
}
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:0244cfb03e5576610bdd4f71c97adbf3d48ea61110c10dba717e900dd0854f3b",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}