P661_T1_FullMultiplicationExecution

Lean checked

Statement

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

Lemma · Full unsigned product execution

For every pair of modeled U64 operands x,y, the extracted full multiplication returns normally with U64 words l,h satisfying h2^{64}+l=xy and h=\lfloor xy/2^{64}\rfloor. No nonzero, normalization, or prior-success hypothesis is required.

Lean statement

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

import Tablet.num_imp_dec2flt_lemire_full_multiplication

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_FullMultiplicationExecution]
theorem P661_T1_FullMultiplicationExecution (x y : Std.U64) :
    exists l h : Std.U64,
      num.imp.dec2flt.lemire.full_multiplication x y = ok (l, h) /\
      h.val * 2 ^ 64 + l.val = x.val * y.val /\
      h.val = (x.val * y.val) / 2 ^ 64 := 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 num imp dec2flt lemire full multiplication and put B=2^{64}. The U64 carrier gives 0\le x,y<B, so xy\le(B-1)^2<B^2=2^{128}. Each cast to U128 is total and preserves its operand, since both operands are below 2^{128}. The checked U128 multiplication therefore succeeds with exact value xy. The cast of this product to U64 is total, with value l=xy\bmod B; it is a truncating cast, not a checked assertion that xy<B. The U128 right shift by 64 is legal since 64<128, and returns \lfloor xy/B\rfloor. This quotient is below B because xy<B^2, so its total U64 cast preserves it, giving h. These are all six source binds, in order. The final normal pair therefore exists. Euclidean division xy=B\lfloor xy/B\rfloor+(xy\bmod B) gives the first equation, and the shift and last cast give the second.

Lean proof


  have hx64 : x.val < 2 ^ 64 := x.bv.isLt
  have hy64 : y.val < 2 ^ 64 := y.bv.isLt
  have hxy128 : x.val * y.val < 2 ^ 128 := by
    have hxy := Nat.mul_le_mul (Nat.le_pred_of_lt hx64)
      (Nat.le_pred_of_lt hy64)
    norm_num at hxy ⊢
    omega
  have hx128 : x.val < 2 ^ 128 := by omega
  have hy128 : y.val < 2 ^ 128 := by omega
  have hdiv64 : x.val * y.val / 2 ^ 64 < 2 ^ 64 := by
    rw [Nat.div_lt_iff_lt_mul (by positivity)]
    norm_num at hxy128 ⊢
    exact hxy128
  have hx128' : x.val < 340282366920938463463374607431768211456 := by
    norm_num at hx128 ⊢
    exact hx128
  have hy128' : y.val < 340282366920938463463374607431768211456 := by
    norm_num at hy128 ⊢
    exact hy128
  have hxy128' : x.val * y.val < 340282366920938463463374607431768211456 := by
    norm_num at hxy128 ⊢
    exact hxy128
  have hdiv64' : x.val * y.val / 18446744073709551616 <
      18446744073709551616 := by
    norm_num at hdiv64 ⊢
    exact hdiv64
  have hs : num.imp.dec2flt.lemire.full_multiplication x y
      ⦃ r => r.2.val * 2 ^ 64 + r.1.val = x.val * y.val /\
        r.2.val = (x.val * y.val) / 2 ^ 64 ⦄ := by
    unfold num.imp.dec2flt.lemire.full_multiplication
    step
    step
    step
    step
    step
    step
    constructor
    · rw [i4_post, UScalar.cast_val_eq, i3_post1,
        i2_post, UScalar.cast_val_eq, r_post, i_post,
        i1_post, UScalar.cast_val_eq, UScalar.cast_val_eq]
      simp only [UScalarTy.numBits]
      norm_num [Nat.shiftRight_eq_div_pow]
      rw [Nat.mod_eq_of_lt hx128', Nat.mod_eq_of_lt hy128',
        Nat.mod_eq_of_lt hdiv64']
      simpa [Nat.mul_comm] using Nat.div_add_mod (x.val * y.val)
        18446744073709551616
    · rw [i4_post, UScalar.cast_val_eq, i3_post1, r_post,
        i_post, i1_post, UScalar.cast_val_eq, UScalar.cast_val_eq]
      simp only [UScalarTy.numBits]
      norm_num [Nat.shiftRight_eq_div_pow]
      rw [Nat.mod_eq_of_lt hx128', Nat.mod_eq_of_lt hy128',
        Nat.mod_eq_of_lt hdiv64']
  obtain ⟨r, hr, hrs⟩ := WP.spec_imp_exists hs
  exact ⟨r.1, r.2, hr, hrs⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_lemire_full_multiplication

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_FullMultiplicationExecution]
theorem P661_T1_FullMultiplicationExecution (x y : Std.U64) :
    exists l h : Std.U64,
      num.imp.dec2flt.lemire.full_multiplication x y = ok (l, h) /\
      h.val * 2 ^ 64 + l.val = x.val * y.val /\
      h.val = (x.val * y.val) / 2 ^ 64 := by
-- BODY
  have hx64 : x.val < 2 ^ 64 := x.bv.isLt
  have hy64 : y.val < 2 ^ 64 := y.bv.isLt
  have hxy128 : x.val * y.val < 2 ^ 128 := by
    have hxy := Nat.mul_le_mul (Nat.le_pred_of_lt hx64)
      (Nat.le_pred_of_lt hy64)
    norm_num at hxy ⊢
    omega
  have hx128 : x.val < 2 ^ 128 := by omega
  have hy128 : y.val < 2 ^ 128 := by omega
  have hdiv64 : x.val * y.val / 2 ^ 64 < 2 ^ 64 := by
    rw [Nat.div_lt_iff_lt_mul (by positivity)]
    norm_num at hxy128 ⊢
    exact hxy128
  have hx128' : x.val < 340282366920938463463374607431768211456 := by
    norm_num at hx128 ⊢
    exact hx128
  have hy128' : y.val < 340282366920938463463374607431768211456 := by
    norm_num at hy128 ⊢
    exact hy128
  have hxy128' : x.val * y.val < 340282366920938463463374607431768211456 := by
    norm_num at hxy128 ⊢
    exact hxy128
  have hdiv64' : x.val * y.val / 18446744073709551616 <
      18446744073709551616 := by
    norm_num at hdiv64 ⊢
    exact hdiv64
  have hs : num.imp.dec2flt.lemire.full_multiplication x y
      ⦃ r => r.2.val * 2 ^ 64 + r.1.val = x.val * y.val /\
        r.2.val = (x.val * y.val) / 2 ^ 64 ⦄ := by
    unfold num.imp.dec2flt.lemire.full_multiplication
    step
    step
    step
    step
    step
    step
    constructor
    · rw [i4_post, UScalar.cast_val_eq, i3_post1,
        i2_post, UScalar.cast_val_eq, r_post, i_post,
        i1_post, UScalar.cast_val_eq, UScalar.cast_val_eq]
      simp only [UScalarTy.numBits]
      norm_num [Nat.shiftRight_eq_div_pow]
      rw [Nat.mod_eq_of_lt hx128', Nat.mod_eq_of_lt hy128',
        Nat.mod_eq_of_lt hdiv64']
      simpa [Nat.mul_comm] using Nat.div_add_mod (x.val * y.val)
        18446744073709551616
    · rw [i4_post, UScalar.cast_val_eq, i3_post1, r_post,
        i_post, i1_post, UScalar.cast_val_eq, UScalar.cast_val_eq]
      simp only [UScalarTy.numBits]
      norm_num [Nat.shiftRight_eq_div_pow]
      rw [Nat.mod_eq_of_lt hx128', Nat.mod_eq_of_lt hy128',
        Nat.mod_eq_of_lt hdiv64']
  obtain ⟨r, hr, hrs⟩ := WP.spec_imp_exists hs
  exact ⟨r.1, r.2, hr, hrs⟩

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": "P661_T1_FullMultiplicationExecution",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "0f1359c504ff29ea2cfed47ec46ada607570ae1b9eb389bd4c9718932330148e",
  "active_statement_hash": "65b46d59bea27f6bf30143e5d2aea71e05c8273730aa04a9b286eeb86a1a5793",
  "kernel_axioms": [
    "Classical.choice",
    "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-146",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "num_imp_dec2flt_lemire_full_multiplication": "e9ae367eb148ddf9"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_lemire_full_multiplication": "46682dcb8efbf576"
  }
}
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:c838bf171afb3ce07e26e7f25ae50317aaabf5d372bd54f87bcbb53bb2ceb3cd",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}