P835_T1_PartialContinuationA

Lean checked

Statement

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

Lemma · Partial-parser continuation after a specified significand

Let s be nonempty, with |s|\le A=3458764513820540928. Suppose s.\mathit{val}=I++(\text{if }p\text{ then }[46]++F++T \text{ else }T), all bytes of I,F lie in [48,57], and T is empty or nondigit-headed. If p is false, require F=[] and any head of T to differ from 46. There exist slices i,t, a U64 w, an Isize n, and an I64 b, with t.\mathit{val}=T and n.\mathit{val}=|I|+|F|, such that the partial parser equals the following continuation. Define C(e,a,r) by the extracted sequence: compute z=\operatorname{offset\_from}(r,s), cast z with the Isize-to-Usize reinterpreting cast to k; if n\le19, return \texttt{ok}(\texttt{some}(\operatorname{Decimal}(e,w,\texttt{false}, \texttt{false}),k)). Otherwise compute m=n-19 and q=\operatorname{adjust\_many\_digit\_count}(s,m); if q>0 compute (w',e')=\operatorname{parse\_many\_digits}(s,i,a) and return \texttt{ok}(\texttt{some}(\operatorname{Decimal}(e',w',\texttt{false}, \texttt{true}),k)); otherwise return the first record and k. Define E(u) by parsing the scientific suffix u, branching its optional exponent: None takes the extracted option residual return, and Some a computes e=b+a and continues with C(e,a,r), using the returned scientific residual r. All these sequences are Result binds, retaining failures and divergence. The partial parser is \texttt{ok}(\texttt{none}) when n=0. Otherwise split the first byte of t: empty takes C(b,0,t); head 101 or 69 takes E(u) on the split suffix u; every other head takes C(b,0,t).

Lean statement

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

import Tablet.P435_T1_SignificandScanA
import Tablet.num_imp_dec2flt_parse_parse_partial_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P835_T1_PartialContinuationA]
theorem P835_T1_PartialContinuationA
    (s : Slice Std.U8) (integer fraction tail : List Std.U8) (point : Bool)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928)
    (hshape : s.val = integer ++ (if point then 46#u8 :: (fraction ++ tail) else tail))
    (hnoFraction : point = false -> fraction = [])
    (hd : forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57)
    (hf : forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57)
    (ht : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
    (hnoPoint : point = false -> forall b rest, tail = b :: rest -> b ≠ 46#u8) :
    exists (intEnd sigEnd : Slice Std.U8) (word : Std.U64)
      (total : Std.Isize) (base : Std.I64),
      sigEnd.val = tail /\
      total.val = ((integer.length + fraction.length : Nat) : Int) /\
      (let finish := fun (exponent explicit : Std.I64) (rest : Slice Std.U8) => do
        let offset ← SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from rest s
        let len ← lift (IScalar.hcast .Usize offset)
        if total <= 19#isize then
          ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
        else
          let more ← total - 19#isize
          let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s more
          if adjusted > 0#isize then
            let (manyWord, manyExp) ← num.imp.dec2flt.parse.parse_many_digits s intEnd explicit
            ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExp manyWord false true, len))
          else
            ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
       let scientific := fun (next : Slice Std.U8) => do
        let (value, rest) ← num.imp.dec2flt.parse.parse_scientific next
        let cf ← core.option.Option.Insts.CoreOpsTry_traitTry.branch value
        match cf with
        | core.ops.control_flow.ControlFlow.Continue explicit => do
          let exponent ← base + explicit
          finish exponent explicit rest
        | core.ops.control_flow.ControlFlow.Break residual =>
          core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual
            (num.imp.dec2flt.decimal.Decimal × Std.Usize) residual
       let afterSignificand := do
        let o ← core.slice.Slice.split_first sigEnd
        match o with
        | none => finish base 0#i64 sigEnd
        | some (c, next) =>
          if c = 101#u8 then scientific next
          else if c = 69#u8 then scientific next
          else finish base 0#i64 sigEnd
       num.imp.dec2flt.parse.parse_partial_number s =
        (if total = 0#isize then ok none else afterSignificand)) := 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

Apply SignificandScanA with the stated decomposition, digit ranges, residual condition, absent-point condition and A bound. Its statement supplies the actual integer scan, its residual i, integer word and count, the optional fractional scan returning (t,w) with fractional count and base b, and the successful count addition with value |I|+|F|. Use these very slices and scalars. Nonemptiness makes the initial is-empty call return false, hence the assertion in num imp dec2flt parse parse partial number succeeds. Substitute the integer scan and integer offset equations from the significand theorem. Reassociate Result binds around the split-first and optional-fraction match; substitute that theorem's normal optional-fraction equation, followed by its count-addition equation. This leaves the count-zero conditional and the split of t. The empty and nonmarker arms are exactly C(b,0,t) as defined above. Both marker arms have the same scientific call, option branch, checked base addition and record continuation, so are exactly E(u). Reassociation of binds does not change their failure or divergence behavior. Thus this is equality of the complete Result computations, not a normality assertion or a restriction to successful records.

Lean proof


  obtain ⟨intEnd, sigEnd, intWord, word, intCount, fractionCount,
    total, base, hscan, hintEnd, hoffset, hival, hfront, hsigEnd,
    hfval, hbase, hadd, htotal⟩ :=
    P435_T1_SignificandScanA s integer fraction tail point hshape
      hnoFraction hd hf ht hnoPoint hlen
  refine ⟨intEnd, sigEnd, word, total, base, hsigEnd, htotal, ?_⟩
  have hempty : core.slice.Slice.is_empty s = ok false := by
    cases hs : s.val with
    | nil => exact (hne hs).elim
    | cons b bs => simp [core.slice.Slice.is_empty, hs]
  have hfront' : (do
      let o ← core.slice.Slice.split_first intEnd
      match o with
      | none => ok (intEnd, intWord, 0#isize, 0#i64)
      | some p =>
        let (b, next) := p
        match b with
        | 46#uscalar => do
          let (rest, value) ← num.imp.dec2flt.parse.try_parse_digits next intWord
          let count ← SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from rest next
          let neg ← -. count
          let exponent ← lift (IScalar.cast .I64 neg)
          ok (rest, value, count, exponent)
        | _ => ok (intEnd, intWord, 0#isize, 0#i64)) =
      ok (sigEnd, word, fractionCount, base) := by
    convert hfront using 1
    apply congrArg (fun k => Bind.bind (core.slice.Slice.split_first intEnd) k)
    funext o
    cases o with
    | none => rfl
    | some p => cases p; rfl
  unfold num.imp.dec2flt.parse.parse_partial_number
  simp only [hempty, bind_tc_ok, Bool.false_eq_true, not_false_eq_true,
    massert, if_true, hscan]
  dsimp
  simp only [hoffset, bind_tc_ok]
  simp only [Aeneas.Std.uncurry, ← bind_assoc_eq] at hfront' ⊢
  erw [hfront']
  simp only [bind_tc_ok, Aeneas.Std.uncurry_apply_pair]
  simp only [hadd, bind_tc_ok]
  simp only [bind_assoc_eq]
  congr 1
  apply congrArg (fun k => Bind.bind (core.slice.Slice.split_first sigEnd) k)
  funext o
  cases o with
  | none => rfl
  | some p => cases p; rfl
end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P435_T1_SignificandScanA
import Tablet.num_imp_dec2flt_parse_parse_partial_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P835_T1_PartialContinuationA]
theorem P835_T1_PartialContinuationA
    (s : Slice Std.U8) (integer fraction tail : List Std.U8) (point : Bool)
    (hne : s.val ≠ []) (hlen : s.val.length <= 3458764513820540928)
    (hshape : s.val = integer ++ (if point then 46#u8 :: (fraction ++ tail) else tail))
    (hnoFraction : point = false -> fraction = [])
    (hd : forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57)
    (hf : forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57)
    (ht : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
    (hnoPoint : point = false -> forall b rest, tail = b :: rest -> b ≠ 46#u8) :
    exists (intEnd sigEnd : Slice Std.U8) (word : Std.U64)
      (total : Std.Isize) (base : Std.I64),
      sigEnd.val = tail /\
      total.val = ((integer.length + fraction.length : Nat) : Int) /\
      (let finish := fun (exponent explicit : Std.I64) (rest : Slice Std.U8) => do
        let offset ← SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from rest s
        let len ← lift (IScalar.hcast .Usize offset)
        if total <= 19#isize then
          ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
        else
          let more ← total - 19#isize
          let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s more
          if adjusted > 0#isize then
            let (manyWord, manyExp) ← num.imp.dec2flt.parse.parse_many_digits s intEnd explicit
            ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExp manyWord false true, len))
          else
            ok (some (num.imp.dec2flt.decimal.Decimal.mk exponent word false false, len))
       let scientific := fun (next : Slice Std.U8) => do
        let (value, rest) ← num.imp.dec2flt.parse.parse_scientific next
        let cf ← core.option.Option.Insts.CoreOpsTry_traitTry.branch value
        match cf with
        | core.ops.control_flow.ControlFlow.Continue explicit => do
          let exponent ← base + explicit
          finish exponent explicit rest
        | core.ops.control_flow.ControlFlow.Break residual =>
          core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual
            (num.imp.dec2flt.decimal.Decimal × Std.Usize) residual
       let afterSignificand := do
        let o ← core.slice.Slice.split_first sigEnd
        match o with
        | none => finish base 0#i64 sigEnd
        | some (c, next) =>
          if c = 101#u8 then scientific next
          else if c = 69#u8 then scientific next
          else finish base 0#i64 sigEnd
       num.imp.dec2flt.parse.parse_partial_number s =
        (if total = 0#isize then ok none else afterSignificand)) := by
-- BODY
  obtain ⟨intEnd, sigEnd, intWord, word, intCount, fractionCount,
    total, base, hscan, hintEnd, hoffset, hival, hfront, hsigEnd,
    hfval, hbase, hadd, htotal⟩ :=
    P435_T1_SignificandScanA s integer fraction tail point hshape
      hnoFraction hd hf ht hnoPoint hlen
  refine ⟨intEnd, sigEnd, word, total, base, hsigEnd, htotal, ?_⟩
  have hempty : core.slice.Slice.is_empty s = ok false := by
    cases hs : s.val with
    | nil => exact (hne hs).elim
    | cons b bs => simp [core.slice.Slice.is_empty, hs]
  have hfront' : (do
      let o ← core.slice.Slice.split_first intEnd
      match o with
      | none => ok (intEnd, intWord, 0#isize, 0#i64)
      | some p =>
        let (b, next) := p
        match b with
        | 46#uscalar => do
          let (rest, value) ← num.imp.dec2flt.parse.try_parse_digits next intWord
          let count ← SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from rest next
          let neg ← -. count
          let exponent ← lift (IScalar.cast .I64 neg)
          ok (rest, value, count, exponent)
        | _ => ok (intEnd, intWord, 0#isize, 0#i64)) =
      ok (sigEnd, word, fractionCount, base) := by
    convert hfront using 1
    apply congrArg (fun k => Bind.bind (core.slice.Slice.split_first intEnd) k)
    funext o
    cases o with
    | none => rfl
    | some p => cases p; rfl
  unfold num.imp.dec2flt.parse.parse_partial_number
  simp only [hempty, bind_tc_ok, Bool.false_eq_true, not_false_eq_true,
    massert, if_true, hscan]
  dsimp
  simp only [hoffset, bind_tc_ok]
  simp only [Aeneas.Std.uncurry, ← bind_assoc_eq] at hfront' ⊢
  erw [hfront']
  simp only [bind_tc_ok, Aeneas.Std.uncurry_apply_pair]
  simp only [hadd, bind_tc_ok]
  simp only [bind_assoc_eq]
  congr 1
  apply congrArg (fun k => Bind.bind (core.slice.Slice.split_first sigEnd) k)
  funext o
  cases o with
  | none => rfl
  | some p => cases p; rfl
end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (68)
More program dependencies (35)
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 51 entries
Technical checking records
Local closure summary
{
  "node": "P835_T1_PartialContinuationA",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "48fb9024eeb0d0c4a2568394bab98e239f2e3b464e42b52cb6dd78dbda37b8a8",
  "active_statement_hash": "c01645fcc8dc002c2934729c4a8d3e271bb226f3842c8219deaa04830b714c09",
  "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-194",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P435_T1_SignificandScanA": "4fa1dfb050285227",
    "num_imp_dec2flt_parse_parse_partial_number": "820c2962f733bf5c"
  },
  "strict_definition_deps": {
    "P435_T1_SignificandScanA": "a4e982c388531a6e",
    "Preamble": "965f15fc36f80938",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
    "num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
    "num_imp_dec2flt_parse_parse_partial_number": "5712e484f99eb7aa",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
    "num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
  }
}
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:5176a5705f1cabe6cda8d80e21e2f3bd2eef0dfa96853f97da640ef7b86adacb",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}