NearestEvenOrderedGrid

Lean checked

Statement

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

Lemma

Let V:\mathbb N\to\mathbb R be strictly increasing below a natural-number endpoint T. Fix r<T with V(r)=y, and positive lower and upper spacings d_- and d_+. Suppose
y\leq A+d_-/2,\qquad A\leq y+d_+/2,
and suppose that, whenever the relevant neighbor exists, V(r-1)=y-d_- and V(r+1)=y+d_+. If equality at the lower midpoint A=y-d_-/2 or at the upper midpoint A=y+d_+/2 implies that r is even, then for every v<T with v\ne r,
|A-V(r)|\leq |A-V(v)|,
and equality of these two distances implies that r is even.

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

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NearestEvenOrderedGrid]
theorem NearestEvenOrderedGrid (value : Nat → Real) (top raw : Nat)
    (A y dl du : Real)
    (hmono : ∀ p q : Nat, p < q → q < top → value p < value q)
    (hrtop : raw < top) (hval : value raw = y) (hdl : 0 < dl) (hdu : 0 < du)
    (hlo : y ≤ A + dl / 2) (hhi : A ≤ y + du / 2)
    (hprev : raw = 0 ∨ value (raw - 1) = y - dl)
    (hnext : raw + 1 = top ∨ value (raw + 1) = y + du)
    (htieLow : A = y - dl / 2 → raw % 2 = 0)
    (htieHigh : A = y + du / 2 → raw % 2 = 0) :
    ∀ v : Nat, v < top → v ≠ raw →
      abs (A - value raw) ≤ abs (A - value v) ∧
      (abs (A - value raw) = abs (A - value v) → raw % 2 = 0) := 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

First compare y=V(r) with its immediate lower neighbor. If A\leq y, the lower half-step hypothesis y\leq A+d_-/2 is equivalent to y-A\leq A-(y-d_-); both sides are nonnegative, so this is exactly |A-y|\leq|A-(y-d_-)|. If y<A, both A-y and A-(y-d_-) are nonnegative and the same inequality follows strictly from d_->0. Thus in all cases y is no farther from A than y-d_-. The symmetric argument using A\leq y+d_+/2 and d_+>0 shows that y is no farther from A than y+d_+.
Now fix v<T, v\ne r. If v<r, then r\ne0, so the lower-neighbor hypothesis gives V(r-1)=y-d_-. When v=r-1, the preceding comparison proves the required distance inequality. If the distances are equal, squaring them and expanding gives (A-y)^2=(A-y+d_-)^2. Since d_->0, cancellation yields A=y-d_-/2, and the assumed lower-midpoint implication makes r even. When instead v<r-1, strict monotonicity gives V(v)<y-d_-. The lower half-step bound gives y-d_-\leq A, hence
|A-(y-d_-)|=A-(y-d_-)<A-V(v)=|A-V(v)|.
Combining this strict inequality with the immediate-neighbor comparison proves the desired inequality and rules out equality altogether.
If r<v, then r+1\leq v<T, so r+1\ne T and the upper-neighbor hypothesis gives V(r+1)=y+d_+. When v=r+1, the upper-neighbor comparison applies. Equality of distances, after squaring and expanding, forces A=y+d_+/2 because d_+>0, so the upper-midpoint implication makes r even. Finally, if r+1<v, strict monotonicity gives y+d_+<V(v). The upper half-step bound gives A\leq y+d_+, and therefore
|A-(y+d_+)|=(y+d_+)-A<V(v)-A=|A-V(v)|.
Again the immediate-neighbor comparison proves the result, while strictness excludes an equality case. The alternatives v<r and r<v exhaust v\ne r, completing both conclusions.

Lean proof


  intro v hv hne
  rw [hval]
  have lower_near : abs (A - y) ≤ abs (A - (y - dl)) := by
    by_cases hay : A ≤ y
    · rw [abs_of_nonpos (sub_nonpos.mpr hay),
          abs_of_nonneg (by linarith : 0 ≤ A - (y - dl))]
      linarith
    · have hya : y ≤ A := le_of_not_ge hay
      rw [abs_of_nonneg (sub_nonneg.mpr hya),
          abs_of_nonneg (by linarith : 0 ≤ A - (y - dl))]
      linarith
  have upper_near : abs (A - y) ≤ abs (A - (y + du)) := by
    by_cases hay : A ≤ y
    · rw [abs_of_nonpos (sub_nonpos.mpr hay),
          abs_of_nonpos (by linarith : A - (y + du) ≤ 0)]
      linarith
    · have hya : y ≤ A := le_of_not_ge hay
      rw [abs_of_nonneg (sub_nonneg.mpr hya),
          abs_of_nonpos (by linarith : A - (y + du) ≤ 0)]
      linarith
  rcases lt_or_gt_of_ne hne with hlt | hgt
  · have hr0 : raw ≠ 0 := by omega
    have hp := hprev.resolve_left hr0
    have hle : v ≤ raw - 1 := by omega
    rcases hle.eq_or_lt with heq | hvlt
    · subst v
      rw [hp]
      refine ⟨lower_near, ?_⟩
      intro heqdist
      apply htieLow
      have hs := congrArg (fun z : Real => z ^ 2) heqdist
      dsimp only at hs
      rw [sq_abs, sq_abs] at hs
      nlinarith
    · have hvalue : value v < y - dl := by
        rw [← hp]
        exact hmono v (raw - 1) hvlt (by omega)
      have hcomp : abs (A - (y - dl)) < abs (A - value v) := by
        have hva : value v < A := by linarith
        have hpa : y - dl ≤ A := by linarith
        rw [abs_of_nonneg (sub_nonneg.mpr hpa),
          abs_of_nonneg (sub_nonneg.mpr hva.le)]
        linarith
      refine ⟨lower_near.trans hcomp.le, ?_⟩
      intro heqdist
      exact (ne_of_lt (lower_near.trans_lt hcomp) heqdist).elim
  · have hsucctop : raw + 1 ≠ top := by omega
    have hn := hnext.resolve_left hsucctop
    have hle : raw + 1 ≤ v := by omega
    rcases hle.eq_or_lt with heq | hvlt
    · subst v
      rw [hn]
      refine ⟨upper_near, ?_⟩
      intro heqdist
      apply htieHigh
      have hs := congrArg (fun z : Real => z ^ 2) heqdist
      dsimp only at hs
      rw [sq_abs, sq_abs] at hs
      nlinarith
    · have hvalue : y + du < value v := by
        rw [← hn]
        exact hmono (raw + 1) v hvlt hv
      have hcomp : abs (A - (y + du)) < abs (A - value v) := by
        have hva : A < value v := by linarith
        have hpa : A ≤ y + du := by linarith
        rw [abs_of_nonpos (sub_nonpos.mpr hpa),
          abs_of_nonpos (sub_nonpos.mpr hva.le)]
        linarith
      refine ⟨upper_near.trans hcomp.le, ?_⟩
      intro heqdist
      exact (ne_of_lt (upper_near.trans_lt hcomp) heqdist).elim

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NearestEvenOrderedGrid]
theorem NearestEvenOrderedGrid (value : Nat → Real) (top raw : Nat)
    (A y dl du : Real)
    (hmono : ∀ p q : Nat, p < q → q < top → value p < value q)
    (hrtop : raw < top) (hval : value raw = y) (hdl : 0 < dl) (hdu : 0 < du)
    (hlo : y ≤ A + dl / 2) (hhi : A ≤ y + du / 2)
    (hprev : raw = 0 ∨ value (raw - 1) = y - dl)
    (hnext : raw + 1 = top ∨ value (raw + 1) = y + du)
    (htieLow : A = y - dl / 2 → raw % 2 = 0)
    (htieHigh : A = y + du / 2 → raw % 2 = 0) :
    ∀ v : Nat, v < top → v ≠ raw →
      abs (A - value raw) ≤ abs (A - value v) ∧
      (abs (A - value raw) = abs (A - value v) → raw % 2 = 0) := by
-- BODY
  intro v hv hne
  rw [hval]
  have lower_near : abs (A - y) ≤ abs (A - (y - dl)) := by
    by_cases hay : A ≤ y
    · rw [abs_of_nonpos (sub_nonpos.mpr hay),
          abs_of_nonneg (by linarith : 0 ≤ A - (y - dl))]
      linarith
    · have hya : y ≤ A := le_of_not_ge hay
      rw [abs_of_nonneg (sub_nonneg.mpr hya),
          abs_of_nonneg (by linarith : 0 ≤ A - (y - dl))]
      linarith
  have upper_near : abs (A - y) ≤ abs (A - (y + du)) := by
    by_cases hay : A ≤ y
    · rw [abs_of_nonpos (sub_nonpos.mpr hay),
          abs_of_nonpos (by linarith : A - (y + du) ≤ 0)]
      linarith
    · have hya : y ≤ A := le_of_not_ge hay
      rw [abs_of_nonneg (sub_nonneg.mpr hya),
          abs_of_nonpos (by linarith : A - (y + du) ≤ 0)]
      linarith
  rcases lt_or_gt_of_ne hne with hlt | hgt
  · have hr0 : raw ≠ 0 := by omega
    have hp := hprev.resolve_left hr0
    have hle : v ≤ raw - 1 := by omega
    rcases hle.eq_or_lt with heq | hvlt
    · subst v
      rw [hp]
      refine ⟨lower_near, ?_⟩
      intro heqdist
      apply htieLow
      have hs := congrArg (fun z : Real => z ^ 2) heqdist
      dsimp only at hs
      rw [sq_abs, sq_abs] at hs
      nlinarith
    · have hvalue : value v < y - dl := by
        rw [← hp]
        exact hmono v (raw - 1) hvlt (by omega)
      have hcomp : abs (A - (y - dl)) < abs (A - value v) := by
        have hva : value v < A := by linarith
        have hpa : y - dl ≤ A := by linarith
        rw [abs_of_nonneg (sub_nonneg.mpr hpa),
          abs_of_nonneg (sub_nonneg.mpr hva.le)]
        linarith
      refine ⟨lower_near.trans hcomp.le, ?_⟩
      intro heqdist
      exact (ne_of_lt (lower_near.trans_lt hcomp) heqdist).elim
  · have hsucctop : raw + 1 ≠ top := by omega
    have hn := hnext.resolve_left hsucctop
    have hle : raw + 1 ≤ v := by omega
    rcases hle.eq_or_lt with heq | hvlt
    · subst v
      rw [hn]
      refine ⟨upper_near, ?_⟩
      intro heqdist
      apply htieHigh
      have hs := congrArg (fun z : Real => z ^ 2) heqdist
      dsimp only at hs
      rw [sq_abs, sq_abs] at hs
      nlinarith
    · have hvalue : y + du < value v := by
        rw [← hn]
        exact hmono (raw + 1) v hvlt hv
      have hcomp : abs (A - (y + du)) < abs (A - value v) := by
        have hva : A < value v := by linarith
        have hpa : A ≤ y + du := by linarith
        rw [abs_of_nonpos (sub_nonpos.mpr hpa),
          abs_of_nonpos (sub_nonpos.mpr hva.le)]
        linarith
      refine ⟨upper_near.trans hcomp.le, ?_⟩
      intro heqdist
      exact (ne_of_lt (upper_near.trans_lt hcomp) heqdist).elim

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": "NearestEvenOrderedGrid",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "49e4dc0b09ea49c68c675147998bafb036b7ceffa45eeb1588dc4ab623c85846",
  "active_statement_hash": "b1e43e3cee3eedfe0ffa4ba301b6e69a6f736b69402c7ff8a8cfb022d7d517a2",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-173",
  "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:1181ede3d9a79b58732b97dd3fa6a99083073f7d5dcf1d721f56f5520b960bfe",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}