P804_T1_DecimalValueBounds

Lean checked

Statement

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

Helper · Magnitude bounds for a positive-leading decimal record

Let a nonempty decimal digit list x=z::z_s have every digit below ten and z\geq1. If I is its base-ten fold and p is any integer decimal point, then
z10^{p-1}\leq I10^{p-|x|}<10^p.

Lean statement

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

import Tablet.DecimalSeqRightShiftRecordSemantics
import Tablet.P804_T1_DecimalFoldBounds

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_DecimalValueBounds]
theorem P804_T1_DecimalValueBounds
    (xs : List Nat) (z : Nat) (zs : List Nat)
    (hxs : xs = z :: zs) (hz : 1 <= z)
    (hd : forall q, q ∈ xs -> q < 10) (p : Int) :
    let I : Nat := xs.foldl (fun n digit => 10 * n + digit) 0
    (z : Real) * (10 : Real) ^ (p - 1) <=
        (I : Real) * (10 : Real) ^ (p - (xs.length : Int)) /\
      (I : Real) * (10 : Real) ^ (p - (xs.length : Int)) <
        (10 : Real) ^ p := 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

The fold upper bound I<10^{|x|} follows from DecimalFoldBounds. Retaining the actual leading digit in the same positional expansion gives the sharper lower bound
I=z10^{|x|-1}+\operatorname{fold}_{10}(z_s,0) \geq z10^{|x|-1}. \tag{1}
The list is nonempty, so |x|\geq1. Multiply (1) and the strict upper bound by the positive real number 10^{p-|x|}. The integer-power law for the nonzero base ten gives
10^{|x|-1}10^{p-|x|}=10^{p-1},\qquad 10^{|x|}10^{p-|x|}=10^p.
After associating the leading coefficient z, the two multiplied inequalities are exactly the asserted bounds.

Lean proof


  dsimp only
  have hb := P804_T1_DecimalFoldBounds xs hd z zs hxs hz
  have hn : 1 <= xs.length := by simp [hxs]
  have hlowerNat : z * 10 ^ (xs.length - 1) <=
      xs.foldl (fun n digit => 10 * n + digit) 0 := by
    subst xs
    simp only [List.length_cons, Nat.add_sub_cancel, List.foldl_cons]
    let F := fun ys : List Nat =>
      ys.foldl (fun n digit => 10 * n + digit) 0
    have foldlFrom (ys : List Nat) (a : Nat) :
        ys.foldl (fun n digit => 10 * n + digit) a =
          a * 10 ^ ys.length + F ys := by
      induction ys generalizing a with
      | nil => simp [F]
      | cons y ys ih =>
        simp only [List.foldl_cons, List.length_cons]
        rw [ih, pow_succ]
        change (10 * a + y) * 10 ^ ys.length + F ys =
          a * (10 ^ ys.length * 10) +
            (y :: ys).foldl (fun n digit => 10 * n + digit) 0
        simp only [List.foldl_cons]
        rw [ih]
        ring
    change z * 10 ^ zs.length <= F (z :: zs)
    rw [show F (z :: zs) = z * 10 ^ zs.length + F zs by
      simpa [F] using foldlFrom zs z]
    omega
  have hlower : (z : Real) * (10 : Real) ^ (xs.length - 1) <=
      ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) := by
    exact_mod_cast hlowerNat
  have hupper :
      ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) <
        (10 : Real) ^ xs.length := by
    exact_mod_cast hb.2
  have hpowpos : 0 < (10 : Real) ^ (p - (xs.length : Int)) :=
    zpow_pos (by norm_num) _
  constructor
  · have hm := mul_le_mul_of_nonneg_right hlower (le_of_lt hpowpos)
    have hexp : p - 1 = ((xs.length - 1 : Nat) : Int) +
        (p - (xs.length : Int)) := by
      rw [Nat.cast_sub hn]
      omega
    calc
      (z : Real) * (10 : Real) ^ (p - 1) =
          ((z : Real) * (10 : Real) ^ (xs.length - 1)) *
            (10 : Real) ^ (p - (xs.length : Int)) := by
              rw [hexp, zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
              norm_num only [zpow_natCast]
              ring
      _ <= ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) *
          (10 : Real) ^ (p - (xs.length : Int)) := hm
  · have hm := mul_lt_mul_of_pos_right hupper hpowpos
    calc
      ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) *
          (10 : Real) ^ (p - (xs.length : Int)) <
          (10 : Real) ^ xs.length *
            (10 : Real) ^ (p - (xs.length : Int)) := hm
      _ = (10 : Real) ^ p := by
        rw [← zpow_natCast]
        rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
        congr 1
        omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqRightShiftRecordSemantics
import Tablet.P804_T1_DecimalFoldBounds

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P804_T1_DecimalValueBounds]
theorem P804_T1_DecimalValueBounds
    (xs : List Nat) (z : Nat) (zs : List Nat)
    (hxs : xs = z :: zs) (hz : 1 <= z)
    (hd : forall q, q ∈ xs -> q < 10) (p : Int) :
    let I : Nat := xs.foldl (fun n digit => 10 * n + digit) 0
    (z : Real) * (10 : Real) ^ (p - 1) <=
        (I : Real) * (10 : Real) ^ (p - (xs.length : Int)) /\
      (I : Real) * (10 : Real) ^ (p - (xs.length : Int)) <
        (10 : Real) ^ p := by
-- BODY
  dsimp only
  have hb := P804_T1_DecimalFoldBounds xs hd z zs hxs hz
  have hn : 1 <= xs.length := by simp [hxs]
  have hlowerNat : z * 10 ^ (xs.length - 1) <=
      xs.foldl (fun n digit => 10 * n + digit) 0 := by
    subst xs
    simp only [List.length_cons, Nat.add_sub_cancel, List.foldl_cons]
    let F := fun ys : List Nat =>
      ys.foldl (fun n digit => 10 * n + digit) 0
    have foldlFrom (ys : List Nat) (a : Nat) :
        ys.foldl (fun n digit => 10 * n + digit) a =
          a * 10 ^ ys.length + F ys := by
      induction ys generalizing a with
      | nil => simp [F]
      | cons y ys ih =>
        simp only [List.foldl_cons, List.length_cons]
        rw [ih, pow_succ]
        change (10 * a + y) * 10 ^ ys.length + F ys =
          a * (10 ^ ys.length * 10) +
            (y :: ys).foldl (fun n digit => 10 * n + digit) 0
        simp only [List.foldl_cons]
        rw [ih]
        ring
    change z * 10 ^ zs.length <= F (z :: zs)
    rw [show F (z :: zs) = z * 10 ^ zs.length + F zs by
      simpa [F] using foldlFrom zs z]
    omega
  have hlower : (z : Real) * (10 : Real) ^ (xs.length - 1) <=
      ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) := by
    exact_mod_cast hlowerNat
  have hupper :
      ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) <
        (10 : Real) ^ xs.length := by
    exact_mod_cast hb.2
  have hpowpos : 0 < (10 : Real) ^ (p - (xs.length : Int)) :=
    zpow_pos (by norm_num) _
  constructor
  · have hm := mul_le_mul_of_nonneg_right hlower (le_of_lt hpowpos)
    have hexp : p - 1 = ((xs.length - 1 : Nat) : Int) +
        (p - (xs.length : Int)) := by
      rw [Nat.cast_sub hn]
      omega
    calc
      (z : Real) * (10 : Real) ^ (p - 1) =
          ((z : Real) * (10 : Real) ^ (xs.length - 1)) *
            (10 : Real) ^ (p - (xs.length : Int)) := by
              rw [hexp, zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
              norm_num only [zpow_natCast]
              ring
      _ <= ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) *
          (10 : Real) ^ (p - (xs.length : Int)) := hm
  · have hm := mul_lt_mul_of_pos_right hupper hpowpos
    calc
      ((xs.foldl (fun n digit => 10 * n + digit) 0 : Nat) : Real) *
          (10 : Real) ^ (p - (xs.length : Int)) <
          (10 : Real) ^ xs.length *
            (10 : Real) ^ (p - (xs.length : Int)) := hm
      _ = (10 : Real) ^ p := by
        rw [← zpow_natCast]
        rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
        congr 1
        omega

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
Technical checking records
Local closure summary
{
  "node": "P804_T1_DecimalValueBounds",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "8e820e14d947f32b494f524b21721cd85e200d9eb58398e89db5281127411309",
  "active_statement_hash": "2aef2deea511f54f5f5609615d74099d888424b998a80ee1fe8b2bf75f99192c",
  "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": {
    "P804_T1_DecimalFoldBounds": "9af7ca1186664411"
  },
  "strict_definition_deps": {}
}
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:7723901d7bc00adf8a774734e9b7089c8176b4d87af202e71da64b52f91d7cee",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}