P804_T1_SelectedLeftGrowth

Lean checked

Statement

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

Lemma · Digit growth for every selected left shift

Let d be a nonempty positive-leading decimal record with at most 768 retained decimal cells, and let 1\le n\le324. Run the literal slow-loop selector at n, obtaining k, and run the extracted left-shift digit-growth routine on d and k, obtaining g. Both calls return normally, k\le60, and
n\ge19\Longrightarrow g\in\{18,19\},\qquad n\le18\Longrightarrow g\in\{n-1,n\}.
These calls and alternatives are the conjunctions in the Lean statement.

Lean statement

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

import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.SlowShiftSelectorCertificate

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_SelectedLeftGrowth]
theorem P804_T1_SelectedLeftGrowth
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (n : Std.Usize)
    (hnLo : 1 <= n.val) (hnHi : n.val <= 324)
    (hinput :
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun q => q.val)
      d.num_digits.val <= 768 /\
      (forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10) /\
      (exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
        digits.length = d.num_digits.val)) :
    exists (shift growth : Std.Usize),
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift /\
      shift.val <= 60 /\
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d shift = ok growth /\
      (19 <= n.val -> growth.val = 18 \/ growth.val = 19) /\
      (n.val <= 18 -> growth.val = n.val - 1 \/ growth.val = n.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

Apply SlowShiftSelectorCertificate. If n\ge19, it says that k=60 and gives the strict bracket 10^{18}<2^{60}<10^{19}. Use h=19 in DecimalLeftShiftDigitGrowth. Its returned growth is, according to its threshold comparison, either h or h-1, hence either 19 or 18.
Suppose 1\le n\le18. The selector certificate gives its explicit table entry and the inequalities 2^k\le10^n<2^{k+1}. Checking the eighteen literal entries k=3,6,9,13,16,19,23,26,29,33,36,39,43,46,49,53,56,59 strengthens this to the strict bracket 10^{n-1}<2^k<10^n. (This is finite integer powering; the Lean proof checks each entry by normalization.) Apply DecimalLeftShiftDigitGrowth with h=n. Its threshold formula returns exactly n or n-1. The same selector certificate supplies k\le60, and the hypotheses on d are precisely the capacity and digit hypotheses of the growth theorem, so every claimed call and alternative follows.

Lean proof


  dsimp only at hinput
  rcases hinput with ⟨hcap, hdigit, hpositive⟩
  let shift : 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
  have hsel := SlowShiftSelectorCertificate
    F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n
  change
    num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift /\
      shift.val <= 60 /\ _ at hsel
  rcases hsel with ⟨hcall, hk, hzero, hsmall, hlarge⟩
  have hbracket : exists h : Nat,
      (h = 19 /\ 19 <= n.val \/ h = n.val /\ n.val <= 18) /\
      10 ^ (h - 1) < 2 ^ shift.val /\ 2 ^ shift.val < 10 ^ h := by
    by_cases hn19 : 19 <= n.val
    · rcases hlarge hn19 with ⟨hk60, hlo, hhi⟩
      have hk60' : shift.val = 60 := by simpa only [shift] using hk60
      refine ⟨19, Or.inl ⟨rfl, hn19⟩, ?_, ?_⟩
      · simpa only [Nat.reduceSub, hk60'] using hlo
      · simpa only [hk60'] using hhi
    · have hn18 : n.val <= 18 := by omega
      have hnCases : 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
      have hb : 10 ^ (n.val - 1) < 2 ^ shift.val /\
          2 ^ shift.val < 10 ^ n.val := by
        rcases hnCases with h | h | h | h | h | h | h | h | h |
          h | h | h | h | h | h | h | h | h
        all_goals simp [shift, h]
      exact ⟨n.val, Or.inr ⟨rfl, hn18⟩, hb.1, hb.2⟩
  rcases hbracket with ⟨h, hcase, hlo, hhi⟩
  obtain ⟨growth, hgrowth, hgrowthVal⟩ :=
    DecimalLeftShiftDigitGrowth d shift h hk hlo hhi hcap hdigit
  refine ⟨shift, growth, hcall, hk, hgrowth, ?_, ?_⟩
  · intro hn19
    rcases hcase with ⟨rfl, _⟩ | ⟨hh, hn18⟩
    · split at hgrowthVal <;> omega
    · omega
  · intro hn18
    rcases hcase with ⟨hh, hn19⟩ | ⟨rfl, _⟩
    · omega
    · split at hgrowthVal <;> omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.SlowShiftSelectorCertificate

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_SelectedLeftGrowth]
theorem P804_T1_SelectedLeftGrowth
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (n : Std.Usize)
    (hnLo : 1 <= n.val) (hnHi : n.val <= 324)
    (hinput :
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun q => q.val)
      d.num_digits.val <= 768 /\
      (forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10) /\
      (exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
        digits.length = d.num_digits.val)) :
    exists (shift growth : Std.Usize),
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift /\
      shift.val <= 60 /\
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d shift = ok growth /\
      (19 <= n.val -> growth.val = 18 \/ growth.val = 19) /\
      (n.val <= 18 -> growth.val = n.val - 1 \/ growth.val = n.val) := by
-- BODY
  dsimp only at hinput
  rcases hinput with ⟨hcap, hdigit, hpositive⟩
  let shift : 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
  have hsel := SlowShiftSelectorCertificate
    F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n
  change
    num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift /\
      shift.val <= 60 /\ _ at hsel
  rcases hsel with ⟨hcall, hk, hzero, hsmall, hlarge⟩
  have hbracket : exists h : Nat,
      (h = 19 /\ 19 <= n.val \/ h = n.val /\ n.val <= 18) /\
      10 ^ (h - 1) < 2 ^ shift.val /\ 2 ^ shift.val < 10 ^ h := by
    by_cases hn19 : 19 <= n.val
    · rcases hlarge hn19 with ⟨hk60, hlo, hhi⟩
      have hk60' : shift.val = 60 := by simpa only [shift] using hk60
      refine ⟨19, Or.inl ⟨rfl, hn19⟩, ?_, ?_⟩
      · simpa only [Nat.reduceSub, hk60'] using hlo
      · simpa only [hk60'] using hhi
    · have hn18 : n.val <= 18 := by omega
      have hnCases : 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
      have hb : 10 ^ (n.val - 1) < 2 ^ shift.val /\
          2 ^ shift.val < 10 ^ n.val := by
        rcases hnCases with h | h | h | h | h | h | h | h | h |
          h | h | h | h | h | h | h | h | h
        all_goals simp [shift, h]
      exact ⟨n.val, Or.inr ⟨rfl, hn18⟩, hb.1, hb.2⟩
  rcases hbracket with ⟨h, hcase, hlo, hhi⟩
  obtain ⟨growth, hgrowth, hgrowthVal⟩ :=
    DecimalLeftShiftDigitGrowth d shift h hk hlo hhi hcap hdigit
  refine ⟨shift, growth, hcall, hk, hgrowth, ?_, ?_⟩
  · intro hn19
    rcases hcase with ⟨rfl, _⟩ | ⟨hh, hn18⟩
    · split at hgrowthVal <;> omega
    · omega
  · intro hn18
    rcases hcase with ⟨hh, hn19⟩ | ⟨rfl, _⟩
    · omega
    · split at hgrowthVal <;> omega

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 87 entries
Technical checking records
Local closure summary
{
  "node": "P804_T1_SelectedLeftGrowth",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "d764c663c0cb2159f7369d0a6549be41c0e0553aead20d16ed9377d2d6025d8e",
  "active_statement_hash": "2c6b9949fd545a87d2308c0d198f758125f3b5bdd99fd86f24aa6354c8b57653",
  "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": "revalidate-cycle-189",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalLeftShiftDigitGrowth": "6dcf8858df4713eb",
    "SlowShiftSelectorCertificate": "963b7a2e670856e8"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "SlowShiftSelectorCertificate": "7ebc2b39d69850c4",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
    "num_imp_dec2flt_decimal_seq_number_of_digits_decimal_left_shift": "b3efbd0e6b3fe061",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790"
  }
}
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:6a9a61a99949613951c3a5df4a8de43a391086e9eadd77b990efe05d0d802f35",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}