DecimalSeqI32HCastCongruence

Lean checked

Statement

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

Lemma · Unsigned-to-I32 cast congruence

For every extracted unsigned machine word x, there is an integer k such that the signed value of its Rust cast to I32 is
\operatorname{hcast}_{\mathrm{I32}}(x)=x+k2^{32}.

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: DecimalSeqI32HCastCongruence]
theorem DecimalSeqI32HCastCongruence (x : Std.Usize) :
    exists k : Int,
      (UScalar.hcast .I32 x).val = (x.val : Int) + k * 4294967296 := 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 unsigned-to-signed cast supplied by the Aeneas scalar semantics in the shared preamble. It zero-extends or truncates the source bitvector to 32 bits. The unsigned value of the resulting bitvector is therefore r=x\bmod 2^{32}. Its signed interpretation is r when r<2^{31} and r-2^{32} otherwise. Euclidean division gives r=x-2^{32}\lfloor x/2^{32}\rfloor. In the first case choose k=-\lfloor x/2^{32}\rfloor; in the second choose that integer minus one. Both choices give the displayed equality.

Lean proof


  simp only [UScalar.hcast, IScalar.val, UScalar.val,
    BitVec.zeroExtend_eq_setWidth, BitVec.toInt, BitVec.toNat_setWidth]
  norm_num [IScalarTy.numBits]
  split
  · refine ⟨-((x.val : Int) / 4294967296), ?_⟩
    have h := Int.emod_add_ediv (x.val : Int) 4294967296
    omega
  · refine ⟨-((x.val : Int) / 4294967296) - 1, ?_⟩
    have h := Int.emod_add_ediv (x.val : Int) 4294967296
    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: DecimalSeqI32HCastCongruence]
theorem DecimalSeqI32HCastCongruence (x : Std.Usize) :
    exists k : Int,
      (UScalar.hcast .I32 x).val = (x.val : Int) + k * 4294967296 := by
-- BODY
  simp only [UScalar.hcast, IScalar.val, UScalar.val,
    BitVec.zeroExtend_eq_setWidth, BitVec.toInt, BitVec.toNat_setWidth]
  norm_num [IScalarTy.numBits]
  split
  · refine ⟨-((x.val : Int) / 4294967296), ?_⟩
    have h := Int.emod_add_ediv (x.val : Int) 4294967296
    omega
  · refine ⟨-((x.val : Int) / 4294967296) - 1, ?_⟩
    have h := Int.emod_add_ediv (x.val : Int) 4294967296
    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": "DecimalSeqI32HCastCongruence",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "0a6abc0eab2603f3453058aed92f0b719f084152293ac144c8ca6556c2447ffd",
  "active_statement_hash": "87697a3173e953fb17a44e082e0ac1b45f6c991b541014b9733acb14029a51f4",
  "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:170862d11b9eed6be50ebd5d62e4a59887d02ab9def60ace46a1d41dc1397818",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}