Binary64FastPathGuard

Lean checked

Statement

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

Lemma

For every decimal record, the selected fast-path guard returns normally. Its Boolean result is true exactly when the exponent lies in [-22,37], the mantissa is at most 2^{53}, and many_digits is false.

Lean statement

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

import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_DISGUISED_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: Binary64FastPathGuard]
theorem Binary64FastPathGuard :
    ∀ d : num.imp.dec2flt.decimal.Decimal,
      ∃ b : Bool,
        num.imp.dec2flt.decimal.Decimal.can_use_fast_path
          F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 d = ok b ∧
        (b = true ↔ (-22 : Int) ≤ d.exponent.val ∧ d.exponent.val ≤ 37 ∧
          d.mantissa.val ≤ 2 ^ 53 ∧ d.many_digits = false) := 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 the selected Lemire implementation F64 Insts Dec2flt modelNumImpDec2fltLemireU64. Its ordinary and disguised maximum-exponent constants are respectively 22 and 37, by F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT FAST PATH and F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT DISGUISED FAST PATH. Checked negation of 22 succeeds and gives the minimum -22.
The significand-bit constant is 53 by F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS; shifting the unsigned word one left by 53 is in range and gives 2^{53}. Substitute these three successful constant computations into num imp dec2flt decimal Decimal can use fast path. Its nested tests return false as soon as one numerical bound fails. If all three hold, it returns Boolean negation of many_digits, which is true exactly when that field is false. These exhaustive cases prove both normal return and the stated equivalence.

Lean proof


  intro d
  have hmax22 :
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_FAST_PATH =
        22#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_FAST_PATH.eq_def]
  have hmax37 :
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_DISGUISED_FAST_PATH =
        37#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_DISGUISED_FAST_PATH.eq_def]
  have hminField :
      (F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 :
        num.imp.dec2flt.Lemire F64 Std.U64).MIN_EXPONENT_FAST_PATH =
        ok (-22)#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.eq_def]
    change (do
      let i ← ok
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_FAST_PATH
      HNeg.hNeg i) = ok (-22)#i64
    rw [hmax22]
    rfl
  have hmax37Field :
      (F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 :
        num.imp.dec2flt.Lemire F64 Std.U64).MAX_EXPONENT_DISGUISED_FAST_PATH =
        ok 37#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.eq_def, hmax37]
  have hmaxMantissaField :
      (F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 :
        num.imp.dec2flt.Lemire F64 Std.U64).MAX_MANTISSA_FAST_PATH =
        ok 9007199254740992#u64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.eq_def]
    change (do
      let i ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
      1#u64 <<< i) = ok 9007199254740992#u64
    rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS.eq_def]
    rfl
  unfold num.imp.dec2flt.decimal.Decimal.can_use_fast_path
  rw [hminField, hmax37Field, hmaxMantissaField]
  simp
  by_cases hmin : (-22 : Int) ≤ d.exponent.val <;>
    by_cases hmax : d.exponent.val ≤ 37 <;>
      by_cases hmant : d.mantissa.val ≤ 2 ^ 53 <;>
        cases d.many_digits <;> simp_all

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_DISGUISED_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: Binary64FastPathGuard]
theorem Binary64FastPathGuard :
    ∀ d : num.imp.dec2flt.decimal.Decimal,
      ∃ b : Bool,
        num.imp.dec2flt.decimal.Decimal.can_use_fast_path
          F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 d = ok b ∧
        (b = true ↔ (-22 : Int) ≤ d.exponent.val ∧ d.exponent.val ≤ 37 ∧
          d.mantissa.val ≤ 2 ^ 53 ∧ d.many_digits = false) := by
-- BODY
  intro d
  have hmax22 :
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_FAST_PATH =
        22#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_FAST_PATH.eq_def]
  have hmax37 :
      F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_DISGUISED_FAST_PATH =
        37#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_DISGUISED_FAST_PATH.eq_def]
  have hminField :
      (F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 :
        num.imp.dec2flt.Lemire F64 Std.U64).MIN_EXPONENT_FAST_PATH =
        ok (-22)#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.eq_def]
    change (do
      let i ← ok
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.MAX_EXPONENT_FAST_PATH
      HNeg.hNeg i) = ok (-22)#i64
    rw [hmax22]
    rfl
  have hmax37Field :
      (F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 :
        num.imp.dec2flt.Lemire F64 Std.U64).MAX_EXPONENT_DISGUISED_FAST_PATH =
        ok 37#i64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.eq_def, hmax37]
  have hmaxMantissaField :
      (F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64 :
        num.imp.dec2flt.Lemire F64 Std.U64).MAX_MANTISSA_FAST_PATH =
        ok 9007199254740992#u64 := by
    rw [F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.eq_def]
    change (do
      let i ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
      1#u64 <<< i) = ok 9007199254740992#u64
    rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS.eq_def]
    rfl
  unfold num.imp.dec2flt.decimal.Decimal.can_use_fast_path
  rw [hminField, hmax37Field, hmaxMantissaField]
  simp
  by_cases hmin : (-22 : Int) ≤ d.exponent.val <;>
    by_cases hmax : d.exponent.val ≤ 37 <;>
      by_cases hmant : d.mantissa.val ≤ 2 ^ 53 <;>
        cases d.many_digits <;> simp_all

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (89)
More program dependencies (47)
Standard-library dependencies (39)

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 85 entries
Technical checking records
Local closure summary
{
  "node": "Binary64FastPathGuard",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "3c7d2ca85a15500b5330dda048f2417f0fd1a2e7523e306dd74f325dfd413afd",
  "active_statement_hash": "546a9d5b2a26ee7b684fec84ac4df280d699f6ed348bf330afd586a556d35efb",
  "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_MAX_EXPONENT_DISGUISED_FAST_PATH": "394b9257cd714abf",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH": "6bf5ea9f18f5e8dc",
    "num_imp_dec2flt_Lemire_MAX_MANTISSA_FAST_PATH_default": "32d9110750ebf062"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_DISGUISED_FAST_PATH": "238680a0d0ed48da",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH": "c8b07a02533b83c6",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path": "c0ce6fdd5caeca22",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "Preamble": "1f712bede6a5dae6",
    "num_imp_dec2flt_Lemire": "cf15206a4202872c",
    "num_imp_dec2flt_decimal_Decimal": "fe99f3f976739f2d",
    "num_imp_dec2flt_decimal_Decimal_can_use_fast_path": "11145d187f88b02e",
    "num_imp_traits_Float": "22e97e73b1292e80",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
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:d3465ff422bb82e18b066166e3d176b36b313b492c2dd2a6c8fa57b4e9f02195",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}