NumberHelperScientificExponentBounds

Lean checked

Statement

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

Lemma · Scientific exponent bounds and boundary suffixes

Every normal Some return of the extracted parse_scientific has value between -655359 and 655359. Moreover, the unsigned suffix 655360 returns 65536 with no unconsumed byte, and the signed suffix -655359 returns -655359 with no unconsumed byte.

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_parse_scientific

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificExponentBounds]
theorem NumberHelperScientificExponentBounds :
    (forall (s rest : Slice Std.U8) (e : Std.I64),
      num.imp.dec2flt.parse.parse_scientific s = ok (some e, rest) ->
        -655359 <= e.val /\ e.val <= 655359) /\
    (forall s : Slice Std.U8,
      s.val = [54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] ->
        exists rest,
          num.imp.dec2flt.parse.parse_scientific s =
              ok (some 65536#i64, rest) /\
            rest.val = []) /\
    (forall s : Slice Std.U8,
      s.val = [45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] ->
        exists rest,
          num.imp.dec2flt.parse.parse_scientific s =
              ok (some ((-655359)#i64), rest) /\
            rest.val = []) := 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 scientific parser in num imp dec2flt parse parse scientific. After removing an optional sign, its digit loop has the following invariant: the count is the number of consumed digit bytes, the count is at most the slice length, and the nonnegative accumulator is at most 655359. Initially both count and accumulator are zero. If the old accumulator a is below 65536, a digit d\in\{0,\ldots,9\} changes it by the checked operations a\mapsto10a+d. Hence the new value is at most 10\cdot65535+9=655359, well inside the signed 64-bit range. If a\geq65536, the guard leaves it unchanged. The byte access is justified by the loop test count < len; the following checked count increment is safe because its result is at most the slice length and hence at most Usize.max. The final slice starts at that same in-bounds count. Thus every unsigned result is in [0,655359]. The only remaining operation for a leading minus is checked negation; negating this interval is safe and gives the asserted two-sided bound.
For bytes 655360, successive accumulator values after the first five digits are
0,\ 6,\ 65,\ 655,\ 6553,\ 65536.
The sixth iteration reads the final zero in bounds, but its old accumulator is already 65536, so the strict guard is false and the value stays 65536. The count then equals six, the loop terminates, and slicing at six leaves the empty slice. There is no sign to negate.
For bytes -655359, the leading minus is removed before the loop. The six digit iterations have values
0,\ 6,\ 65,\ 655,\ 6553,\ 65535,\ 655359.
Here the old value before the last digit is 65535<65536, so the checked multiplication and addition are taken. Count six again leaves an empty slice, and the final safe negation returns -655359. These calculations also discharge every digit cast, multiplication, addition, index, increment, and final slice bound in the two concrete evaluations.

Lean proof


  refine ⟨?_, ?_, ?_⟩
  · intro s rest e h
    have loop_bound : ∀ (t : Slice Std.U8) (a : Std.I64) (k : Std.Usize),
        k.val ≤ t.length → 0 ≤ a.val → a.val ≤ 655359 →
        num.imp.dec2flt.parse.parse_scientific_loop a t k
          ⦃ p => p.2.val ≤ t.length ∧ 0 ≤ p.1.val ∧ p.1.val ≤ 655359 ⦄ := by
      intro t a k hk ha hb
      unfold num.imp.dec2flt.parse.parse_scientific_loop
      apply Aeneas.Std.loop.spec_decr_nat
        (fun p : Std.I64 × Std.Usize => t.length - p.2.val)
        (fun p => p.2.val ≤ t.length ∧ 0 ≤ p.1.val ∧ p.1.val ≤ 655359)
        (fun p => p.2.val ≤ t.length ∧ 0 ≤ p.1.val ∧ p.1.val ≤ 655359)
        (fun p => num.imp.dec2flt.parse.parse_scientific_loop.body t p.1 p.2)
        (a, k)
      · intro p hp
        simp [num.imp.dec2flt.parse.parse_scientific_loop.body, WP.spec_ok]
        split
        · step
          step
          split
          · step
            split
            · step
              step
              have hd : digit.val < 10 := by
                calc
                  digit.val = i2.val := by simp [digit_post, i2_post]
                  _ < 10 := by assumption
              have hc : (UScalar.hcast IScalarTy.I64 digit).val = digit.val := by
                have q := UScalar.hcast_inBounds_spec IScalarTy.I64 digit (by grind)
                simpa [WP.spec_ok] using q
              have hx : x.val = digit.val := by rw [x_post, hc]
              have hmax : exponent1.val + x.val ≤ I64.max := by
                rw [I64.max_eq]
                omega
              step with IScalar.add_spec
              step
              omega
            · step
              simp_all <;> grind
          · simp_all
        · simp_all
      · exact ⟨hk, ha, hb⟩
    have parse_bound : ∀ (t : Slice Std.U8),
        num.imp.dec2flt.parse.parse_scientific t
          ⦃ q => ∀ (z : Std.I64) (r : Slice Std.U8),
            q = (some z, r) → -655359 ≤ z.val ∧ z.val ≤ 655359 ⦄ := by
      intro t
      unfold num.imp.dec2flt.parse.parse_scientific
      cases hval : t.val with
      | nil =>
        have ht : t = (⟨[], by simpa [hval] using t.property⟩ : Slice Std.U8) := by
          exact (Slice.eq_iff _ _).2 hval
        rw [ht]
        simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst]
      | cons c xs =>
        have ht : t = (⟨c :: xs, by simpa [hval] using t.property⟩ : Slice Std.U8) := by
          exact (Slice.eq_iff _ _).2 hval
        rw [ht]
        simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst]
        split
        · simp
          split
          · simp_all
          ·
            have hxlen : 0 < xs.length := List.length_pos_of_ne_nil (by assumption)
            step
            simp [core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit]
            split
            · have lp := loop_bound
                (⟨xs, by
                  have q := t.property
                  rw [hval] at q
                  have q' : 1 + xs.length ≤ Usize.max := by simpa [Nat.add_comm] using q
                  exact Nat.le_trans (Nat.le_add_left xs.length 1) q'⟩ : Slice Std.U8)
                0#i64 0#usize (by simp) (by norm_num) (by norm_num)
              step with lp
              step
              step
              simp_all <;> omega
            · simp_all
        · split
          · simp
            split
            · simp_all
            ·
              have hxlen : 0 < xs.length := List.length_pos_of_ne_nil (by assumption)
              step
              simp [core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit]
              split
              · have lp := loop_bound
                  (⟨xs, by
                    have q := t.property
                    rw [hval] at q
                    have q' : 1 + xs.length ≤ Usize.max := by simpa [Nat.add_comm] using q
                    exact Nat.le_trans (Nat.le_add_left xs.length 1) q'⟩ : Slice Std.U8)
                  0#i64 0#usize (by simp) (by norm_num) (by norm_num)
                step with lp
                step
                simp_all <;> omega
              · simp_all
          · simp
            have htlen : 0 < t.length := by simp [Slice.length, hval]
            step
            simp [core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit]
            split
            · have lp := loop_bound
                (⟨c :: xs, by simpa [hval] using t.property⟩ : Slice Std.U8)
                0#i64 0#usize (by simp) (by norm_num) (by norm_num)
              step with lp
              step
              simp_all <;> omega
            · simp_all
    have hb := parse_bound s
    rw [h] at hb
    exact hb e rest rfl
  · intro s hs
    have ht : s = (⟨[54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8], by
      rcases Usize.bounds_eq with q | q <;> norm_num [q, U32.max_eq, U64.max_eq]⟩ : Slice Std.U8) := by
      exact (Slice.eq_iff _ _).2 hs
    rw [ht]
    refine ⟨⟨[], by simp⟩, ?_, by scalar_tac⟩
    simp [num.imp.dec2flt.parse.parse_scientific,
      core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
      core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit,
      Slice.index_usize]
    simp [num.imp.dec2flt.parse.parse_scientific_loop]
    rw [Aeneas.Std.loop.eq_1]
    have first_product : (10#i64 * 0#i64) = ok 0#i64 := by rfl
    have first_sum : (0#i64 + 6#i64) = ok 6#i64 := by rfl
    have first_digit : (UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = 6#i64 := by rfl
    have first_sum2 : (0#i64 + UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_sum3 : (0#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_count : (0#usize + 1#usize) = ok 1#usize := by
      change UScalar.add (0#usize) (1#usize) = ok 1#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have second_product : (10#i64 * 6#i64) = ok 60#i64 := by rfl
    have second_sum : (60#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65#i64 := by rfl
    have second_count : (1#usize + 1#usize) = ok 2#usize := by
      change UScalar.add (1#usize) (1#usize) = ok 2#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have third_product : (10#i64 * 65#i64) = ok 650#i64 := by rfl
    have third_sum : (650#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 655#i64 := by rfl
    have third_count : (2#usize + 1#usize) = ok 3#usize := by
      change UScalar.add (2#usize) (1#usize) = ok 3#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fourth_product : (10#i64 * 655#i64) = ok 6550#i64 := by rfl
    have fourth_sum : (6550#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 51#u8 48#u8)) = ok 6553#i64 := by rfl
    have fourth_count : (3#usize + 1#usize) = ok 4#usize := by
      change UScalar.add (3#usize) (1#usize) = ok 4#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
    have fifth_sum : (65530#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 54#u8 48#u8)) = ok 65536#i64 := by rfl
    have fifth_count : (4#usize + 1#usize) = ok 5#usize := by
      change UScalar.add (4#usize) (1#usize) = ok 5#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have sixth_count : (5#usize + 1#usize) = ok 6#usize := by
      change UScalar.add (5#usize) (1#usize) = ok 6#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
      first_product, first_sum, first_count, first_digit, first_sum2]
    rw [first_sum3]
    simp
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [second_product, second_sum, second_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [third_product, third_sum, third_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fourth_product, fourth_sum, fourth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fifth_product, fifth_sum, fifth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq, sixth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
      core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
      Slice.length, List.drop]
  · intro s hs
    have ht : s = (⟨[45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8], by
      rcases Usize.bounds_eq with q | q <;> norm_num [q, U32.max_eq, U64.max_eq]⟩ : Slice Std.U8) := by
      exact (Slice.eq_iff _ _).2 hs
    rw [ht]
    refine ⟨⟨[], by simp⟩, ?_, by scalar_tac⟩
    simp [num.imp.dec2flt.parse.parse_scientific,
      core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
      core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit,
      Slice.index_usize]
    simp [num.imp.dec2flt.parse.parse_scientific_loop]
    rw [Aeneas.Std.loop.eq_1]
    have first_product : (10#i64 * 0#i64) = ok 0#i64 := by rfl
    have first_sum : (0#i64 + 6#i64) = ok 6#i64 := by rfl
    have first_digit : (UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = 6#i64 := by rfl
    have first_sum2 : (0#i64 + UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_sum3 : (0#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_count : (0#usize + 1#usize) = ok 1#usize := by
      change UScalar.add (0#usize) (1#usize) = ok 1#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have second_product : (10#i64 * 6#i64) = ok 60#i64 := by rfl
    have second_sum : (60#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65#i64 := by rfl
    have second_count : (1#usize + 1#usize) = ok 2#usize := by
      change UScalar.add (1#usize) (1#usize) = ok 2#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have third_product : (10#i64 * 65#i64) = ok 650#i64 := by rfl
    have third_sum : (650#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 655#i64 := by rfl
    have third_count : (2#usize + 1#usize) = ok 3#usize := by
      change UScalar.add (2#usize) (1#usize) = ok 3#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fourth_product : (10#i64 * 655#i64) = ok 6550#i64 := by rfl
    have fourth_sum : (6550#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 51#u8 48#u8)) = ok 6553#i64 := by rfl
    have fourth_count : (3#usize + 1#usize) = ok 4#usize := by
      change UScalar.add (3#usize) (1#usize) = ok 4#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
    have fifth_sum : (65530#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65535#i64 := by rfl
    have fifth_count : (4#usize + 1#usize) = ok 5#usize := by
      change UScalar.add (4#usize) (1#usize) = ok 5#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have sixth_product : (10#i64 * 65535#i64) = ok 655350#i64 := by rfl
    have sixth_sum : (655350#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 57#u8 48#u8)) = ok 655359#i64 := by rfl
    have sixth_count : (5#usize + 1#usize) = ok 6#usize := by
      change UScalar.add (5#usize) (1#usize) = ok 6#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
      first_product, first_sum, first_count, first_digit, first_sum2]
    rw [first_sum3]
    simp
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [second_product, second_sum, second_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [third_product, third_sum, third_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fourth_product, fourth_sum, fourth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fifth_product, fifth_sum, fifth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
      sixth_product, sixth_sum, sixth_count]
    rw [Aeneas.Std.loop.eq_1]
    have neg_final : IScalar.neg (655359#i64) = ok ((-655359)#i64) := by rfl
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
      core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
      Slice.length, List.drop, HNeg.hNeg, IScalar.neg, neg_final,
      IScalar.tryMk, IScalar.tryMkOpt, Result.ofOption, IScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_parse_parse_scientific

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: NumberHelperScientificExponentBounds]
theorem NumberHelperScientificExponentBounds :
    (forall (s rest : Slice Std.U8) (e : Std.I64),
      num.imp.dec2flt.parse.parse_scientific s = ok (some e, rest) ->
        -655359 <= e.val /\ e.val <= 655359) /\
    (forall s : Slice Std.U8,
      s.val = [54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] ->
        exists rest,
          num.imp.dec2flt.parse.parse_scientific s =
              ok (some 65536#i64, rest) /\
            rest.val = []) /\
    (forall s : Slice Std.U8,
      s.val = [45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] ->
        exists rest,
          num.imp.dec2flt.parse.parse_scientific s =
              ok (some ((-655359)#i64), rest) /\
            rest.val = []) := by
-- BODY
  refine ⟨?_, ?_, ?_⟩
  · intro s rest e h
    have loop_bound : ∀ (t : Slice Std.U8) (a : Std.I64) (k : Std.Usize),
        k.val ≤ t.length → 0 ≤ a.val → a.val ≤ 655359 →
        num.imp.dec2flt.parse.parse_scientific_loop a t k
          ⦃ p => p.2.val ≤ t.length ∧ 0 ≤ p.1.val ∧ p.1.val ≤ 655359 ⦄ := by
      intro t a k hk ha hb
      unfold num.imp.dec2flt.parse.parse_scientific_loop
      apply Aeneas.Std.loop.spec_decr_nat
        (fun p : Std.I64 × Std.Usize => t.length - p.2.val)
        (fun p => p.2.val ≤ t.length ∧ 0 ≤ p.1.val ∧ p.1.val ≤ 655359)
        (fun p => p.2.val ≤ t.length ∧ 0 ≤ p.1.val ∧ p.1.val ≤ 655359)
        (fun p => num.imp.dec2flt.parse.parse_scientific_loop.body t p.1 p.2)
        (a, k)
      · intro p hp
        simp [num.imp.dec2flt.parse.parse_scientific_loop.body, WP.spec_ok]
        split
        · step
          step
          split
          · step
            split
            · step
              step
              have hd : digit.val < 10 := by
                calc
                  digit.val = i2.val := by simp [digit_post, i2_post]
                  _ < 10 := by assumption
              have hc : (UScalar.hcast IScalarTy.I64 digit).val = digit.val := by
                have q := UScalar.hcast_inBounds_spec IScalarTy.I64 digit (by grind)
                simpa [WP.spec_ok] using q
              have hx : x.val = digit.val := by rw [x_post, hc]
              have hmax : exponent1.val + x.val ≤ I64.max := by
                rw [I64.max_eq]
                omega
              step with IScalar.add_spec
              step
              omega
            · step
              simp_all <;> grind
          · simp_all
        · simp_all
      · exact ⟨hk, ha, hb⟩
    have parse_bound : ∀ (t : Slice Std.U8),
        num.imp.dec2flt.parse.parse_scientific t
          ⦃ q => ∀ (z : Std.I64) (r : Slice Std.U8),
            q = (some z, r) → -655359 ≤ z.val ∧ z.val ≤ 655359 ⦄ := by
      intro t
      unfold num.imp.dec2flt.parse.parse_scientific
      cases hval : t.val with
      | nil =>
        have ht : t = (⟨[], by simpa [hval] using t.property⟩ : Slice Std.U8) := by
          exact (Slice.eq_iff _ _).2 hval
        rw [ht]
        simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst]
      | cons c xs =>
        have ht : t = (⟨c :: xs, by simpa [hval] using t.property⟩ : Slice Std.U8) := by
          exact (Slice.eq_iff _ _).2 hval
        rw [ht]
        simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst]
        split
        · simp
          split
          · simp_all
          ·
            have hxlen : 0 < xs.length := List.length_pos_of_ne_nil (by assumption)
            step
            simp [core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit]
            split
            · have lp := loop_bound
                (⟨xs, by
                  have q := t.property
                  rw [hval] at q
                  have q' : 1 + xs.length ≤ Usize.max := by simpa [Nat.add_comm] using q
                  exact Nat.le_trans (Nat.le_add_left xs.length 1) q'⟩ : Slice Std.U8)
                0#i64 0#usize (by simp) (by norm_num) (by norm_num)
              step with lp
              step
              step
              simp_all <;> omega
            · simp_all
        · split
          · simp
            split
            · simp_all
            ·
              have hxlen : 0 < xs.length := List.length_pos_of_ne_nil (by assumption)
              step
              simp [core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit]
              split
              · have lp := loop_bound
                  (⟨xs, by
                    have q := t.property
                    rw [hval] at q
                    have q' : 1 + xs.length ≤ Usize.max := by simpa [Nat.add_comm] using q
                    exact Nat.le_trans (Nat.le_add_left xs.length 1) q'⟩ : Slice Std.U8)
                  0#i64 0#usize (by simp) (by norm_num) (by norm_num)
                step with lp
                step
                simp_all <;> omega
              · simp_all
          · simp
            have htlen : 0 < t.length := by simp [Slice.length, hval]
            step
            simp [core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit]
            split
            · have lp := loop_bound
                (⟨c :: xs, by simpa [hval] using t.property⟩ : Slice Std.U8)
                0#i64 0#usize (by simp) (by norm_num) (by norm_num)
              step with lp
              step
              simp_all <;> omega
            · simp_all
    have hb := parse_bound s
    rw [h] at hb
    exact hb e rest rfl
  · intro s hs
    have ht : s = (⟨[54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8], by
      rcases Usize.bounds_eq with q | q <;> norm_num [q, U32.max_eq, U64.max_eq]⟩ : Slice Std.U8) := by
      exact (Slice.eq_iff _ _).2 hs
    rw [ht]
    refine ⟨⟨[], by simp⟩, ?_, by scalar_tac⟩
    simp [num.imp.dec2flt.parse.parse_scientific,
      core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
      core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit,
      Slice.index_usize]
    simp [num.imp.dec2flt.parse.parse_scientific_loop]
    rw [Aeneas.Std.loop.eq_1]
    have first_product : (10#i64 * 0#i64) = ok 0#i64 := by rfl
    have first_sum : (0#i64 + 6#i64) = ok 6#i64 := by rfl
    have first_digit : (UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = 6#i64 := by rfl
    have first_sum2 : (0#i64 + UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_sum3 : (0#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_count : (0#usize + 1#usize) = ok 1#usize := by
      change UScalar.add (0#usize) (1#usize) = ok 1#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have second_product : (10#i64 * 6#i64) = ok 60#i64 := by rfl
    have second_sum : (60#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65#i64 := by rfl
    have second_count : (1#usize + 1#usize) = ok 2#usize := by
      change UScalar.add (1#usize) (1#usize) = ok 2#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have third_product : (10#i64 * 65#i64) = ok 650#i64 := by rfl
    have third_sum : (650#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 655#i64 := by rfl
    have third_count : (2#usize + 1#usize) = ok 3#usize := by
      change UScalar.add (2#usize) (1#usize) = ok 3#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fourth_product : (10#i64 * 655#i64) = ok 6550#i64 := by rfl
    have fourth_sum : (6550#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 51#u8 48#u8)) = ok 6553#i64 := by rfl
    have fourth_count : (3#usize + 1#usize) = ok 4#usize := by
      change UScalar.add (3#usize) (1#usize) = ok 4#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
    have fifth_sum : (65530#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 54#u8 48#u8)) = ok 65536#i64 := by rfl
    have fifth_count : (4#usize + 1#usize) = ok 5#usize := by
      change UScalar.add (4#usize) (1#usize) = ok 5#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have sixth_count : (5#usize + 1#usize) = ok 6#usize := by
      change UScalar.add (5#usize) (1#usize) = ok 6#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
      first_product, first_sum, first_count, first_digit, first_sum2]
    rw [first_sum3]
    simp
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [second_product, second_sum, second_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [third_product, third_sum, third_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fourth_product, fourth_sum, fourth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fifth_product, fifth_sum, fifth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq, sixth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
      core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
      Slice.length, List.drop]
  · intro s hs
    have ht : s = (⟨[45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8], by
      rcases Usize.bounds_eq with q | q <;> norm_num [q, U32.max_eq, U64.max_eq]⟩ : Slice Std.U8) := by
      exact (Slice.eq_iff _ _).2 hs
    rw [ht]
    refine ⟨⟨[], by simp⟩, ?_, by scalar_tac⟩
    simp [num.imp.dec2flt.parse.parse_scientific,
      core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
      core.num.U8.is_ascii_digit, dec2flt_model.ModelU8IsAsciiDigit,
      Slice.index_usize]
    simp [num.imp.dec2flt.parse.parse_scientific_loop]
    rw [Aeneas.Std.loop.eq_1]
    have first_product : (10#i64 * 0#i64) = ok 0#i64 := by rfl
    have first_sum : (0#i64 + 6#i64) = ok 6#i64 := by rfl
    have first_digit : (UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = 6#i64 := by rfl
    have first_sum2 : (0#i64 + UScalar.hcast IScalarTy.I64 (core.num.U8.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_sum3 : (0#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 54#u8 48#u8)) = ok 6#i64 := by rfl
    have first_count : (0#usize + 1#usize) = ok 1#usize := by
      change UScalar.add (0#usize) (1#usize) = ok 1#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have second_product : (10#i64 * 6#i64) = ok 60#i64 := by rfl
    have second_sum : (60#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65#i64 := by rfl
    have second_count : (1#usize + 1#usize) = ok 2#usize := by
      change UScalar.add (1#usize) (1#usize) = ok 2#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have third_product : (10#i64 * 65#i64) = ok 650#i64 := by rfl
    have third_sum : (650#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 655#i64 := by rfl
    have third_count : (2#usize + 1#usize) = ok 3#usize := by
      change UScalar.add (2#usize) (1#usize) = ok 3#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fourth_product : (10#i64 * 655#i64) = ok 6550#i64 := by rfl
    have fourth_sum : (6550#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 51#u8 48#u8)) = ok 6553#i64 := by rfl
    have fourth_count : (3#usize + 1#usize) = ok 4#usize := by
      change UScalar.add (3#usize) (1#usize) = ok 4#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have fifth_product : (10#i64 * 6553#i64) = ok 65530#i64 := by rfl
    have fifth_sum : (65530#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 53#u8 48#u8)) = ok 65535#i64 := by rfl
    have fifth_count : (4#usize + 1#usize) = ok 5#usize := by
      change UScalar.add (4#usize) (1#usize) = ok 5#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    have sixth_product : (10#i64 * 65535#i64) = ok 655350#i64 := by rfl
    have sixth_sum : (655350#i64 + UScalar.hcast IScalarTy.I64 (UScalar.wrapping_sub 57#u8 48#u8)) = ok 655359#i64 := by rfl
    have sixth_count : (5#usize + 1#usize) = ok 6#usize := by
      change UScalar.add (5#usize) (1#usize) = ok 6#usize
      unfold UScalar.add UScalar.tryMk UScalar.tryMkOpt
      simp [Result.ofOption, UScalar.check_bounds, Dec2Flt.configured_x86_64_numBits]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
      first_product, first_sum, first_count, first_digit, first_sum2]
    rw [first_sum3]
    simp
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [second_product, second_sum, second_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [third_product, third_sum, third_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fourth_product, fourth_sum, fourth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq]
    simp [fifth_product, fifth_sum, fifth_count]
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body, Slice.index_usize,
      Aeneas.Std.lift, core.num.U8.wrapping_sub, U8.size_eq,
      sixth_product, sixth_sum, sixth_count]
    rw [Aeneas.Std.loop.eq_1]
    have neg_final : IScalar.neg (655359#i64) = ok ((-655359)#i64) := by rfl
    simp [num.imp.dec2flt.parse.parse_scientific_loop.body,
      core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
      Slice.length, List.drop, HNeg.hNeg, IScalar.neg, neg_final,
      IScalar.tryMk, IScalar.tryMkOpt, Result.ofOption, IScalar.check_bounds,
      Dec2Flt.configured_x86_64_numBits]

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
All 31 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperScientificExponentBounds",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "dfd8006fdcfedf7db77d427c50c122511d4ac85a76044f473a20e2622b17468f",
  "active_statement_hash": "e8915816dcbdc6f161a1c74e4c4de909685024c968b0ccbdbef66564f27127f8",
  "kernel_axioms": [
    "Classical.choice",
    "Dec2Flt.configured_x86_64_numBits",
    "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": "revalidate-cycle-28",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "num_imp_dec2flt_parse_parse_scientific": "ba81300a2601d639"
  },
  "strict_definition_deps": {
    "ModelSliceSplitFirst": "4ed9c51a5bb9fb58",
    "ModelU8IsAsciiDigit": "67d39fc6c37cfc41",
    "Preamble": "956f3baee2191107",
    "num_imp_dec2flt_parse_parse_scientific": "76b01b9377828a5f"
  }
}
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:6e85482a90f43c77cd2edfd8bce6f685a7b09b8e72e923f99e220cd17f084953",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}