P616_T1_RoundingCellConvexity

Lean checked

Statement

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

Lemma · Convexity of every nearest-even magnitude cell

If a word w rounds real magnitudes a and b in DecimalGoalVocabularyDefault, and a\leq y\leq b, then the same word rounds y. The claim includes zero, infinity and both even and odd finite words, with the actual strict odd-word tie boundaries.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Tactic.Linarith

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_RoundingCellConvexity]
theorem P616_T1_RoundingCellConvexity (a b y : Real) (w : F64)
    (ha : DecimalGoalVocabularyDefault.roundsMagnitude a w)
    (hb : DecimalGoalVocabularyDefault.roundsMagnitude b w)
    (hay : a <= y) (hyb : y <= b) :
    DecimalGoalVocabularyDefault.roundsMagnitude y w := 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 DecimalGoalVocabularyDefault. Both premises give nonnegativity of their inputs and the target bound w.\mathit{val}\leq I, where I=2047\,2^{52} and T=2^{1024}-2^{970} is the overflow threshold. In particular 0\leq a\leq y, giving nonnegativity for y. If w.\mathit{val}=I, the premise at a gives T\leq a\leq y; this is exactly the infinity branch at y.
Otherwise both inputs satisfy a<T and b<T, so y\leq b<T. Write W=\phi(w.\mathit{val}) for the finite value of w. For each finite competitor v\ne w, put V=\phi(v.\mathit{val}) and
D_v(t)=(t-V)^2-(t-W)^2 =2(W-V)t+V^2-W^2. \tag{1}
The absolute distances are nonnegative; therefore their comparison |t-W|\leq|t-V| is equivalent to D_v(t)\geq0, and equality of distances is equivalent to D_v(t)=0. This follows by squaring both nonnegative quantities, whose squares are respectively (t-W)^2 and (t-V)^2.
If a=b, the two interval inequalities force y=a and the premise at a is the conclusion. Suppose a<b. Then \lambda=(y-a)/(b-a) belongs to [0,1] and y=(1-\lambda)a+\lambda b. By the affine identity (1),
D_v(y)=(1-\lambda)D_v(a)+\lambda D_v(b). \tag{2}
The two rounding premises give D_v(a),D_v(b)\geq0, so (2) gives the required weak comparison at y. If w.\mathit{val}\bmod2=0, every tie implication at y already has its required conclusion. If the residue is not zero, either premise's tie implication excludes equality with this competitor, so in fact D_v(a)>0 and D_v(b)>0. Equation (2) is then strictly positive: at least one of 1-\lambda,\lambda is positive and both are nonnegative. Thus equality at y is impossible and the odd-word tie implication holds vacuously. This reasoning is valid for every finite competitor; it does not assume differentiability, a strictly interior y, or that the target is a normal number. In particular an even zero target permits its endpoint ties. We have established the finite threshold, every distance inequality and every parity condition, completing the proof.

Lean proof


  let F : Nat := 2 ^ 52
  let I : Nat := 2047 * F
  let T : Real := (2 : Real)^1024 - (2 : Real)^970
  let phi : Nat → Real := fun n =>
    let e := n / F
    let m := n % F
    if e = 0 then (m : Real) / (2 : Real) ^ 1074
    else if 1075 <= e then ((F + m : Nat) : Real) * (2 : Real) ^ (e - 1075)
    else ((F + m : Nat) : Real) / (2 : Real) ^ (1075 - e)
  let R : Real → Prop := fun t => 0 <= t ∧ w.val <= I ∧
    if w.val = I then T <= t else t < T ∧
      ∀ v : F64, v.val < I → v ≠ w →
        abs (t - phi w.val) <= abs (t - phi v.val) ∧
        (abs (t - phi w.val) = abs (t - phi v.val) → w.val % 2 = 0)
  change R a at ha
  change R b at hb
  change R y
  dsimp only [R] at ha hb ⊢
  by_cases hi : w.val = I
  · simp only [if_pos hi] at ha hb ⊢
    exact ⟨le_trans ha.1 hay, ha.2.1, le_trans ha.2.2 hay⟩
  · simp only [if_neg hi] at ha hb ⊢
    refine ⟨le_trans ha.1 hay, ha.2.1, lt_of_le_of_lt hyb hb.2.2.1, ?_⟩
    intro v hv hne
    obtain ⟨hava, hata⟩ := ha.2.2.2 v hv hne
    obtain ⟨havb, hatb⟩ := hb.2.2.2 v hv hne
    let W := phi w.val
    let V := phi v.val
    have sa : (a - W)^2 <= (a - V)^2 := sq_le_sq.mpr hava
    have sb : (b - W)^2 <= (b - V)^2 := sq_le_sq.mpr havb
    have mid : (y - W)^2 <= (y - V)^2 := by
      by_cases slope : W <= V
      · have hm := mul_nonneg (sub_nonneg.mpr hyb) (sub_nonneg.mpr slope)
        nlinarith only [sb, hm]
      · have hm := mul_nonneg (sub_nonneg.mpr hay)
          (sub_nonneg.mpr (le_of_not_ge slope))
        nlinarith only [sa, hm]
    refine ⟨sq_le_sq.mp mid, ?_⟩
    intro htie
    by_contra hodd
    have sta : (a - W)^2 < (a - V)^2 := by
      apply lt_of_le_of_ne sa
      intro he
      exact hodd (hata ((sq_eq_sq_iff_abs_eq_abs _ _).mp he))
    have stb : (b - W)^2 < (b - V)^2 := by
      apply lt_of_le_of_ne sb
      intro he
      exact hodd (hatb ((sq_eq_sq_iff_abs_eq_abs _ _).mp he))
    have stmid : (y - W)^2 < (y - V)^2 := by
      by_cases slope : W <= V
      · have hm := mul_nonneg (sub_nonneg.mpr hyb) (sub_nonneg.mpr slope)
        nlinarith only [stb, hm]
      · have hm := mul_nonneg (sub_nonneg.mpr hay)
          (sub_nonneg.mpr (le_of_not_ge slope))
        nlinarith only [sta, hm]
    have heq : (y - W)^2 = (y - V)^2 := (sq_eq_sq_iff_abs_eq_abs _ _).mpr htie
    exact (ne_of_lt stmid) heq
end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Tactic.Linarith

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_RoundingCellConvexity]
theorem P616_T1_RoundingCellConvexity (a b y : Real) (w : F64)
    (ha : DecimalGoalVocabularyDefault.roundsMagnitude a w)
    (hb : DecimalGoalVocabularyDefault.roundsMagnitude b w)
    (hay : a <= y) (hyb : y <= b) :
    DecimalGoalVocabularyDefault.roundsMagnitude y w := by
-- BODY
  let F : Nat := 2 ^ 52
  let I : Nat := 2047 * F
  let T : Real := (2 : Real)^1024 - (2 : Real)^970
  let phi : Nat → Real := fun n =>
    let e := n / F
    let m := n % F
    if e = 0 then (m : Real) / (2 : Real) ^ 1074
    else if 1075 <= e then ((F + m : Nat) : Real) * (2 : Real) ^ (e - 1075)
    else ((F + m : Nat) : Real) / (2 : Real) ^ (1075 - e)
  let R : Real → Prop := fun t => 0 <= t ∧ w.val <= I ∧
    if w.val = I then T <= t else t < T ∧
      ∀ v : F64, v.val < I → v ≠ w →
        abs (t - phi w.val) <= abs (t - phi v.val) ∧
        (abs (t - phi w.val) = abs (t - phi v.val) → w.val % 2 = 0)
  change R a at ha
  change R b at hb
  change R y
  dsimp only [R] at ha hb ⊢
  by_cases hi : w.val = I
  · simp only [if_pos hi] at ha hb ⊢
    exact ⟨le_trans ha.1 hay, ha.2.1, le_trans ha.2.2 hay⟩
  · simp only [if_neg hi] at ha hb ⊢
    refine ⟨le_trans ha.1 hay, ha.2.1, lt_of_le_of_lt hyb hb.2.2.1, ?_⟩
    intro v hv hne
    obtain ⟨hava, hata⟩ := ha.2.2.2 v hv hne
    obtain ⟨havb, hatb⟩ := hb.2.2.2 v hv hne
    let W := phi w.val
    let V := phi v.val
    have sa : (a - W)^2 <= (a - V)^2 := sq_le_sq.mpr hava
    have sb : (b - W)^2 <= (b - V)^2 := sq_le_sq.mpr havb
    have mid : (y - W)^2 <= (y - V)^2 := by
      by_cases slope : W <= V
      · have hm := mul_nonneg (sub_nonneg.mpr hyb) (sub_nonneg.mpr slope)
        nlinarith only [sb, hm]
      · have hm := mul_nonneg (sub_nonneg.mpr hay)
          (sub_nonneg.mpr (le_of_not_ge slope))
        nlinarith only [sa, hm]
    refine ⟨sq_le_sq.mp mid, ?_⟩
    intro htie
    by_contra hodd
    have sta : (a - W)^2 < (a - V)^2 := by
      apply lt_of_le_of_ne sa
      intro he
      exact hodd (hata ((sq_eq_sq_iff_abs_eq_abs _ _).mp he))
    have stb : (b - W)^2 < (b - V)^2 := by
      apply lt_of_le_of_ne sb
      intro he
      exact hodd (hatb ((sq_eq_sq_iff_abs_eq_abs _ _).mp he))
    have stmid : (y - W)^2 < (y - V)^2 := by
      by_cases slope : W <= V
      · have hm := mul_nonneg (sub_nonneg.mpr hyb) (sub_nonneg.mpr slope)
        nlinarith only [stb, hm]
      · have hm := mul_nonneg (sub_nonneg.mpr hay)
          (sub_nonneg.mpr (le_of_not_ge slope))
        nlinarith only [sta, hm]
    have heq : (y - W)^2 = (y - V)^2 := (sq_eq_sq_iff_abs_eq_abs _ _).mpr htie
    exact (ne_of_lt stmid) heq
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
All 7 entries
Technical checking records
Local closure summary
{
  "node": "P616_T1_RoundingCellConvexity",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "6e85d14801c569c8d80f7178cb46d8917d8906e1aa58a17841f96abfbde3f392",
  "active_statement_hash": "b5109fed61018997313b4d8fdae6915c795e6e22f1be3ae7759e546f1bf88723",
  "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-138",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "f76c8174a4d58eb5",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "F64": "ec4e25fbaf4e11d4"
  }
}
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:823a5a3270bac9a74a8ca349ad34968932646a1baf4fa6579f3e13e3c35baf4c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}