Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Scientific exponent bounds and boundary suffixes
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
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.655360, successive accumulator values after the first five
digits are
-655359, the leading minus is removed before the loop.
The six digit iterations have values
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.
Inspect related source (47)
- parse_scientific · dec2flt/parse.rs:121 Program Rust
- parse_scientific_loop · dec2flt/parse.rs:142 Program Rust
- body · dec2flt/parse.rs:142 Program Rust
More program dependencies (14)
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (30)
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
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
- Classical.choice
- Dec2Flt.configured_x86_64_numBits
- Quot.sound
- propext
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
- Binary64Model
- Binary64ModelDefault
- F64
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- NumberHelperScientificExponentBounds
- Preamble
- core num FpCategory
- num imp dec2flt parse parse scientific
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"
}