SlowShiftSelectorCertificate

Lean checked

Statement

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

Helper · Exact slow-normalization selector certificate

For every machine-size natural input n, the extracted slow-normalization closure returns the literal machine-size value k(n) given by
\begin{array}{c|rrrrrrrrrrrrrrrrrrr} n&0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18\\ \hline k(n)&0&3&6&9&13&16&19&23&26&29&33&36&39&43&46&49&53&56&59, \end{array}
and it returns k(n)=60 for n\geq19. Always k(n)\leq60. At zero, k(0)=0; for every 1\leq n\leq18,
2^{k(n)}\leq10^n<2^{k(n)+1}; \tag{1}
and on the fallback branch
10^{18}<2^{60}<10^{19}. \tag{2}
The Lean statement includes the exact successful extracted closure-call equation as well as these bounds.

Lean statement

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

import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_NUM_POWERS
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_POWERS
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: SlowShiftSelectorCertificate]
theorem SlowShiftSelectorCertificate :
    forall {F Clause0_Int : Type}
      (traitsFloatInst : num.imp.traits.Float F Clause0_Int)
      (n : Std.Usize),
      let k : Std.Usize := match n.val with
        | 0 => 0#usize | 1 => 3#usize | 2 => 6#usize | 3 => 9#usize
        | 4 => 13#usize | 5 => 16#usize | 6 => 19#usize | 7 => 23#usize
        | 8 => 26#usize | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
        | 12 => 39#usize | 13 => 43#usize | 14 => 46#usize | 15 => 49#usize
        | 16 => 53#usize | 17 => 56#usize | 18 => 59#usize | _ => 60#usize
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
          traitsFloatInst () n = ok k /\
      k.val <= 60 /\
      (n.val = 0 -> k.val = 0) /\
      (1 <= n.val -> n.val <= 18 ->
        2 ^ k.val <= 10 ^ n.val /\ 10 ^ n.val < 2 ^ (k.val + 1)) /\
      (19 <= n.val ->
        k.val = 60 /\ 10 ^ 18 < 2 ^ 60 /\ 2 ^ 60 < 10 ^ 19) := 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 extracted closure call num imp dec2flt slow parse long mantissa closure Insts CoreOpsFunctionFnTupleUsizeUsize call. By num imp dec2flt slow parse long mantissa NUM POWERS, its branch test is exactly n<19. In that branch, the array in num imp dec2flt slow parse long mantissa POWERS has length 19 and has, at indices 0 through 18, exactly the entries displayed in the statement. Hence the fixed-array access is in bounds, its U8-to-Usize cast is exact, and the call returns the displayed k(n). If n\geq19, the other branch returns the machine value 60 by num imp dec2flt slow parse long mantissa MAX SHIFT. This proves the call equation, the literal table, and k(n)\leq60.
It remains only finite natural-number arithmetic. At n=0 the entry is zero. For n=1,\ldots,18, substituting respectively
3,6,9,13,16,19,23,26,29,33,36,39,43,46,49,53,56,59
and evaluating integer powers gives (1) in each of the eighteen cases. For example, the two comparisons are comparisons of natural numerals, with no rounding or logarithms involved. On the fallback branch, direct integer powering gives
10^{18}=1000000000000000000 <1152921504606846976=2^{60} <10000000000000000000=10^{19},
which is (2). Thus every clause follows by exhaustive evaluation of the literal extracted data.

Lean proof


  intro F Clause0_Int traitsFloatInst n
  dsimp
  simp only [num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call]
  rw [num.imp.dec2flt.slow.parse_long_mantissa.NUM_POWERS.eq_def,
    num.imp.dec2flt.slow.parse_long_mantissa.POWERS.eq_def,
    num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT.eq_def]
  by_cases small : n.val < 19
  · have cases : n.val = 0 ∨ n.val = 1 ∨ n.val = 2 ∨ n.val = 3 ∨
        n.val = 4 ∨ n.val = 5 ∨ n.val = 6 ∨ n.val = 7 ∨
        n.val = 8 ∨ n.val = 9 ∨ n.val = 10 ∨ n.val = 11 ∨
        n.val = 12 ∨ n.val = 13 ∨ n.val = 14 ∨ n.val = 15 ∨
        n.val = 16 ∨ n.val = 17 ∨ n.val = 18 := by omega
    rcases cases with h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h
    all_goals
      simp [Array.make, Array.index_usize, h]
      apply UScalar.eq_imp
      norm_num [UScalar.cast_val_eq]
  · change ¬ n.val < 19 at small
    have large : 19 ≤ n.val := by omega
    have normal : n.val = (n.val - 19) + 19 := by omega
    rw [normal]
    have branch : ¬ n < 19#usize := by
      change ¬ n.val < 19
      omega
    simp [Array.index_usize, branch]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_NUM_POWERS
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_POWERS
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: SlowShiftSelectorCertificate]
theorem SlowShiftSelectorCertificate :
    forall {F Clause0_Int : Type}
      (traitsFloatInst : num.imp.traits.Float F Clause0_Int)
      (n : Std.Usize),
      let k : Std.Usize := match n.val with
        | 0 => 0#usize | 1 => 3#usize | 2 => 6#usize | 3 => 9#usize
        | 4 => 13#usize | 5 => 16#usize | 6 => 19#usize | 7 => 23#usize
        | 8 => 26#usize | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
        | 12 => 39#usize | 13 => 43#usize | 14 => 46#usize | 15 => 49#usize
        | 16 => 53#usize | 17 => 56#usize | 18 => 59#usize | _ => 60#usize
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
          traitsFloatInst () n = ok k /\
      k.val <= 60 /\
      (n.val = 0 -> k.val = 0) /\
      (1 <= n.val -> n.val <= 18 ->
        2 ^ k.val <= 10 ^ n.val /\ 10 ^ n.val < 2 ^ (k.val + 1)) /\
      (19 <= n.val ->
        k.val = 60 /\ 10 ^ 18 < 2 ^ 60 /\ 2 ^ 60 < 10 ^ 19) := by
-- BODY
  intro F Clause0_Int traitsFloatInst n
  dsimp
  simp only [num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call]
  rw [num.imp.dec2flt.slow.parse_long_mantissa.NUM_POWERS.eq_def,
    num.imp.dec2flt.slow.parse_long_mantissa.POWERS.eq_def,
    num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT.eq_def]
  by_cases small : n.val < 19
  · have cases : n.val = 0 ∨ n.val = 1 ∨ n.val = 2 ∨ n.val = 3 ∨
        n.val = 4 ∨ n.val = 5 ∨ n.val = 6 ∨ n.val = 7 ∨
        n.val = 8 ∨ n.val = 9 ∨ n.val = 10 ∨ n.val = 11 ∨
        n.val = 12 ∨ n.val = 13 ∨ n.val = 14 ∨ n.val = 15 ∨
        n.val = 16 ∨ n.val = 17 ∨ n.val = 18 := by omega
    rcases cases with h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h | h
    all_goals
      simp [Array.make, Array.index_usize, h]
      apply UScalar.eq_imp
      norm_num [UScalar.cast_val_eq]
  · change ¬ n.val < 19 at small
    have large : 19 ≤ n.val := by omega
    have normal : n.val = (n.val - 19) + 19 := by omega
    rw [normal]
    have branch : ¬ n < 19#usize := by
      change ¬ n.val < 19
      omega
    simp [Array.index_usize, branch]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (49)
More program dependencies (16)
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 16 entries
Technical checking records
Local closure summary
{
  "node": "SlowShiftSelectorCertificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "9e6d4c82a5eb91d468d39b4463365f8dab54444225403b39e77c2a2856a7227f",
  "active_statement_hash": "e085991640570f4b373b00638f4f1921848962bc72785674a251bfdfce1fb56f",
  "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": "sidecar-sc-20261005-102107-68fc93-SlowShiftSelectorCertificate-cycle-180",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "a858290d96a26cbd",
    "num_imp_dec2flt_slow_parse_long_mantissa_NUM_POWERS": "6886acab8f15b99e",
    "num_imp_dec2flt_slow_parse_long_mantissa_POWERS": "6886acab8f15b99e",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "6886acab8f15b99e"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "32f403f33bee78a7",
    "num_imp_dec2flt_slow_parse_long_mantissa_NUM_POWERS": "5969fcec51b40196",
    "num_imp_dec2flt_slow_parse_long_mantissa_POWERS": "3b3dc92c505e8aac",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure": "658171309af8dc0e",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790",
    "num_imp_traits_Float": "94ab5f784cdf5db8"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:7d4db028086e35079ac301bcb208609dcb6a8f2ce1c5d106c9482ad04ed61866",
  "current_fingerprint": "sound-v2:7d4db028086e35079ac301bcb208609dcb6a8f2ce1c5d106c9482ad04ed61866",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}