IntegerPowerFiniteCertificate

Lean checked

Statement

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

Helper · Finite power-table certificate

For every j\in\{0,\ldots,650\} put q=j-342 and e=\lfloor217706q/65536\rfloor-q. Casting q to a signed 32-bit integer and running the extracted power routine succeeds with value \lfloor217706q/65536\rfloor+63. If (a,b) is entry j of the extracted table and D=a2^{64}+b, the following integer facts hold.
If q<0, put n=-q and z=-e. Then n,z\ge1, 2^{z-1}<5^n<2^z, and
\begin{array}{ll} D5^n\le2^{z+127}<(D+1)5^n,&q<-27,\\ (D-1)5^n<2^{z+127}<D5^n,&-27\le q<0. \end{array}
If q\ge0, then e\ge0 and 2^e\le5^q<2^{e+1}. For e\le127 one has D=5^q2^{127-e}, while for e>127 one has
D2^{e-127}\le5^q<(D+1)2^{e-127}.
In addition, q\le55 implies the displayed exact formula for D, q\le23 implies b=0, and throughout this index range q\le55 implies e\le127.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.num_imp_dec2flt_lemire_power
import Tablet.num_imp_dec2flt_table_POWER_OF_FIVE_128

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

namespace dec2flt_model

-- [TABLET NODE: IntegerPowerFiniteCertificate]
theorem IntegerPowerFiniteCertificate :
    (∀ j : Fin 651,
      let q : Int := j.val - 342
      let q32 : Std.I32 := IScalar.ofInt q (by
        change -(2 : Int) ^ 31 ≤ (j.val : Int) - 342 ∧
          (j.val : Int) - 342 ≤ (2 : Int) ^ 31 - 1
        omega)
      (match num.imp.dec2flt.lemire.power q32 with
      | ok p => decide (p.val = 217706 * q / 65536 + 63)
      | fail _ => false
      | div => false) = true) ∧
    (∀ j : Fin 651,
      let table := num.imp.dec2flt.table.POWER_OF_FIVE_128
      let ab := table.val.get ⟨j.val, by simpa using j.isLt⟩
      let a := ab.1
      let b := ab.2
      let q : Int := j.val - 342
      let e : Int := 217706 * q / 65536 - q
      let D : Nat := a.val * 2 ^ 64 + b.val
      (q < 0 →
        let n := (-q).toNat
        let z := (-e).toNat
        q = -(n : Int) ∧ 1 ≤ n ∧ 1 ≤ z ∧
        2 ^ (z - 1) < 5 ^ n ∧ 5 ^ n < 2 ^ z ∧ e = -(z : Int) ∧
        (q < -27 → D * 5 ^ n ≤ 2 ^ (z + 127) ∧
          2 ^ (z + 127) < (D + 1) * 5 ^ n) ∧
        (-27 ≤ q → (D - 1) * 5 ^ n < 2 ^ (z + 127) ∧
          2 ^ (z + 127) < D * 5 ^ n)) ∧
      (0 ≤ q →
        0 ≤ e ∧
        2 ^ e.toNat ≤ 5 ^ q.toNat ∧ 5 ^ q.toNat < 2 ^ (e.toNat + 1) ∧
        (e ≤ 127 → D = 5 ^ q.toNat * 2 ^ (127 - e).toNat) ∧
        (127 < e → D * 2 ^ (e - 127).toNat ≤ 5 ^ q.toNat ∧
          5 ^ q.toNat < (D + 1) * 2 ^ (e - 127).toNat) ∧
        (q ≤ 55 → D = 5 ^ q.toNat * 2 ^ (127 - e).toNat) ∧
        (q ≤ 23 → b.val = 0))) ∧
    (∀ j : Fin 651,
      let q : Int := j.val - 342
      let e : Int := 217706 * q / 65536 - q
      q ≤ 55 → e ≤ 127) := 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

There are exactly 651 values of the finite index. Unfold num imp dec2flt table POWER OF FIVE 128 once and evaluate the three decidable integer propositions for every index. For the first proposition, evaluation unfolds num imp dec2flt lemire power; it checks the wrapping product, signed shift by 16, and final checked addition, and compares the returned signed value with \lfloor217706q/65536\rfloor+63. The match is required to return true, so a failure or divergence result cannot satisfy the certificate.
For the second proposition, evaluation reads entry j directly from the single unfolded table, forms D=a2^{64}+b, and uses exact natural-number multiplication, exponentiation, comparison, and Euclidean integer division. It separately checks the negative and nonnegative implications, including both directed cross-product inequalities and the two small-range clauses. The third finite pass checks the fixed-point bound e\le127 for every q\le55. Lean's kernel reduces each Boolean decision for all inhabitants of Fin 651; no native evaluator or unproved arithmetic fact is used. Consequently all quantified conclusions in the statement hold.

Lean proof


  constructor
  · decide +kernel
  constructor
  · rw [num.imp.dec2flt.table.POWER_OF_FIVE_128.eq_def]
    decide +kernel
  · decide +kernel

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.num_imp_dec2flt_lemire_power
import Tablet.num_imp_dec2flt_table_POWER_OF_FIVE_128

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

namespace dec2flt_model

-- [TABLET NODE: IntegerPowerFiniteCertificate]
theorem IntegerPowerFiniteCertificate :
    (∀ j : Fin 651,
      let q : Int := j.val - 342
      let q32 : Std.I32 := IScalar.ofInt q (by
        change -(2 : Int) ^ 31 ≤ (j.val : Int) - 342 ∧
          (j.val : Int) - 342 ≤ (2 : Int) ^ 31 - 1
        omega)
      (match num.imp.dec2flt.lemire.power q32 with
      | ok p => decide (p.val = 217706 * q / 65536 + 63)
      | fail _ => false
      | div => false) = true) ∧
    (∀ j : Fin 651,
      let table := num.imp.dec2flt.table.POWER_OF_FIVE_128
      let ab := table.val.get ⟨j.val, by simpa using j.isLt⟩
      let a := ab.1
      let b := ab.2
      let q : Int := j.val - 342
      let e : Int := 217706 * q / 65536 - q
      let D : Nat := a.val * 2 ^ 64 + b.val
      (q < 0 →
        let n := (-q).toNat
        let z := (-e).toNat
        q = -(n : Int) ∧ 1 ≤ n ∧ 1 ≤ z ∧
        2 ^ (z - 1) < 5 ^ n ∧ 5 ^ n < 2 ^ z ∧ e = -(z : Int) ∧
        (q < -27 → D * 5 ^ n ≤ 2 ^ (z + 127) ∧
          2 ^ (z + 127) < (D + 1) * 5 ^ n) ∧
        (-27 ≤ q → (D - 1) * 5 ^ n < 2 ^ (z + 127) ∧
          2 ^ (z + 127) < D * 5 ^ n)) ∧
      (0 ≤ q →
        0 ≤ e ∧
        2 ^ e.toNat ≤ 5 ^ q.toNat ∧ 5 ^ q.toNat < 2 ^ (e.toNat + 1) ∧
        (e ≤ 127 → D = 5 ^ q.toNat * 2 ^ (127 - e).toNat) ∧
        (127 < e → D * 2 ^ (e - 127).toNat ≤ 5 ^ q.toNat ∧
          5 ^ q.toNat < (D + 1) * 2 ^ (e - 127).toNat) ∧
        (q ≤ 55 → D = 5 ^ q.toNat * 2 ^ (127 - e).toNat) ∧
        (q ≤ 23 → b.val = 0))) ∧
    (∀ j : Fin 651,
      let q : Int := j.val - 342
      let e : Int := 217706 * q / 65536 - q
      q ≤ 55 → e ≤ 127) := by
-- BODY
  constructor
  · decide +kernel
  constructor
  · rw [num.imp.dec2flt.table.POWER_OF_FIVE_128.eq_def]
    decide +kernel
  · decide +kernel

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (46)
More program dependencies (13)
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
Technical checking records
Local closure summary
{
  "node": "IntegerPowerFiniteCertificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "e1fd7a52879924525cfe2c47bff7a72673e0087168ba22b5cf5d04b6a8e87c40",
  "active_statement_hash": "a10f8bcabff22e2a3f68827c9ee7c8e6f9db869dd53bc1937b7c62cc0578582c",
  "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-145",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "num_imp_dec2flt_table_POWER_OF_FIVE_128": "1190913ff1c52659"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_lemire_power": "56b7c3bd69ca3c6a",
    "num_imp_dec2flt_table_POWER_OF_FIVE_128": "bdd28e83b60fa362"
  }
}
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:a225e95626c5b92d2ae4b77bdd00259e1fef2ad5d7b0859ffcac3de5a97470a4",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}