P844_T1_LeftStepPotential

Lean checked

Statement

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

Lemma · Head bonus for a continuing normalization step

For integers p,q\le0, natural heads z,w, and a machine shift k\le60, assume the negative-point selector chooses k at n=-p whenever p<0. Assume that p\le-19 implies q=p+18 or p+19; -18\le p<0 implies q=-1 or 0; p=q=-1 implies w\ge7; and p=-1,z\ge7 implies q=0,w\ge5. When p=0, assume z<5, k=2 for z=1 and k=1 otherwise, q=0, z\le2\Rightarrow w\ge3, and z\ge3\Rightarrow w\ge5. Define H(-1,z)=36 for z\ge7 and 27 otherwise; H(0,z)=36 for z\ge5, 33 for 3\le z<5, and 27 otherwise; and H(p,z)=0 at all other points. Then
H(p,z)+3k\le H(q,w)+10(q-p),\qquad q-p\le k,\qquad H(p,z)\ge0.

Lean statement

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

import Tablet.SlowShiftSelectorCertificate
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.NormNum
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P844_T1_LeftStepPotential]
theorem P844_T1_LeftStepPotential (p q : Int) (z w : Nat) (k : Std.Usize)
    (hp : p <= 0) (hq : q <= 0) (hk : k.val <= 60)
    (hsel : p < 0 -> exists n : Std.Usize, (n.val : Int) = -p /\
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok k)
    (hlarge : p <= -19 -> q = p + 18 \/ q = p + 19)
    (hsmall : -18 <= p -> p < 0 -> q = -1 \/ q = 0)
    (hstall : p = -1 -> q = -1 -> 7 <= w)
    (hrecover : p = -1 -> 7 <= z -> q = 0 /\ 5 <= w)
    (hzero : p = 0 -> z < 5 /\ k = (if z = 1 then 2#usize else 1#usize) /\
      q = 0 /\ (z <= 2 -> 3 <= w) /\ (3 <= z -> 5 <= w)) :
    let H := fun (r : Int) (a : Nat) =>
      (if r = -1 then if 7 <= a then 36 else 27
       else if r = 0 then if 5 <= a then 36 else if 3 <= a then 33 else 27
       else 0 : Int)
    H p z + 3 * (k.val : Int) <= H q w + 10 * (q - p) /\
      q - p <= (k.val : Int) /\ 0 <= H p z := 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

Nonnegativity follows directly from the four possible bonus values. The literal selector rows in SlowShiftSelectorCertificate identify the shift uniquely by injectivity of the normal result constructor. For p\le-19, the input bonus is zero and q-p\in\{18,19\}. Thus 3k\le180\le10(q-p)+H(q,w). The selector gives k=60 in this regime, so also q-p\le k. For p=-1, the selector gives k=3. If q=-1, recovery excludes z\ge7, so the bonuses are 27 and 36: the inequality is equality. If q=0 and z\ge7, the output head is at least five and both bonuses are 36, so 36+9\le36+10. Otherwise the input bonus is 27 and the output bonus is at least 27, so 27+9\le H(q,w)+10. In these cases q-p is zero or one and is at most three. For -18\le p\le-2, write n=-p. The output bonus is at least 27 and q-p\in\{n-1,n\}. The seventeen literal rows for n=2,\ldots,18 are 6,9,13,16,19,23,26,29,33,36,39,43,46,49,53,56,59. Direct integer arithmetic in each row gives 3k\le10n and n\le k. Since 10n\le27+10(n-1), both asserted inequalities follow. Finally p=0 implies q=0. For z\le2, the bonuses are 27 and at least 33, and k\le2. For 3\le z<5, they are 33 and 36, and k=1. This proves the bonus inequality; the growth bound is 0\le k. These cases exhaust p\le0.

Lean proof


  intro H
  have hnonneg (r : Int) (a : Nat) : 0 <= H r a := by
    dsimp only [H]
    split_ifs <;> omega
  refine ⟨?_, ?_, hnonneg p z⟩
  all_goals
    by_cases hpL : p <= -19
    · have hbonus : H p z = 0 := by simp [H, show p ≠ -1 by omega, show p ≠ 0 by omega]
      have hnext := hlarge hpL
      have hbonus' := hnonneg q w
      obtain ⟨n, hn, hcall⟩ := hsel (by omega)
      have hcert := SlowShiftSelectorCertificate
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n
      have heq := Result.ok.inj (hcert.1.symm.trans hcall)
      have hk60 : k.val = 60 := by
        rw [← heq]
        exact (hcert.2.2.2.2 (by omega)).1
      rw [hbonus] at *
      rcases hnext with h | h <;> omega
    · by_cases hpneg : p < 0
      · obtain ⟨n, hn, hcall⟩ := hsel hpneg
        have heq := Result.ok.inj ((SlowShiftSelectorCertificate
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n).1.symm.trans hcall)
        have hnhi : n.val <= 18 := by omega
        have hnlo : 1 <= n.val := by omega
        have hnext := hsmall (by omega) hpneg
        by_cases hpm : p = -1
        · have hn1 : n.val = 1 := by omega
          have hk3 : k.val = 3 := by
            have hv := congrArg UScalar.val heq
            simpa [hn1] using hv.symm
          by_cases hqm : q = -1
          · have hw := hstall hpm hqm
            have hz : z < 7 := by
              by_contra h
              have := (hrecover hpm (by omega)).1
              omega
            simp [H, hpm, hqm, show ¬ 7 <= z by omega, hw, hk3]
          · have hq0 : q = 0 := by omega
            by_cases hz : 7 <= z
            · have hw := (hrecover hpm hz).2
              simp [H, hpm, hq0, hz, hw, hk3]
            · simp [H, hpm, hq0, hz, hk3] <;> split_ifs <;> omega
        · have hn2 : 2 <= n.val := by omega
          have hbonus : H p z = 0 := by
            simp [H, hpm, show p ≠ 0 by omega]
          have hbonus' : 27 <= H q w := by
            rcases hnext with h | h <;> simp [H, h] <;> split_ifs <;> omega
          have harith : 3 * (k.val : Int) <= 10 * (n.val : Int) /\
              (n.val : Int) <= k.val := by
            have hv := congrArg UScalar.val heq
            interval_cases hncase : n.val <;> norm_num [hncase] at hv ⊢ <;> omega
          rw [hbonus] at *
          rcases hnext with h | h <;> omega
      · have hp0 : p = 0 := by omega
        obtain ⟨hz5, hkval, hq0, hsmallHead, hlargeHead⟩ := hzero hp0
        have hk2 : k.val <= 2 := by rw [hkval]; split <;> norm_num
        by_cases hz2 : z <= 2
        · have hw := hsmallHead hz2
          simp [H, hp0, hq0, show ¬ 5 <= z by omega, show ¬ 3 <= z by omega] <;>
            split_ifs <;> omega
        · have hz3 : 3 <= z := by omega
          have hw := hlargeHead hz3
          have hk1 : k.val = 1 := by
            rw [hkval, if_neg (by omega)]
            norm_num
          simp [H, hp0, hq0, show ¬ 5 <= z by omega, hz3, hw, hk1]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.SlowShiftSelectorCertificate
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.NormNum
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P844_T1_LeftStepPotential]
theorem P844_T1_LeftStepPotential (p q : Int) (z w : Nat) (k : Std.Usize)
    (hp : p <= 0) (hq : q <= 0) (hk : k.val <= 60)
    (hsel : p < 0 -> exists n : Std.Usize, (n.val : Int) = -p /\
      num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok k)
    (hlarge : p <= -19 -> q = p + 18 \/ q = p + 19)
    (hsmall : -18 <= p -> p < 0 -> q = -1 \/ q = 0)
    (hstall : p = -1 -> q = -1 -> 7 <= w)
    (hrecover : p = -1 -> 7 <= z -> q = 0 /\ 5 <= w)
    (hzero : p = 0 -> z < 5 /\ k = (if z = 1 then 2#usize else 1#usize) /\
      q = 0 /\ (z <= 2 -> 3 <= w) /\ (3 <= z -> 5 <= w)) :
    let H := fun (r : Int) (a : Nat) =>
      (if r = -1 then if 7 <= a then 36 else 27
       else if r = 0 then if 5 <= a then 36 else if 3 <= a then 33 else 27
       else 0 : Int)
    H p z + 3 * (k.val : Int) <= H q w + 10 * (q - p) /\
      q - p <= (k.val : Int) /\ 0 <= H p z := by
-- BODY
  intro H
  have hnonneg (r : Int) (a : Nat) : 0 <= H r a := by
    dsimp only [H]
    split_ifs <;> omega
  refine ⟨?_, ?_, hnonneg p z⟩
  all_goals
    by_cases hpL : p <= -19
    · have hbonus : H p z = 0 := by simp [H, show p ≠ -1 by omega, show p ≠ 0 by omega]
      have hnext := hlarge hpL
      have hbonus' := hnonneg q w
      obtain ⟨n, hn, hcall⟩ := hsel (by omega)
      have hcert := SlowShiftSelectorCertificate
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n
      have heq := Result.ok.inj (hcert.1.symm.trans hcall)
      have hk60 : k.val = 60 := by
        rw [← heq]
        exact (hcert.2.2.2.2 (by omega)).1
      rw [hbonus] at *
      rcases hnext with h | h <;> omega
    · by_cases hpneg : p < 0
      · obtain ⟨n, hn, hcall⟩ := hsel hpneg
        have heq := Result.ok.inj ((SlowShiftSelectorCertificate
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 n).1.symm.trans hcall)
        have hnhi : n.val <= 18 := by omega
        have hnlo : 1 <= n.val := by omega
        have hnext := hsmall (by omega) hpneg
        by_cases hpm : p = -1
        · have hn1 : n.val = 1 := by omega
          have hk3 : k.val = 3 := by
            have hv := congrArg UScalar.val heq
            simpa [hn1] using hv.symm
          by_cases hqm : q = -1
          · have hw := hstall hpm hqm
            have hz : z < 7 := by
              by_contra h
              have := (hrecover hpm (by omega)).1
              omega
            simp [H, hpm, hqm, show ¬ 7 <= z by omega, hw, hk3]
          · have hq0 : q = 0 := by omega
            by_cases hz : 7 <= z
            · have hw := (hrecover hpm hz).2
              simp [H, hpm, hq0, hz, hw, hk3]
            · simp [H, hpm, hq0, hz, hk3] <;> split_ifs <;> omega
        · have hn2 : 2 <= n.val := by omega
          have hbonus : H p z = 0 := by
            simp [H, hpm, show p ≠ 0 by omega]
          have hbonus' : 27 <= H q w := by
            rcases hnext with h | h <;> simp [H, h] <;> split_ifs <;> omega
          have harith : 3 * (k.val : Int) <= 10 * (n.val : Int) /\
              (n.val : Int) <= k.val := by
            have hv := congrArg UScalar.val heq
            interval_cases hncase : n.val <;> norm_num [hncase] at hv ⊢ <;> omega
          rw [hbonus] at *
          rcases hnext with h | h <;> omega
      · have hp0 : p = 0 := by omega
        obtain ⟨hz5, hkval, hq0, hsmallHead, hlargeHead⟩ := hzero hp0
        have hk2 : k.val <= 2 := by rw [hkval]; split <;> norm_num
        by_cases hz2 : z <= 2
        · have hw := hsmallHead hz2
          simp [H, hp0, hq0, show ¬ 5 <= z by omega, show ¬ 3 <= z by omega] <;>
            split_ifs <;> omega
        · have hz3 : 3 <= z := by omega
          have hw := hlargeHead hz3
          have hk1 : k.val = 1 := by
            rw [hkval, if_neg (by omega)]
            norm_num
          simp [H, hp0, hq0, show ¬ 5 <= z by omega, hz3, hw, hk1]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (84)
More program dependencies (42)
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 79 entries
Technical checking records
Local closure summary
{
  "node": "P844_T1_LeftStepPotential",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "61ebd695a45df43bf7f862bd4aced3c46514b65b3c9f3c441b6b72d3fbed32c2",
  "active_statement_hash": "fbb1b9ae44e97ddab9eb7d5a737f1758c816d8692d077a5cdef8ad20e1966e5c",
  "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-195",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "SlowShiftSelectorCertificate": "963b7a2e670856e8"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "SlowShiftSelectorCertificate": "7ebc2b39d69850c4",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790"
  }
}
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:68bca0b9f9624ef19c371c0de2e5c88ea924eb2d1de83cafa133a8a7ed6497c6",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}