P616_T1_NegationWordLaw

Lean checked

Statement

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

Lemma · Total actual negation and its natural word equation

For every binary64 word f, actual negation in ActualDispatchOperations returns normally with a word g whose value is f.\mathit{val}+2^{63} when f.\mathit{val}<2^{63}, and f.\mathit{val}-2^{63} otherwise. This includes every NaN payload.

Lean statement

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

import Tablet.P9_T1_ActualDispatchOperations
import Tablet.ModelF64Neg
import Tablet.Binary64ModelDefault
import Mathlib.Tactic.NormNum

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_NegationWordLaw]
theorem P616_T1_NegationWordLaw (f : F64) :
    exists g : F64, P9_T1_ActualDispatchOperations.negate f = ok g ∧
      g.val = if f.val < 2 ^ 63 then f.val + 2 ^ 63 else f.val - 2 ^ 63 := 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 negation field in ActualDispatchOperations is the extracted F64 negation instance, bound to ModelF64Neg. Its defining neg field in Binary64ModelDefault is \texttt{ok}\langle f.\mathit{bv}\mathbin{\mathrm{xor}}2^{63}\rangle. Choose that word as g; this gives the normal equation without any precondition. By F64, 0\leq f.\mathit{val}<2^{64}. Euclidean division by 2^{63} therefore writes this value uniquely as h2^{63}+l, where h\in\{0,1\} and 0\leq l<2^{63}. The mask 2^{63} has precisely bit 63 set. XOR leaves the lower 63 bits l unchanged and replaces the single top bit h by 1-h. If h=0, the output value is 2^{63}+l=f.\mathit{val}+2^{63}, and f.\mathit{val}<2^{63}. If h=1, it is l=f.\mathit{val}-2^{63}, and 2^{63}\leq f.\mathit{val}. Both values are below 2^{64}, so there is no modular wrap in these displayed natural equations. The two top-bit cases give exactly the stated conditional.

Lean proof


  refine ⟨⟨f.bv ^^^ BitVec.ofNat 64 (2^63)⟩, rfl, ?_⟩
  change (f.bv ^^^ BitVec.ofNat 64 (2^63)).toNat = _
  rw [BitVec.toNat_xor]
  norm_num only [BitVec.toNat_ofNat]
  have hf : f.val < 18446744073709551616 := f.bv.isLt
  change f.val ^^^ 9223372036854775808 = _
  have hq : (f.val ^^^ 2^63) / 2^63 = f.val / 2^63 ^^^ 1 := by
    rw [Nat.xor_div_two_pow]
    norm_num
  have hm : (f.val ^^^ 2^63) % 2^63 = f.val % 2^63 := by
    rw [Nat.xor_mod_two_pow]
    simp
  have hdecomp := Nat.mod_add_div (f.val ^^^ 2^63) (2^63)
  have hdecompf := Nat.mod_add_div f.val (2^63)
  norm_num at hq hm hdecomp hdecompf
  by_cases h : f.val < 9223372036854775808
  · rw [if_pos h]
    have hqf : f.val / 9223372036854775808 = 0 := by omega
    simp only [hqf, Nat.zero_xor] at hq
    omega
  · rw [if_neg h]
    have hqf : f.val / 9223372036854775808 = 1 := by omega
    simp only [hqf, Nat.xor_self] at hq
    omega
end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.ModelF64Neg
import Tablet.Binary64ModelDefault
import Mathlib.Tactic.NormNum

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_NegationWordLaw]
theorem P616_T1_NegationWordLaw (f : F64) :
    exists g : F64, P9_T1_ActualDispatchOperations.negate f = ok g ∧
      g.val = if f.val < 2 ^ 63 then f.val + 2 ^ 63 else f.val - 2 ^ 63 := by
-- BODY
  refine ⟨⟨f.bv ^^^ BitVec.ofNat 64 (2^63)⟩, rfl, ?_⟩
  change (f.bv ^^^ BitVec.ofNat 64 (2^63)).toNat = _
  rw [BitVec.toNat_xor]
  norm_num only [BitVec.toNat_ofNat]
  have hf : f.val < 18446744073709551616 := f.bv.isLt
  change f.val ^^^ 9223372036854775808 = _
  have hq : (f.val ^^^ 2^63) / 2^63 = f.val / 2^63 ^^^ 1 := by
    rw [Nat.xor_div_two_pow]
    norm_num
  have hm : (f.val ^^^ 2^63) % 2^63 = f.val % 2^63 := by
    rw [Nat.xor_mod_two_pow]
    simp
  have hdecomp := Nat.mod_add_div (f.val ^^^ 2^63) (2^63)
  have hdecompf := Nat.mod_add_div f.val (2^63)
  norm_num at hq hm hdecomp hdecompf
  by_cases h : f.val < 9223372036854775808
  · rw [if_pos h]
    have hqf : f.val / 9223372036854775808 = 0 := by omega
    simp only [hqf, Nat.zero_xor] at hq
    omega
  · rw [if_neg h]
    have hqf : f.val / 9223372036854775808 = 1 := by omega
    simp only [hqf, Nat.xor_self] at hq
    omega
end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (198)
More program dependencies (156)
Standard-library dependencies (39)

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
All 140 entries
Technical checking records
Local closure summary
{
  "node": "P616_T1_NegationWordLaw",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c20f507853b8b136dcadaa1c819f003436c4f6d11afd56692551392973fcd21d",
  "active_statement_hash": "3138294524a6f95baaed5fcb8adee2e2e592a70ad8ce2e739d3d5a47ec0b0ef8",
  "kernel_axioms": [
    "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchOperations": "e43212aade117cab"
  }
}
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:8299fc788da421990ab14fb2d4ba5ab1d561ad524e775f17d48e4ebf8764a57d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}