NumberHelperLeadingOneAdjustment

Lean checked

Statement

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

Helper · Many-digit adjustment on a leading one

For the maximal witness slice and any initial isize value n, the extracted adjust_many_digit_count returns n unchanged.

Lean statement

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

import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperLeadingOneAdjustment]
theorem NumberHelperLeadingOneAdjustment (s : Slice Std.U8) (n : Std.Isize)
    (hs : s.val = List.replicate 9223372036854775800 49#u8 ++
      [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    num.imp.dec2flt.parse.adjust_many_digit_count s n = ok n := 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

The replicated prefix is nonempty and its first byte is ASCII one, 49. In the first equation of num imp dec2flt parse adjust many digit count, the slice-length guard is true and the scanning flag is true, so index zero is read. The byte 49 is neither the point byte 46 nor the zero byte 48. The loop therefore continues with the same value n, the same index zero, and the scanning flag false. In the next equation the length guard is still true, but the false scanning flag immediately returns the current value. No arithmetic operation is reached, so the exact result is ok n.

Lean proof


  have hnonempty : 0 < s.val.length := by
    rw [hs, List.length_append, List.length_replicate]
    omega
  have hrepl : List.replicate 9223372036854775800 49#u8 =
      49#u8 :: List.replicate 9223372036854775799 49#u8 := by
    rw [show 9223372036854775800 = 9223372036854775799 + 1 by norm_num,
      List.replicate_succ]
  have hscons : s.val = 49#u8 ::
      (List.replicate 9223372036854775799 49#u8 ++
        [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
    rw [hs, hrepl, List.cons_append]
  have hindex : Slice.index_usize s 0#usize = ok 49#u8 := by
    have hbound : (49#u8 ::
        (List.replicate 9223372036854775799 49#u8 ++
          [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8])).length <=
        Usize.max := by
      rw [← hscons]
      exact s.property
    let t : Slice Std.U8 := ⟨49#u8 ::
      (List.replicate 9223372036854775799 49#u8 ++
        [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]), hbound⟩
    have hst : s = t := (Slice.eq_iff _ _).2 hscons
    rw [hst]
    rfl
  unfold num.imp.dec2flt.parse.adjust_many_digit_count
  unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
    hnonempty, hindex]
  rw [Aeneas.Std.loop.eq_1]
  simp [hnonempty]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperLeadingOneAdjustment]
theorem NumberHelperLeadingOneAdjustment (s : Slice Std.U8) (n : Std.Isize)
    (hs : s.val = List.replicate 9223372036854775800 49#u8 ++
      [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    num.imp.dec2flt.parse.adjust_many_digit_count s n = ok n := by
-- BODY
  have hnonempty : 0 < s.val.length := by
    rw [hs, List.length_append, List.length_replicate]
    omega
  have hrepl : List.replicate 9223372036854775800 49#u8 =
      49#u8 :: List.replicate 9223372036854775799 49#u8 := by
    rw [show 9223372036854775800 = 9223372036854775799 + 1 by norm_num,
      List.replicate_succ]
  have hscons : s.val = 49#u8 ::
      (List.replicate 9223372036854775799 49#u8 ++
        [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
    rw [hs, hrepl, List.cons_append]
  have hindex : Slice.index_usize s 0#usize = ok 49#u8 := by
    have hbound : (49#u8 ::
        (List.replicate 9223372036854775799 49#u8 ++
          [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8])).length <=
        Usize.max := by
      rw [← hscons]
      exact s.property
    let t : Slice Std.U8 := ⟨49#u8 ::
      (List.replicate 9223372036854775799 49#u8 ++
        [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]), hbound⟩
    have hst : s = t := (Slice.eq_iff _ _).2 hscons
    rw [hst]
    rfl
  unfold num.imp.dec2flt.parse.adjust_many_digit_count
  unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
  rw [Aeneas.Std.loop.eq_1]
  simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
    hnonempty, hindex]
  rw [Aeneas.Std.loop.eq_1]
  simp [hnonempty]

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (47)
More program dependencies (14)
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": "NumberHelperLeadingOneAdjustment",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "d42d5b84dcd93689163c10826d4eef57f38dac80ac2d85f1b88567f23aac8c1c",
  "active_statement_hash": "3b9435522c100a457e2b319c6509f42b406612813c3068712c2cb92ec2a81515",
  "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-115",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "num_imp_dec2flt_parse_adjust_many_digit_count": "faf0081b4c91301b"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_parse_adjust_many_digit_count": "1bc88a1b016164f3"
  }
}
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:ef37c6e18e9f00fd3457c07584c4df31ff9868a0b7147bf990431388e22da88d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}