ParserExactRoundingAdjustment

Lean checked

Statement

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

Helper · Exact adjustment for the long decimal witness

Let start contain the ASCII bytes 0., followed by exactly 65{,}535 zero bytes, and then 1e655360. When the extracted adjust_many_digit_count operation starts with count 65{,}518, it returns the signed count -18.

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
set_option maxHeartbeats 2000000
set_option maxRecDepth 1000000

namespace dec2flt_model

-- [TABLET NODE: ParserExactRoundingAdjustment]
theorem ParserExactRoundingAdjustment (start : Slice Std.U8)
    (hs : start.val = [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
      [49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    num.imp.dec2flt.parse.adjust_many_digit_count start 65518#isize =
      ok (-18)#isize := 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

Unfold the extracted adjustment loop in num imp dec2flt parse adjust many digit count. The first byte is 0; subtracting 47 saturatingly from its byte value produces one, so the checked signed subtraction changes the count from 65{,}518 to 65{,}517. The next byte is the point. Its saturating difference from 47 is zero, so the count remains 65{,}517. Both checked index increments remain within either possible model usize bound.
For the remaining scan use k, with 0\leq k\leq65{,}535, as the number of fractional zero bytes already consumed. While scanning is true, the loop index is 2+k and the signed count is 65{,}517-k. If k<65{,}535, the byte at that index is a zero: this follows symbolically from the append and replicate indexing laws, without expanding the replicate. The byte calculation is one, the checked subtraction gives 65{,}516-k, and the checked index increment gives 3+k. Thus the invariant holds with k+1. These counts range only from 65{,}517 down to -18, and the indices range only up to 65{,}537, so all signed subtractions and unsigned increments remain in bounds on both the 32-bit and 64-bit platforms admitted by Aeneas.
At k=65{,}535, the indexed byte is the terminal 1. It is neither the point nor zero, so the loop preserves the count 65{,}517-65{,}535=-18 and changes the scanning flag to false. The next loop body returns that count. Termination follows from the decreasing measure twice the distance from index 65{,}537, plus one exactly while scanning is true. Hence the extracted operation returns -18 as claimed.

Lean proof


  have read_zero (index : Std.Usize) (k : Nat)
      (hi : index.val = 2 + k) (hk : k < 65535) :
      Slice.index_usize start index = ok 48#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq]
    rw [hs, hi]
    rw [List.getElem?_append_left (by
      simp only [List.length_append, List.length_cons, List.length_nil,
        List.length_replicate]
      omega)]
    rw [List.getElem?_append_right (by norm_num)]
    simp only [List.length_cons, List.length_nil, Nat.add_sub_cancel_left]
    rw [List.getElem?_replicate_of_lt hk]
  have read_one (index : Std.Usize) (hi : index.val = 65537) :
      Slice.index_usize start index = ok 49#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq]
    rw [hs, hi]
    rw [List.getElem?_append_right (by norm_num)]
    simp only [List.length_append, List.length_cons, List.length_nil,
      List.length_replicate]
    rfl
  have adjust_loop_exact :
      num.imp.dec2flt.parse.adjust_many_digit_count_loop
        start 65517#isize 2#usize true = ok (-18)#isize := by
    have hloop : num.imp.dec2flt.parse.adjust_many_digit_count_loop
        start 65517#isize 2#usize true
        ⦃ adjusted => adjusted.val = -18 ⦄ := by
      unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
      apply Aeneas.Std.loop.spec_decr_nat
        (fun p : Std.Isize × Std.Usize × Bool =>
          2 * (65537 - p.2.1.val) + if p.2.2 then 1 else 0)
        (fun p =>
          (p.2.2 = true /\ exists k : Nat,
            k <= 65535 /\ p.2.1.val = 2 + k /\
              p.1.val = 65517 - (k : Int)) \/
          (p.2.2 = false /\ p.2.1.val = 65537 /\ p.1.val = -18))
        (fun adjusted => adjusted.val = -18)
        (fun p => num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
          start p.1 p.2.1 p.2.2)
        (65517#isize, 2#usize, true)
      · intro p hp
        rcases p with ⟨count, index, scanning⟩
        rcases hp with hscan | hdone
        · rcases hscan with ⟨hscanning, k, hk, hindex, hcount⟩
          simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
          have hscanning' : scanning = true := hscanning
          subst scanning
          by_cases hmore : k < 65535
          · have hinside : index < Slice.len start := by
              change index.val < start.val.length
              simp only [hs, List.length_append, List.length_cons,
                List.length_nil, List.length_replicate]
              omega
            have hread := read_zero index k hindex hmore
            have hsublo :
                IScalar.min .Isize <= count.val - (1#isize).val := by
              rcases System.Platform.numBits_eq with hbits | hbits <;>
                simp [IScalar.min, IScalarTy.numBits, hbits] <;> omega
            have hsubhi :
                count.val - (1#isize).val <= IScalar.max .Isize := by
              rcases System.Platform.numBits_eq with hbits | hbits <;>
                simp [IScalar.max, IScalarTy.numBits, hbits] <;> omega
            obtain ⟨count1, hcount1, hcount1val⟩ :=
              Aeneas.Std.WP.spec_imp_exists
                (IScalar.sub_spec hsublo hsubhi)
            have haddbound :
                index.val + (1#usize).val <= UScalar.max .Usize := by
              rcases System.Platform.numBits_eq with hbits | hbits <;>
                simp [UScalar.max, hbits] <;> omega
            obtain ⟨index1, hindex1, hindex1val⟩ :=
              Aeneas.Std.WP.spec_imp_exists (UScalar.add_spec haddbound)
            have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
              apply IScalar.eq_of_val_eq
              have h := UScalar.hcast_inBounds_spec .Isize (1#u8)
                (by
                  rcases System.Platform.numBits_eq with hbits | hbits <;>
                    simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
              simpa [Aeneas.Std.lift, WP.spec_ok] using h
            simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
              hinside, hread, hindex1]
            rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
            change (do
              let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
              let digit' ← lift (UScalar.hcast .Isize digit)
              let count2 ← count - digit'
              ok (cont (count2, index1, true))) ⦃_⦄
            rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
              ok 1#u8 by rfl]
            change (do
              let digit' ← lift (UScalar.hcast .Isize 1#u8)
              let count2 ← count - digit'
              ok (cont (count2, index1, true))) ⦃_⦄
            rw [hcast1]
            change (do
              let count2 ← count - 1#isize
              ok (cont (count2, index1, true))) ⦃_⦄
            rw [hcount1]
            simp [WP.spec_ok]
            have hcount1val' : count1.val = count.val - 1 := by
              simpa using hcount1val
            have hindex1val' : index1.val = index.val + 1 := by
              simpa using hindex1val
            clear hsublo hsubhi haddbound hcount1val hindex1val
            constructor
            · refine ⟨k + 1, by omega, ?_, ?_⟩ <;> omega
            · omega
          · have hindex' : index.val = 65537 := by omega
            have hinside : index < Slice.len start := by
              change index.val < start.val.length
              simp only [hs, List.length_append, List.length_cons,
                List.length_nil, List.length_replicate]
              omega
            have hread := read_one index hindex'
            simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
              hinside, hread, WP.spec_ok]
            omega
        · rcases hdone with ⟨hscanning, hindex, hcount⟩
          simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
          have hscanning' : scanning = false := hscanning
          subst scanning
          have hinside : index < Slice.len start := by
            change index.val < start.val.length
            simp only [hs, List.length_append, List.length_cons,
              List.length_nil, List.length_replicate]
            omega
          simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
            hinside, WP.spec_ok]
          exact hcount
      · simp
    obtain ⟨adjusted, hadjusted, hval⟩ :=
      Aeneas.Std.WP.spec_imp_exists hloop
    have heq : adjusted = (-18)#isize := by
      apply IScalar.eq_of_val_eq
      simpa using hval
    simpa [heq] using hadjusted
  have hinside0 : (0#usize) < Slice.len start := by
    change 0 < start.val.length
    simp only [hs, List.length_append, List.length_cons, List.length_nil,
      List.length_replicate]
    omega
  have hinside1 : (1#usize) < Slice.len start := by
    change 1 < start.val.length
    simp only [hs, List.length_append, List.length_cons, List.length_nil,
      List.length_replicate]
    omega
  have hread0 : Slice.index_usize start 0#usize = ok 48#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq, hs]
    rfl
  have hread1 : Slice.index_usize start 1#usize = ok 46#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq, hs]
    rfl
  have addOne (x y : Usize) (hxy : x.val + 1 = y.val) :
      x + 1#usize = ok y := by
    have hmax : x.val + (1#usize).val <= UScalar.max .Usize := by
      rw [show (1#usize).val = 1 by rfl, hxy]
      have hy := UScalar.hrBounds y
      simpa [UScalar.rMax_eq_max] using hy
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (UScalar.add_spec hmax)
    rw [hz]
    congr 1
    apply UScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have subSmall (x y d : Isize) (hxy : x.val - d.val = y.val) :
      x - d = ok y := by
    have hy := IScalar.hBounds y
    have hmin : IScalar.min .Isize <= x.val - d.val := by
      rw [hxy]
      simpa [IScalar.min] using hy.1
    have hmax : x.val - d.val <= IScalar.max .Isize := by
      rw [hxy]
      simp only [IScalar.max]
      omega
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (IScalar.sub_spec hmin hmax)
    rw [hz]
    congr 1
    apply IScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have hsub0 : 65518#isize - 1#isize = ok 65517#isize :=
    subSmall _ _ _ (by
      rcases System.Platform.numBits_eq with hbits | hbits <;>
        scalar_tac)
  have hsubPoint : 65517#isize - 0#isize = ok 65517#isize :=
    subSmall _ _ _ (by
      rcases System.Platform.numBits_eq with hbits | hbits <;>
        scalar_tac)
  have hidx0 : 0#usize + 1#usize = ok 1#usize := addOne _ _ (by rfl)
  have hidx1 : 1#usize + 1#usize = ok 2#usize := addOne _ _ (by rfl)
  have hbody0 :
      num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
        start 65518#isize 0#usize true =
        ok (cont (65517#isize, 1#usize, true)) := by
    simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
      hinside0, hread0, Aeneas.Std.lift]
    rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
    change (do
      let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
      let digit' ← lift (UScalar.hcast .Isize digit)
      let count ← 65518#isize - digit'
      let index ← 0#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
      ok 1#u8 by rfl]
    change (do
      let digit' ← lift (UScalar.hcast .Isize 1#u8)
      let count ← 65518#isize - digit'
      let index ← 0#usize + 1#usize
      ok (cont (count, index, true))) = _
    have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
      apply IScalar.eq_of_val_eq
      have h := UScalar.hcast_inBounds_spec .Isize (1#u8) (by
        rcases System.Platform.numBits_eq with hbits | hbits <;>
          simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
      simpa [Aeneas.Std.lift, WP.spec_ok] using h
    rw [hcast1]
    change (do
      let count ← 65518#isize - 1#isize
      let index ← 0#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [hsub0]
    change (do
      let index ← 0#usize + 1#usize
      ok (cont (65517#isize, index, true))) = _
    rw [hidx0]
    rfl
  have hbody1 :
      num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
        start 65517#isize 1#usize true =
        ok (cont (65517#isize, 2#usize, true)) := by
    simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
      hinside1, hread1, Aeneas.Std.lift]
    rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
    change (do
      let digit ← lift (core.num.U8.saturating_sub 46#u8 47#u8)
      let digit' ← lift (UScalar.hcast .Isize digit)
      let count ← 65517#isize - digit'
      let index ← 1#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [show lift (core.num.U8.saturating_sub 46#u8 47#u8) =
      ok 0#u8 by rfl]
    change (do
      let digit' ← lift (UScalar.hcast .Isize 0#u8)
      let count ← 65517#isize - digit'
      let index ← 1#usize + 1#usize
      ok (cont (count, index, true))) = _
    have hcast0 : UScalar.hcast .Isize 0#u8 = 0#isize := by
      apply IScalar.eq_of_val_eq
      have h := UScalar.hcast_inBounds_spec .Isize (0#u8) (by
        rcases System.Platform.numBits_eq with hbits | hbits <;>
          simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
      simpa [Aeneas.Std.lift, WP.spec_ok] using h
    rw [hcast0]
    change (do
      let count ← 65517#isize - 0#isize
      let index ← 1#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [hsubPoint]
    change (do
      let index ← 1#usize + 1#usize
      ok (cont (65517#isize, index, true))) = _
    rw [hidx1]
    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 only [hbody0]
  rw [Aeneas.Std.loop.eq_1]
  simp only [hbody1]
  simpa [num.imp.dec2flt.parse.adjust_many_digit_count_loop] using
    adjust_loop_exact

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
set_option maxHeartbeats 2000000
set_option maxRecDepth 1000000

namespace dec2flt_model

-- [TABLET NODE: ParserExactRoundingAdjustment]
theorem ParserExactRoundingAdjustment (start : Slice Std.U8)
    (hs : start.val = [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
      [49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
    num.imp.dec2flt.parse.adjust_many_digit_count start 65518#isize =
      ok (-18)#isize := by
-- BODY
  have read_zero (index : Std.Usize) (k : Nat)
      (hi : index.val = 2 + k) (hk : k < 65535) :
      Slice.index_usize start index = ok 48#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq]
    rw [hs, hi]
    rw [List.getElem?_append_left (by
      simp only [List.length_append, List.length_cons, List.length_nil,
        List.length_replicate]
      omega)]
    rw [List.getElem?_append_right (by norm_num)]
    simp only [List.length_cons, List.length_nil, Nat.add_sub_cancel_left]
    rw [List.getElem?_replicate_of_lt hk]
  have read_one (index : Std.Usize) (hi : index.val = 65537) :
      Slice.index_usize start index = ok 49#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq]
    rw [hs, hi]
    rw [List.getElem?_append_right (by norm_num)]
    simp only [List.length_append, List.length_cons, List.length_nil,
      List.length_replicate]
    rfl
  have adjust_loop_exact :
      num.imp.dec2flt.parse.adjust_many_digit_count_loop
        start 65517#isize 2#usize true = ok (-18)#isize := by
    have hloop : num.imp.dec2flt.parse.adjust_many_digit_count_loop
        start 65517#isize 2#usize true
        ⦃ adjusted => adjusted.val = -18 ⦄ := by
      unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
      apply Aeneas.Std.loop.spec_decr_nat
        (fun p : Std.Isize × Std.Usize × Bool =>
          2 * (65537 - p.2.1.val) + if p.2.2 then 1 else 0)
        (fun p =>
          (p.2.2 = true /\ exists k : Nat,
            k <= 65535 /\ p.2.1.val = 2 + k /\
              p.1.val = 65517 - (k : Int)) \/
          (p.2.2 = false /\ p.2.1.val = 65537 /\ p.1.val = -18))
        (fun adjusted => adjusted.val = -18)
        (fun p => num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
          start p.1 p.2.1 p.2.2)
        (65517#isize, 2#usize, true)
      · intro p hp
        rcases p with ⟨count, index, scanning⟩
        rcases hp with hscan | hdone
        · rcases hscan with ⟨hscanning, k, hk, hindex, hcount⟩
          simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
          have hscanning' : scanning = true := hscanning
          subst scanning
          by_cases hmore : k < 65535
          · have hinside : index < Slice.len start := by
              change index.val < start.val.length
              simp only [hs, List.length_append, List.length_cons,
                List.length_nil, List.length_replicate]
              omega
            have hread := read_zero index k hindex hmore
            have hsublo :
                IScalar.min .Isize <= count.val - (1#isize).val := by
              rcases System.Platform.numBits_eq with hbits | hbits <;>
                simp [IScalar.min, IScalarTy.numBits, hbits] <;> omega
            have hsubhi :
                count.val - (1#isize).val <= IScalar.max .Isize := by
              rcases System.Platform.numBits_eq with hbits | hbits <;>
                simp [IScalar.max, IScalarTy.numBits, hbits] <;> omega
            obtain ⟨count1, hcount1, hcount1val⟩ :=
              Aeneas.Std.WP.spec_imp_exists
                (IScalar.sub_spec hsublo hsubhi)
            have haddbound :
                index.val + (1#usize).val <= UScalar.max .Usize := by
              rcases System.Platform.numBits_eq with hbits | hbits <;>
                simp [UScalar.max, hbits] <;> omega
            obtain ⟨index1, hindex1, hindex1val⟩ :=
              Aeneas.Std.WP.spec_imp_exists (UScalar.add_spec haddbound)
            have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
              apply IScalar.eq_of_val_eq
              have h := UScalar.hcast_inBounds_spec .Isize (1#u8)
                (by
                  rcases System.Platform.numBits_eq with hbits | hbits <;>
                    simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
              simpa [Aeneas.Std.lift, WP.spec_ok] using h
            simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
              hinside, hread, hindex1]
            rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
            change (do
              let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
              let digit' ← lift (UScalar.hcast .Isize digit)
              let count2 ← count - digit'
              ok (cont (count2, index1, true))) ⦃_⦄
            rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
              ok 1#u8 by rfl]
            change (do
              let digit' ← lift (UScalar.hcast .Isize 1#u8)
              let count2 ← count - digit'
              ok (cont (count2, index1, true))) ⦃_⦄
            rw [hcast1]
            change (do
              let count2 ← count - 1#isize
              ok (cont (count2, index1, true))) ⦃_⦄
            rw [hcount1]
            simp [WP.spec_ok]
            have hcount1val' : count1.val = count.val - 1 := by
              simpa using hcount1val
            have hindex1val' : index1.val = index.val + 1 := by
              simpa using hindex1val
            clear hsublo hsubhi haddbound hcount1val hindex1val
            constructor
            · refine ⟨k + 1, by omega, ?_, ?_⟩ <;> omega
            · omega
          · have hindex' : index.val = 65537 := by omega
            have hinside : index < Slice.len start := by
              change index.val < start.val.length
              simp only [hs, List.length_append, List.length_cons,
                List.length_nil, List.length_replicate]
              omega
            have hread := read_one index hindex'
            simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
              hinside, hread, WP.spec_ok]
            omega
        · rcases hdone with ⟨hscanning, hindex, hcount⟩
          simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
          have hscanning' : scanning = false := hscanning
          subst scanning
          have hinside : index < Slice.len start := by
            change index.val < start.val.length
            simp only [hs, List.length_append, List.length_cons,
              List.length_nil, List.length_replicate]
            omega
          simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
            hinside, WP.spec_ok]
          exact hcount
      · simp
    obtain ⟨adjusted, hadjusted, hval⟩ :=
      Aeneas.Std.WP.spec_imp_exists hloop
    have heq : adjusted = (-18)#isize := by
      apply IScalar.eq_of_val_eq
      simpa using hval
    simpa [heq] using hadjusted
  have hinside0 : (0#usize) < Slice.len start := by
    change 0 < start.val.length
    simp only [hs, List.length_append, List.length_cons, List.length_nil,
      List.length_replicate]
    omega
  have hinside1 : (1#usize) < Slice.len start := by
    change 1 < start.val.length
    simp only [hs, List.length_append, List.length_cons, List.length_nil,
      List.length_replicate]
    omega
  have hread0 : Slice.index_usize start 0#usize = ok 48#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq, hs]
    rfl
  have hread1 : Slice.index_usize start 1#usize = ok 46#u8 := by
    unfold Slice.index_usize
    rw [Slice.getElem?_Usize_eq, hs]
    rfl
  have addOne (x y : Usize) (hxy : x.val + 1 = y.val) :
      x + 1#usize = ok y := by
    have hmax : x.val + (1#usize).val <= UScalar.max .Usize := by
      rw [show (1#usize).val = 1 by rfl, hxy]
      have hy := UScalar.hrBounds y
      simpa [UScalar.rMax_eq_max] using hy
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (UScalar.add_spec hmax)
    rw [hz]
    congr 1
    apply UScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have subSmall (x y d : Isize) (hxy : x.val - d.val = y.val) :
      x - d = ok y := by
    have hy := IScalar.hBounds y
    have hmin : IScalar.min .Isize <= x.val - d.val := by
      rw [hxy]
      simpa [IScalar.min] using hy.1
    have hmax : x.val - d.val <= IScalar.max .Isize := by
      rw [hxy]
      simp only [IScalar.max]
      omega
    obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
      (IScalar.sub_spec hmin hmax)
    rw [hz]
    congr 1
    apply IScalar.eq_of_val_eq
    simpa [hxy] using hzval
  have hsub0 : 65518#isize - 1#isize = ok 65517#isize :=
    subSmall _ _ _ (by
      rcases System.Platform.numBits_eq with hbits | hbits <;>
        scalar_tac)
  have hsubPoint : 65517#isize - 0#isize = ok 65517#isize :=
    subSmall _ _ _ (by
      rcases System.Platform.numBits_eq with hbits | hbits <;>
        scalar_tac)
  have hidx0 : 0#usize + 1#usize = ok 1#usize := addOne _ _ (by rfl)
  have hidx1 : 1#usize + 1#usize = ok 2#usize := addOne _ _ (by rfl)
  have hbody0 :
      num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
        start 65518#isize 0#usize true =
        ok (cont (65517#isize, 1#usize, true)) := by
    simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
      hinside0, hread0, Aeneas.Std.lift]
    rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
    change (do
      let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
      let digit' ← lift (UScalar.hcast .Isize digit)
      let count ← 65518#isize - digit'
      let index ← 0#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
      ok 1#u8 by rfl]
    change (do
      let digit' ← lift (UScalar.hcast .Isize 1#u8)
      let count ← 65518#isize - digit'
      let index ← 0#usize + 1#usize
      ok (cont (count, index, true))) = _
    have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
      apply IScalar.eq_of_val_eq
      have h := UScalar.hcast_inBounds_spec .Isize (1#u8) (by
        rcases System.Platform.numBits_eq with hbits | hbits <;>
          simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
      simpa [Aeneas.Std.lift, WP.spec_ok] using h
    rw [hcast1]
    change (do
      let count ← 65518#isize - 1#isize
      let index ← 0#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [hsub0]
    change (do
      let index ← 0#usize + 1#usize
      ok (cont (65517#isize, index, true))) = _
    rw [hidx0]
    rfl
  have hbody1 :
      num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
        start 65517#isize 1#usize true =
        ok (cont (65517#isize, 2#usize, true)) := by
    simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
      hinside1, hread1, Aeneas.Std.lift]
    rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
    change (do
      let digit ← lift (core.num.U8.saturating_sub 46#u8 47#u8)
      let digit' ← lift (UScalar.hcast .Isize digit)
      let count ← 65517#isize - digit'
      let index ← 1#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [show lift (core.num.U8.saturating_sub 46#u8 47#u8) =
      ok 0#u8 by rfl]
    change (do
      let digit' ← lift (UScalar.hcast .Isize 0#u8)
      let count ← 65517#isize - digit'
      let index ← 1#usize + 1#usize
      ok (cont (count, index, true))) = _
    have hcast0 : UScalar.hcast .Isize 0#u8 = 0#isize := by
      apply IScalar.eq_of_val_eq
      have h := UScalar.hcast_inBounds_spec .Isize (0#u8) (by
        rcases System.Platform.numBits_eq with hbits | hbits <;>
          simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
      simpa [Aeneas.Std.lift, WP.spec_ok] using h
    rw [hcast0]
    change (do
      let count ← 65517#isize - 0#isize
      let index ← 1#usize + 1#usize
      ok (cont (count, index, true))) = _
    rw [hsubPoint]
    change (do
      let index ← 1#usize + 1#usize
      ok (cont (65517#isize, index, true))) = _
    rw [hidx1]
    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 only [hbody0]
  rw [Aeneas.Std.loop.eq_1]
  simp only [hbody1]
  simpa [num.imp.dec2flt.parse.adjust_many_digit_count_loop] using
    adjust_loop_exact

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": "ParserExactRoundingAdjustment",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "9d09748f71c4609875c0c42f6e8a4ab90a244de2fc419348ed6cc81cc1deea09",
  "active_statement_hash": "77a7e4d11728f051dbf0d640c901fce5bfd986f6e53236c40057072e4b14fb59",
  "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-128",
  "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:5f4720f11f16bbeb96e9c6e6b026d7b64751937bc969982bc51b52f119da83c1",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}