P804_T1_PointMinusOneGrowth

Lean checked

Statement

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

Lemma · Forced growth from a large leading digit at point minus one

Let a nonempty decimal record have leading digit z\ge7, at most 768 retained cells, and decimal cells throughout. For shift three, the extracted left-shift digit-growth routine returns normally and returns growth one.

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.P804_T1_DecimalLeadingInterval

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_PointMinusOneGrowth]
theorem P804_T1_PointMinusOneGrowth
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (z : Nat) (zs : List Nat)
    (hcap : d.num_digits.val <= 768)
    (hdigit : forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10)
    (hshape :
      (d.digits.val.take d.num_digits.val).map (fun q => q.val) = z :: zs)
    (hz : 7 <= z) :
    exists growth : Std.Usize,
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d 3#usize = ok growth /\ growth.val = 1 := 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

Put n for the retained length and I for the base-ten fold. By DecimalLeadingInterval, or equivalently by the positional expansion of the fold,
I\ge z10^{n-1}\ge7\,10^{n-1}.
Consequently I2^3\ge56\,10^{n-1}\ge10^n. The bracket 1<2^3<10 permits applying DecimalLeftShiftDigitGrowth with h=1. Its exact threshold formula returns one precisely when 10^n\le I2^3, which is the inequality just proved. The capacity hypothesis identifies the length of the taken digit list with the retained count, so the threshold is exactly the one used by the extracted routine.

Lean proof


  have hdin : forall q,
      q ∈ (d.digits.val.take d.num_digits.val).map (fun q => q.val) ->
      q < 10 := by
    intro q hq
    simp only [List.mem_map] at hq
    rcases hq with ⟨u, hu, rfl⟩
    exact hdigit u hu
  obtain ⟨growth, hgrowth, hgrowthVal⟩ :=
    DecimalLeftShiftDigitGrowth d 3#usize 1 (by norm_num) (by norm_num)
      (by norm_num) hcap hdigit
  let xs := (d.digits.val.take d.num_digits.val).map (fun q => q.val)
  have hlead := P804_T1_DecimalLeadingInterval xs z zs
    (by simpa [xs] using hshape) (by omega) (by simpa [xs] using hdin)
      (xs.length : Int)
  dsimp only at hlead
  have hnpos : 1 <= xs.length := by simp [xs, hshape]
  have hexp : (xs.length : Int) - 1 = ((xs.length - 1 : Nat) : Int) := by
    rw [Nat.cast_sub hnpos]
    norm_num
  have hIlowerR : (z : Real) * (10 : Real) ^ (xs.length - 1) <=
      (xs.foldl (fun a q => 10 * a + q) 0 : Nat) := by
    simpa only [sub_self, zpow_zero, mul_one, hexp, zpow_natCast] using hlead.1
  have hIlower : z * 10 ^ (xs.length - 1) <=
      xs.foldl (fun a q => 10 * a + q) 0 := by
    exact_mod_cast hIlowerR
  have hlen : xs.length = d.num_digits.val := by
    have h := congrArg List.length hshape
    simp only [List.length_map, List.length_take, d.digits.property,
      List.length_cons] at h
    norm_num at h
    rw [Nat.min_eq_left hcap] at h
    rw [show xs = z :: zs by simpa [xs] using hshape]
    simpa using h.symm
  have hthreshold : 10 ^ d.num_digits.val <=
      ((d.digits.val.take d.num_digits.val).map (fun q => q.val)).foldl
        (fun a q => 10 * a + q) 0 * 2 ^ (3#usize : Std.Usize).val := by
    change 10 ^ d.num_digits.val <= xs.foldl (fun a q => 10 * a + q) 0 * 8
    rw [← hlen]
    have hpow : 10 ^ xs.length = 10 ^ (xs.length - 1) * 10 := by
      calc
        10 ^ xs.length = 10 ^ ((xs.length - 1) + 1) := by congr 1 <;> omega
        _ = 10 ^ (xs.length - 1) * 10 := by rw [pow_succ]
    rw [hpow]
    nlinarith
  refine ⟨growth, hgrowth, ?_⟩
  rw [hgrowthVal]
  have hthreshold' : 10 ^ (d.num_digits.val + 1 - 1) <=
      ((d.digits.val.map (fun q => q.val)).take d.num_digits.val).foldl
        (fun a q => 10 * a + q) 0 * 2 ^ (3#usize : Std.Usize).val := by
    simpa only [Nat.add_sub_cancel, List.map_take] using hthreshold
  split
  · rfl
  · rename_i h
    have hthreshold0 : 10 ^ (d.num_digits.val + 1 - 1) <=
        ((d.digits.val.take d.num_digits.val).map (fun q => q.val)).foldl
          (fun a q => 10 * a + q) 0 * 2 ^ (3#usize : Std.Usize).val := by
      simpa only [Nat.add_sub_cancel] using hthreshold
    exact False.elim (h hthreshold0)

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.P804_T1_DecimalLeadingInterval

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_PointMinusOneGrowth]
theorem P804_T1_PointMinusOneGrowth
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (z : Nat) (zs : List Nat)
    (hcap : d.num_digits.val <= 768)
    (hdigit : forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10)
    (hshape :
      (d.digits.val.take d.num_digits.val).map (fun q => q.val) = z :: zs)
    (hz : 7 <= z) :
    exists growth : Std.Usize,
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d 3#usize = ok growth /\ growth.val = 1 := by
-- BODY
  have hdin : forall q,
      q ∈ (d.digits.val.take d.num_digits.val).map (fun q => q.val) ->
      q < 10 := by
    intro q hq
    simp only [List.mem_map] at hq
    rcases hq with ⟨u, hu, rfl⟩
    exact hdigit u hu
  obtain ⟨growth, hgrowth, hgrowthVal⟩ :=
    DecimalLeftShiftDigitGrowth d 3#usize 1 (by norm_num) (by norm_num)
      (by norm_num) hcap hdigit
  let xs := (d.digits.val.take d.num_digits.val).map (fun q => q.val)
  have hlead := P804_T1_DecimalLeadingInterval xs z zs
    (by simpa [xs] using hshape) (by omega) (by simpa [xs] using hdin)
      (xs.length : Int)
  dsimp only at hlead
  have hnpos : 1 <= xs.length := by simp [xs, hshape]
  have hexp : (xs.length : Int) - 1 = ((xs.length - 1 : Nat) : Int) := by
    rw [Nat.cast_sub hnpos]
    norm_num
  have hIlowerR : (z : Real) * (10 : Real) ^ (xs.length - 1) <=
      (xs.foldl (fun a q => 10 * a + q) 0 : Nat) := by
    simpa only [sub_self, zpow_zero, mul_one, hexp, zpow_natCast] using hlead.1
  have hIlower : z * 10 ^ (xs.length - 1) <=
      xs.foldl (fun a q => 10 * a + q) 0 := by
    exact_mod_cast hIlowerR
  have hlen : xs.length = d.num_digits.val := by
    have h := congrArg List.length hshape
    simp only [List.length_map, List.length_take, d.digits.property,
      List.length_cons] at h
    norm_num at h
    rw [Nat.min_eq_left hcap] at h
    rw [show xs = z :: zs by simpa [xs] using hshape]
    simpa using h.symm
  have hthreshold : 10 ^ d.num_digits.val <=
      ((d.digits.val.take d.num_digits.val).map (fun q => q.val)).foldl
        (fun a q => 10 * a + q) 0 * 2 ^ (3#usize : Std.Usize).val := by
    change 10 ^ d.num_digits.val <= xs.foldl (fun a q => 10 * a + q) 0 * 8
    rw [← hlen]
    have hpow : 10 ^ xs.length = 10 ^ (xs.length - 1) * 10 := by
      calc
        10 ^ xs.length = 10 ^ ((xs.length - 1) + 1) := by congr 1 <;> omega
        _ = 10 ^ (xs.length - 1) * 10 := by rw [pow_succ]
    rw [hpow]
    nlinarith
  refine ⟨growth, hgrowth, ?_⟩
  rw [hgrowthVal]
  have hthreshold' : 10 ^ (d.num_digits.val + 1 - 1) <=
      ((d.digits.val.map (fun q => q.val)).take d.num_digits.val).foldl
        (fun a q => 10 * a + q) 0 * 2 ^ (3#usize : Std.Usize).val := by
    simpa only [Nat.add_sub_cancel, List.map_take] using hthreshold
  split
  · rfl
  · rename_i h
    have hthreshold0 : 10 ^ (d.num_digits.val + 1 - 1) <=
        ((d.digits.val.take d.num_digits.val).map (fun q => q.val)).foldl
          (fun a q => 10 * a + q) 0 * 2 ^ (3#usize : Std.Usize).val := by
      simpa only [Nat.add_sub_cancel] using hthreshold
    exact False.elim (h hthreshold0)

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (116)
More program dependencies (83)
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 10 entries
Technical checking records
Local closure summary
{
  "node": "P804_T1_PointMinusOneGrowth",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "d91cfd21e04ee7ea6c35f66dfddf4b1b8f2a471dd85b85698abec8a98d6b000f",
  "active_statement_hash": "de487e8a39ae507d63053b1e12b19edf61248430b5db23c98a2870af8f178942",
  "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",
    "P804_T1_DecimalLeadingInterval": "702e68e4f3ef9449"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "13e3cec939d02f51",
    "num_imp_dec2flt_decimal_seq_number_of_digits_decimal_left_shift": "b3efbd0e6b3fe061"
  }
}
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:4b7b222e35c0a606b955847924b6beccfb0ec5cb74bc8711b3088685c52052ce",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}