DecimalSeqExponentResidualPointwise

Lean checked

Statement

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

Helper · Pointwise exact exponent residual

Let a modeled slice s satisfy SourceValidByteSlice, let e be an optional triple (u,\sigma,J) consisting of a Boolean marker choice, an optional Boolean sign, and a finite list of natural numbers, and let E be an integer. Assume the following pointwise conditions. If e is absent, the natural byte-value list of s is empty and E=0. For every equality e=\mathsf{some}(u,\sigma,J), the list J is nonempty, all its entries are less than 10, and the natural byte-value list of s is
[\text{if }u\text{ then }69\text{ else }101]\mathbin{++} \operatorname{signBytes}(\sigma)\mathbin{++} J.\operatorname{map}(z\mapsto48+z),
where \operatorname{signBytes}(\mathsf{none})=[], \operatorname{signBytes}(\mathsf{some}(\mathsf{true}))=[45], and \operatorname{signBytes}(\mathsf{some}(\mathsf{false}))=[43]. For every such equality, also let
N=J.\operatorname{foldl} (n,z\mapsto\text{if }n<65536\text{ then }10n+z\text{ else }n)\ 0
and assume E=-N when \sigma=\mathsf{some}(\mathsf{true}), while E=N when \sigma=\mathsf{none} or \sigma=\mathsf{some}(\mathsf{false}). Then for all I32 values base and result, if the extracted optional-exponent evaluator DecimalSeqExponentEval on s and base returns \operatorname{ok}(\texttt{result}), then
\texttt{result.val}=\texttt{base.val}+E.

Lean statement

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

import Tablet.DecimalSeqExponentResidualExact
import Tablet.DecimalSeqExponentEval

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
namespace dec2flt_model

-- [TABLET NODE: DecimalSeqExponentResidualPointwise]
theorem DecimalSeqExponentResidualPointwise (s : Slice Std.U8)
    (exponent : Option (Bool × Option Bool × List Nat)) (E : Int)
    (hsource : SourceValidByteSlice s)
    (hne : forall upper sign digits,
      exponent = some (upper, sign, digits) -> digits ≠ [])
    (hdigits : forall upper sign digits,
      exponent = some (upper, sign, digits) ->
        forall z, z ∈ digits -> z < 10)
    (hbytesNone : exponent = none -> s.val.map (fun b => b.val) = [])
    (hbytesSome : forall upper sign digits,
      exponent = some (upper, sign, digits) ->
      s.val.map (fun b => b.val) =
        (if upper then 69 else 101) ::
          (match sign with
          | none => []
          | some negative => [if negative then 45 else 43]) ++
          digits.map (fun z => 48 + z))
    (hENone : exponent = none -> E = 0)
    (hESome : forall upper sign digits,
      exponent = some (upper, sign, digits) -> E =
        let n : Nat := digits.foldl
          (fun n digit => if n < 65536 then 10 * n + digit else n) 0
        match sign with | some true => -(n : Int) | _ => (n : Int)) :
    forall base result : Std.I32,
      DecimalSeqExponentEval s base = ok result ->
        result.val = base.val + E := 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

Split on the optional description. In the absent case, the pointwise byte and value hypotheses reduce the claim directly to DecimalSeqExponentResidualExact with an empty residual. In the present case, write the description as marker case, optional sign, and digit list. The pointwise hypotheses supply exactly the nonemptiness, digit bound, and rendered byte assumptions of DecimalSeqExponentResidualExact. Split the optional sign into no sign, plus, and minus cases so that the dependent match in that theorem reduces. Its conclusion gives the evaluator result as the base plus the corresponding signed decimal fold; the pointwise equation for E rewrites that fold to E in each case.

Lean proof


  intro base result heval
  cases he : exponent with
  | none =>
    have hv := DecimalSeqExponentResidualExact s none hsource (by trivial)
      (hbytesNone he) base result (by
        simpa [DecimalSeqExponentEval] using heval)
    rw [hENone he]
    simpa using hv
  | some data =>
    rcases data with ⟨upper, sign, digits⟩
    cases sign with
    | none =>
      have hv := DecimalSeqExponentResidualExact s
        (some (upper, none, digits)) hsource
        ⟨hne upper none digits he, hdigits upper none digits he⟩
        (by simpa using hbytesSome upper none digits he) base result
        (by simpa [DecimalSeqExponentEval] using heval)
      rw [hESome upper none digits he]
      simpa using hv
    | some negative =>
      cases negative with
      | false =>
        have hv := DecimalSeqExponentResidualExact s
          (some (upper, some false, digits)) hsource
          ⟨hne upper (some false) digits he,
            hdigits upper (some false) digits he⟩
          (by simpa using hbytesSome upper (some false) digits he)
          base result (by simpa [DecimalSeqExponentEval] using heval)
        rw [hESome upper (some false) digits he]
        simpa using hv
      | true =>
        have hv := DecimalSeqExponentResidualExact s
          (some (upper, some true, digits)) hsource
          ⟨hne upper (some true) digits he,
            hdigits upper (some true) digits he⟩
          (by simpa using hbytesSome upper (some true) digits he)
          base result (by simpa [DecimalSeqExponentEval] using heval)
        rw [hESome upper (some true) digits he]
        simpa using hv

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqExponentResidualExact
import Tablet.DecimalSeqExponentEval

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
namespace dec2flt_model

-- [TABLET NODE: DecimalSeqExponentResidualPointwise]
theorem DecimalSeqExponentResidualPointwise (s : Slice Std.U8)
    (exponent : Option (Bool × Option Bool × List Nat)) (E : Int)
    (hsource : SourceValidByteSlice s)
    (hne : forall upper sign digits,
      exponent = some (upper, sign, digits) -> digits ≠ [])
    (hdigits : forall upper sign digits,
      exponent = some (upper, sign, digits) ->
        forall z, z ∈ digits -> z < 10)
    (hbytesNone : exponent = none -> s.val.map (fun b => b.val) = [])
    (hbytesSome : forall upper sign digits,
      exponent = some (upper, sign, digits) ->
      s.val.map (fun b => b.val) =
        (if upper then 69 else 101) ::
          (match sign with
          | none => []
          | some negative => [if negative then 45 else 43]) ++
          digits.map (fun z => 48 + z))
    (hENone : exponent = none -> E = 0)
    (hESome : forall upper sign digits,
      exponent = some (upper, sign, digits) -> E =
        let n : Nat := digits.foldl
          (fun n digit => if n < 65536 then 10 * n + digit else n) 0
        match sign with | some true => -(n : Int) | _ => (n : Int)) :
    forall base result : Std.I32,
      DecimalSeqExponentEval s base = ok result ->
        result.val = base.val + E := by
-- BODY
  intro base result heval
  cases he : exponent with
  | none =>
    have hv := DecimalSeqExponentResidualExact s none hsource (by trivial)
      (hbytesNone he) base result (by
        simpa [DecimalSeqExponentEval] using heval)
    rw [hENone he]
    simpa using hv
  | some data =>
    rcases data with ⟨upper, sign, digits⟩
    cases sign with
    | none =>
      have hv := DecimalSeqExponentResidualExact s
        (some (upper, none, digits)) hsource
        ⟨hne upper none digits he, hdigits upper none digits he⟩
        (by simpa using hbytesSome upper none digits he) base result
        (by simpa [DecimalSeqExponentEval] using heval)
      rw [hESome upper none digits he]
      simpa using hv
    | some negative =>
      cases negative with
      | false =>
        have hv := DecimalSeqExponentResidualExact s
          (some (upper, some false, digits)) hsource
          ⟨hne upper (some false) digits he,
            hdigits upper (some false) digits he⟩
          (by simpa using hbytesSome upper (some false) digits he)
          base result (by simpa [DecimalSeqExponentEval] using heval)
        rw [hESome upper (some false) digits he]
        simpa using hv
      | true =>
        have hv := DecimalSeqExponentResidualExact s
          (some (upper, some true, digits)) hsource
          ⟨hne upper (some true) digits he,
            hdigits upper (some true) digits he⟩
          (by simpa using hbytesSome upper (some true) digits he)
          base result (by simpa [DecimalSeqExponentEval] using heval)
        rw [hESome upper (some true) digits he]
        simpa using hv

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (77)
More program dependencies (44)
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 13 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqExponentResidualPointwise",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "dec644b954cbaf139e3275d5a1eaa59042b4f16f735bad0c7cae00f5eaa76ce4",
  "active_statement_hash": "3bf891b49644b691bc330a63ed30ca0970e7a3b695a7a6422f725779065d6c8a",
  "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-169",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalSeqExponentEval": "004e715471c389b8",
    "DecimalSeqExponentResidualExact": "01e592e7bbbfb100"
  },
  "strict_definition_deps": {
    "DecimalSeqExponentEval": "b51b6389c17b6c1f",
    "DecimalSeqExponentResidualExact": "3d09476ce39bd493",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_decimal_seq_parse_decimal_exponent": "e22eec67a6a49ff8"
  }
}
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:6c70e3d387077ec13962f5b5d0f1106dc07eb96caca853a1a64d423155b945e4",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}