P364_T1_NumberHelperOffsetSourceLength

Lean checked

Statement

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

Lemma · Exact source-length offset

For Aeneas byte slices w,r with |w|\leq 9223372036854775807 and |r|\leq |w|, the extracted offset operation SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from on r relative to w returns normally with a signed word of integer value |w|-|r|.

Lean statement

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

import Tablet.Assumptions
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P364_T1_NumberHelperOffsetSourceLength]
theorem P364_T1_NumberHelperOffsetSourceLength :
  forall (whole rest : Slice Std.U8),
    whole.val.length <= 9223372036854775807 ->
    rest.val.length <= whole.val.length ->
    exists z : Std.Isize,
      SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
        rest whole = ok z /\
      z.val = whole.val.length - rest.val.length := 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 C=9223372036854775807=2^{63}-1. The approved target equation in Assumptions fixes both pointer-sized scalar widths to 64. The extracted operation cited above first casts each slice length from usize to isize, then subtracts the cast length of r from that of w. Aeneas slice lengths observe the list lengths, and 0\leq |r|\leq |w|\leq C. Thus both heterogeneous casts preserve their ordinary integer values: each input lies within the signed 64-bit range, so neither truncation nor a change of sign occurs. The resulting difference satisfies 0\leq |w|-|r|\leq C, inside [-2^{63},2^{63}-1]. The library specification for checked signed subtraction therefore gives normal return and this exact value. Combining the two exact casts with that subtraction yields the claimed result.

Lean proof


  have hbits := Dec2Flt.P340_T1_selected_target_numBits

  intro whole rest hw hr
  have hbits := hbits
  have hwcast : (Slice.len whole).val <= IScalar.max .Isize := by
    simp [IScalar.max, IScalarTy.numBits, hbits]
    omega
  have hrcast : (Slice.len rest).val <= IScalar.max .Isize := by
    simp [IScalar.max, IScalarTy.numBits, hbits]
    omega
  have hwsp := UScalar.hcast_inBounds_spec .Isize (Slice.len whole) hwcast
  have hrsp := UScalar.hcast_inBounds_spec .Isize (Slice.len rest) hrcast
  obtain ⟨wi, hwi, hwival⟩ := Aeneas.Std.WP.spec_imp_exists hwsp
  obtain ⟨ri, hri, hrival⟩ := Aeneas.Std.WP.spec_imp_exists hrsp
  simp at hwival hrival
  have hsublo : IScalar.min .Isize <= wi.val - ri.val := by
    simp [IScalar.min, IScalarTy.numBits, hbits]
    omega
  have hsubhi : wi.val - ri.val <= IScalar.max .Isize := by
    simp [IScalar.max, IScalarTy.numBits, hbits]
    omega
  have hsub := IScalar.sub_spec hsublo hsubhi
  obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists hsub
  refine ⟨z, ?_, ?_⟩
  · simp [SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from,
      hwi, hri, hz]
  · omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Assumptions
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P364_T1_NumberHelperOffsetSourceLength]
theorem P364_T1_NumberHelperOffsetSourceLength :
  forall (whole rest : Slice Std.U8),
    whole.val.length <= 9223372036854775807 ->
    rest.val.length <= whole.val.length ->
    exists z : Std.Isize,
      SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
        rest whole = ok z /\
      z.val = whole.val.length - rest.val.length := by
-- BODY
  have hbits := Dec2Flt.P340_T1_selected_target_numBits

  intro whole rest hw hr
  have hbits := hbits
  have hwcast : (Slice.len whole).val <= IScalar.max .Isize := by
    simp [IScalar.max, IScalarTy.numBits, hbits]
    omega
  have hrcast : (Slice.len rest).val <= IScalar.max .Isize := by
    simp [IScalar.max, IScalarTy.numBits, hbits]
    omega
  have hwsp := UScalar.hcast_inBounds_spec .Isize (Slice.len whole) hwcast
  have hrsp := UScalar.hcast_inBounds_spec .Isize (Slice.len rest) hrcast
  obtain ⟨wi, hwi, hwival⟩ := Aeneas.Std.WP.spec_imp_exists hwsp
  obtain ⟨ri, hri, hrival⟩ := Aeneas.Std.WP.spec_imp_exists hrsp
  simp at hwival hrival
  have hsublo : IScalar.min .Isize <= wi.val - ri.val := by
    simp [IScalar.min, IScalarTy.numBits, hbits]
    omega
  have hsubhi : wi.val - ri.val <= IScalar.max .Isize := by
    simp [IScalar.max, IScalarTy.numBits, hbits]
    omega
  have hsub := IScalar.sub_spec hsublo hsubhi
  obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists hsub
  refine ⟨z, ?_, ?_⟩
  · simp [SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from,
      hwi, hri, hz]
  · omega

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (45)
More program dependencies (12)
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": "P364_T1_NumberHelperOffsetSourceLength",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "91b6f0794f881dfa82a2b54f544c182056cf03b92684b8ec5b55c229d72aaf3d",
  "active_statement_hash": "b8e4efd6c9832b98a9e7a4e1e1949709266f3109c9798182de4282df4ef6c1e5",
  "kernel_axioms": [
    "Classical.choice",
    "Dec2Flt.P340_T1_selected_target_numBits",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-73",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830"
  }
}
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:e4f070ddcc63608362d946c94a1663d1fb9aa8c0736101b7bd12dd5a5206a505",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}