DecimalSeqBulkLaneSubtraction

Lean checked

Statement

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

Helper · Bytewise subtraction of eight ASCII zeroes

Let v<2^{64} and suppose each of its eight little-endian base-256 lanes is between 48 and 57. Subtracting 3472328296227680304=48\sum_{j=0}^{7}256^j from v produces, in every lane k<8, the old lane minus 48.

Lean statement

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

import Tablet.Preamble

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqBulkLaneSubtraction]
theorem DecimalSeqBulkLaneSubtraction (v : Nat)
    (hv : v < 18446744073709551616)
    (h : forall k : Nat, k < 8 ->
      48 <= (v / 256^k) % 256 /\ (v / 256^k) % 256 <= 57) :
    forall k : Nat, k < 8 ->
      ((v - 3472328296227680304) / 256^k) % 256 =
        (v / 256^k) % 256 - 48 := 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

Write the eight lane bounds explicitly. The least lane is at least 48, so subtracting its 48 causes no borrow. Its result is below ten, and the same argument applies successively to each higher lane: because every old lane is at least 48, no lower subtraction borrows into it. For each of the eight possible values of k, expand the finite powers of 256 and Euclidean division/remainder. The hypotheses v<2^{64} and the lane intervals reduce the resulting equality to linear integer arithmetic, yielding exactly the old remainder minus 48. The Lean proof performs these eight exhaustive finite calculations with kernel-checked numeral normalization and Presburger arithmetic.

Lean proof


  intro k hk
  have h0 := h 0 (by omega)
  have h1 := h 1 (by omega)
  have h2 := h 2 (by omega)
  have h3 := h 3 (by omega)
  have h4 := h 4 (by omega)
  have h5 := h 5 (by omega)
  have h6 := h 6 (by omega)
  have h7 := h 7 (by omega)
  have hkcases : k = 0 \/ k = 1 \/ k = 2 \/ k = 3 \/ k = 4 \/
      k = 5 \/ k = 6 \/ k = 7 := by omega
  rcases hkcases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl
  all_goals norm_num only [Nat.pow_zero, Nat.pow_succ] at *
  all_goals omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Preamble

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqBulkLaneSubtraction]
theorem DecimalSeqBulkLaneSubtraction (v : Nat)
    (hv : v < 18446744073709551616)
    (h : forall k : Nat, k < 8 ->
      48 <= (v / 256^k) % 256 /\ (v / 256^k) % 256 <= 57) :
    forall k : Nat, k < 8 ->
      ((v - 3472328296227680304) / 256^k) % 256 =
        (v / 256^k) % 256 - 48 := by
-- BODY
  intro k hk
  have h0 := h 0 (by omega)
  have h1 := h 1 (by omega)
  have h2 := h 2 (by omega)
  have h3 := h 3 (by omega)
  have h4 := h 4 (by omega)
  have h5 := h 5 (by omega)
  have h6 := h 6 (by omega)
  have h7 := h 7 (by omega)
  have hkcases : k = 0 \/ k = 1 \/ k = 2 \/ k = 3 \/ k = 4 \/
      k = 5 \/ k = 6 \/ k = 7 := by omega
  rcases hkcases with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl
  all_goals norm_num only [Nat.pow_zero, Nat.pow_succ] at *
  all_goals omega

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (44)
More program dependencies (11)
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": "DecimalSeqBulkLaneSubtraction",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "86b97c9bd8c1a3506af55cc24d882831906b46b5b07de2f6a9bf1244cb4a6a10",
  "active_statement_hash": "bdf77aa8c5e796116cc6374e53bfd2da86dcf6ddb646622b479ea824930a949f",
  "kernel_axioms": [
    "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-167",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "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:855e8ddb5b092778f261f8d09c9463388d344d1ce6e94ef1c7017cac3c09a3ec",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}