P9_T1_FinalPointArithmetic

Lean checked

Statement

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

Lemma

Put M=2^{63}-1, T=2^{59}, E=10T-1, A=3458764513820540928=M-E, and B=576460752303421440=T-2048. Clipping any integer to [-2047,2047] absorbs prior clipping to [-M-1,M]. If natural counts n,f\leq M, then -M\leq n-f\leq M. If -A\leq o\leq A and -E\leq e\leq E, then -M\leq o+e\leq M. If -B\leq b\leq B, then e\geq T implies b+e\geq2048, and e\leq-T implies b+e\leq-2048.

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: P9_T1_FinalPointArithmetic]
theorem P9_T1_FinalPointArithmetic :
    (forall x : Int,
      max (-2047) (min 2047
        (max (-9223372036854775808) (min 9223372036854775807 x))) =
      max (-2047) (min 2047 x)) /\
    (forall n f : Nat, n <= 9223372036854775807 ->
      f <= 9223372036854775807 ->
      -9223372036854775807 <= (n : Int) - f /\
        (n : Int) - f <= 9223372036854775807) /\
    (forall offset e : Int,
      -3458764513820540928 <= offset -> offset <= 3458764513820540928 ->
      -5764607523034234879 <= e -> e <= 5764607523034234879 ->
      -9223372036854775807 <= offset + e /\
        offset + e <= 9223372036854775807) /\
    (forall base e : Int,
      -576460752303421440 <= base -> base <= 576460752303421440 ->
      (576460752303423488 <= e -> 2048 <= base + e) /\
      (e <= -576460752303423488 -> base + e <= -2048)) := 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

For clipping absorption, split an integer x into x<-M-1, -M-1\leq x\leq M, and x>M. In the middle case the inner clip is x. In the lower case both outer clips are -2047, and in the upper case both are 2047, since the smaller interval lies inside the larger. For the count difference use 0\leq n,f\leq M, giving n-f\geq0-M and n-f\leq M-0. For the bounded sum add its lower and upper bounds and use A+E=M. Finally T-B=2048 gives b+e\geq-B+T=2048 and b+e\leq B-T=-2048 in the respective cases. These are integer facts, not executions on giant allocated inputs.

Lean proof


  refine ⟨?_, ?_, ?_, ?_⟩ <;> intros <;> 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: P9_T1_FinalPointArithmetic]
theorem P9_T1_FinalPointArithmetic :
    (forall x : Int,
      max (-2047) (min 2047
        (max (-9223372036854775808) (min 9223372036854775807 x))) =
      max (-2047) (min 2047 x)) /\
    (forall n f : Nat, n <= 9223372036854775807 ->
      f <= 9223372036854775807 ->
      -9223372036854775807 <= (n : Int) - f /\
        (n : Int) - f <= 9223372036854775807) /\
    (forall offset e : Int,
      -3458764513820540928 <= offset -> offset <= 3458764513820540928 ->
      -5764607523034234879 <= e -> e <= 5764607523034234879 ->
      -9223372036854775807 <= offset + e /\
        offset + e <= 9223372036854775807) /\
    (forall base e : Int,
      -576460752303421440 <= base -> base <= 576460752303421440 ->
      (576460752303423488 <= e -> 2048 <= base + e) /\
      (e <= -576460752303423488 -> base + e <= -2048)) := by
-- BODY
  refine ⟨?_, ?_, ?_, ?_⟩ <;> intros <;> 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": "P9_T1_FinalPointArithmetic",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "051f816699994225b255e40a97678e07f9ccb27fce00a52afb91557ca9879e3b",
  "active_statement_hash": "af74d4b142ad267af46ec3989ce71c9fef04f5ba5e2812adaa2bcd9b7384f23d",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "d5c04ffa333d9b33b238a527f5beaa2be82e021d3e9c0bbe01b1310280f7f55a",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-3",
  "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:9b9bea022248fa03996547506c0044f39c33536418da81de419dbcb302a09657",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}