Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Exact bounded digit scan
try_parse_digits returns the suffix T and an unsigned word whose
natural value is exactly F(D,a).Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.NumberHelperEightDigitWord
import Tablet.NumberHelperParseEightDigitsExact
import Tablet.NumberHelperReadEightBytes
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: NumberHelperDigitScanExact]
theorem NumberHelperDigitScanExact :
forall (s : Slice Std.U8) (initial : Std.U64)
(digits tail : List Std.U8),
s.val = digits ++ tail ->
(forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) ->
(forall b rest, tail = b :: rest ->
Not (48 <= b.val /\ b.val <= 57)) ->
s.val.length <= 9223372036854775807 ->
digits.foldl (fun a b => 10 * a + (b.val - 48)) initial.val <=
U64.max ->
exists (value : Std.U64) (rest : Slice Std.U8),
num.imp.dec2flt.parse.try_parse_digits s initial = ok (rest, value) /\
rest.val = tail /\
value.val = digits.foldl
(fun a b => 10 * a + (b.val - 48)) initial.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
Lean proof
intro s initial digits tail hs hdigits htail hlen hfinal
let digitStep : Nat -> Std.U8 -> Nat :=
fun a b => 10 * a + (b.val - 48)
have fold_ge : forall (l : List Std.U8) (a : Nat),
a <= l.foldl digitStep a := by
intro l
induction l with
| nil => intro a; simp
| cons b bs ih =>
intro a
simp only [List.foldl_cons]
exact le_trans (by simp [digitStep]; omega) (ih _)
have fast : forall (t : Slice Std.U8) (a : Std.U64)
(consumed rem : List Std.U8),
digits = consumed ++ rem ->
t.val = rem ++ tail ->
a.val = consumed.foldl digitStep initial.val ->
(forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) ->
t.val.length <= 9223372036854775807 ->
num.imp.dec2flt.parse.try_parse_digits_loop0 t a
⦃ p => exists used remaining : List Std.U8,
digits = used ++ remaining /\
p.1.val = remaining ++ tail /\
p.2.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
p.1.val.length <= 9223372036854775807 ⦄ := by
intro t a consumed rem hpartition ht hvalue hrem htlen
unfold num.imp.dec2flt.parse.try_parse_digits_loop0
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Slice Std.U8 × Std.U64 => p.1.length)
(fun p => exists used remaining : List Std.U8,
digits = used ++ remaining /\
p.1.val = remaining ++ tail /\
p.2.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
p.1.val.length <= 9223372036854775807)
(fun p => exists used remaining : List Std.U8,
digits = used ++ remaining /\
p.1.val = remaining ++ tail /\
p.2.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
p.1.val.length <= 9223372036854775807)
(fun p => num.imp.dec2flt.parse.try_parse_digits_loop0.body p.1 p.2)
(t, a)
· intro p hp
rcases p with ⟨u, x⟩
rcases hp with
⟨used, remaining, hpart, hurem, hx, hremaining, hulen⟩
change u.val = remaining ++ tail at hurem
change u.val.length <= 9223372036854775807 at hulen
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body, WP.spec_ok,
Slice.length]
split
· rename_i h8
obtain ⟨chunk, hread, hbyte⟩ := NumberHelperReadEightBytes u h8
rw [hread]
simp [num.imp.dec2flt.common.is_8digits, Aeneas.Std.lift]
split
· rename_i hacceptedRaw
have haccepted :
num.imp.dec2flt.common.is_8digits chunk = ok true := by
simp [num.imp.dec2flt.common.is_8digits, Aeneas.Std.lift,
hacceptedRaw]
have hrem8 : 8 <= remaining.length := by
by_contra hn
have hrem_lt : remaining.length < 8 := by omega
have htail_pos : 0 < tail.length := by
by_contra hzero
have ht0 : tail = [] := List.eq_nil_of_length_eq_zero (by omega)
have heq := congrArg List.length hurem
simp [ht0] at heq
omega
obtain ⟨b, rest, htail_eq⟩ :=
List.exists_cons_of_length_pos htail_pos
have hindex : remaining.length < u.val.length := by omega
have hbyte_eq := hbyte remaining.length hrem_lt
have hword_digit :=
NumberHelperEightDigitWord chunk haccepted remaining.length
hrem_lt
have hu_digit :
48 <= (u.val[remaining.length]'hindex).val /\
(u.val[remaining.length]'hindex).val <= 57 := by
omega
have hu_eq : (u.val[remaining.length]'hindex) = b := by
simp [hurem, htail_eq]
rw [hu_eq] at hu_digit
exact (htail b rest htail_eq) hu_digit
obtain ⟨z, hparse, hz⟩ :=
NumberHelperParseEightDigitsExact chunk haccepted
have hprefixShape : exists b0 b1 b2 b3 b4 b5 b6 b7 rest,
remaining = b0 :: b1 :: b2 :: b3 :: b4 :: b5 :: b6 ::
b7 :: rest := by
cases remaining with
| nil => simp at hrem8
| cons b0 r0 =>
cases r0 with
| nil => simp at hrem8
| cons b1 r1 =>
cases r1 with
| nil => simp at hrem8
| cons b2 r2 =>
cases r2 with
| nil => simp at hrem8
| cons b3 r3 =>
cases r3 with
| nil => simp at hrem8
| cons b4 r4 =>
cases r4 with
| nil => simp at hrem8
| cons b5 r5 =>
cases r5 with
| nil => simp at hrem8
| cons b6 r6 =>
cases r6 with
| nil => simp at hrem8
| cons b7 rest =>
exact ⟨b0, b1, b2, b3, b4, b5, b6, b7,
rest, rfl⟩
obtain ⟨b0, b1, b2, b3, b4, b5, b6, b7, more, hshape⟩ :=
hprefixShape
have hb0 := hbyte 0 (by omega)
have hb1 := hbyte 1 (by omega)
have hb2 := hbyte 2 (by omega)
have hb3 := hbyte 3 (by omega)
have hb4 := hbyte 4 (by omega)
have hb5 := hbyte 5 (by omega)
have hb6 := hbyte 6 (by omega)
have hb7 := hbyte 7 (by omega)
rw [hshape] at hurem
simp only [hurem, List.append_assoc, List.cons_append,
List.getElem_cons_zero, List.getElem_cons_succ] at hb0 hb1 hb2 hb3 hb4 hb5 hb6 hb7
have hblock :
([b0, b1, b2, b3, b4, b5, b6, b7] : List Std.U8).foldl
digitStep x.val =
100000000 * x.val + z.val := by
rw [hz]
simp only [hb0, hb1, hb2, hb3, hb4, hb5, hb6, hb7]
simp [digitStep]
omega
let used' := used ++ remaining.take 8
let remaining' := remaining.drop 8
have hpart' : digits = used' ++ remaining' := by
simp only [used', remaining', hpart, List.append_assoc]
rw [List.take_append_drop]
have husedValue : used'.foldl digitStep initial.val =
100000000 * x.val + z.val := by
simp only [used', List.foldl_append]
rw [← hx]
rw [hshape]
norm_num [hblock]
have hprefixBound : used'.foldl digitStep initial.val <= U64.max := by
have hrestGe := fold_ge remaining'
(used'.foldl digitStep initial.val)
rw [← List.foldl_append, ← hpart'] at hrestGe
exact le_trans hrestGe hfinal
let next := core.num.U64.wrapping_add
(core.num.U64.wrapping_mul x 100000000#u64) z
have hnext : next.val = used'.foldl digitStep initial.val := by
rw [husedValue]
simp only [next, core.num.U64.wrapping_add_val_eq,
core.num.U64.wrapping_mul_val_eq]
simp [UScalar.size, U64.size_eq]
have hsum : x.val * 100000000 + z.val <
18446744073709551616 := by
rw [husedValue] at hprefixBound
rw [U64.max_eq] at hprefixBound
omega
rw [Nat.mod_eq_of_lt hsum]
omega
rw [hparse]
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, Slice.length, WP.spec_ok, h8, next]
constructor
· refine ⟨used', remaining', hpart', ?_, ?_, ?_, ?_⟩
· simp [remaining', hurem, hshape]
· simpa [next, core.num.U64.wrapping_add_val_eq,
core.num.U64.wrapping_mul_val_eq, U64.size_eq] using hnext
· intro b hb
exact hremaining b (List.mem_of_mem_drop hb)
· omega
· omega
· simpa [WP.spec_ok] using
(show exists used remaining : List Std.U8,
digits = used ++ remaining /\
u.val = remaining ++ tail /\
x.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
u.val.length <= 9223372036854775807 from
⟨used, remaining, hpart, hurem, hx, hremaining, hulen⟩)
· simpa [WP.spec_ok] using
(show exists used remaining : List Std.U8,
digits = used ++ remaining /\
u.val = remaining ++ tail /\
x.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
u.val.length <= 9223372036854775807 from
⟨used, remaining, hpart, hurem, hx, hremaining, hulen⟩)
· simpa using
(show exists used remaining : List Std.U8,
digits = used ++ remaining /\
t.val = remaining ++ tail /\
a.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
t.val.length <= 9223372036854775807 from
⟨consumed, rem, hpartition, ht, hvalue, hrem, htlen⟩)
have scalar : forall (t : Slice Std.U8) (a : Std.U64)
(used rem : List Std.U8),
digits = used ++ rem ->
t.val = rem ++ tail ->
a.val = used.foldl digitStep initial.val ->
(forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) ->
t.val.length <= 9223372036854775807 ->
num.imp.dec2flt.parse.try_parse_digits_loop1 t a 0#usize
⦃ p => p.2.val = rem.length /\
p.1.val = digits.foldl digitStep initial.val ⦄ := by
intro t a used rem hpart ht ha hrem htlen
unfold num.imp.dec2flt.parse.try_parse_digits_loop1
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Std.U64 × Std.Usize => rem.length - p.2.val)
(fun p => p.2.val <= rem.length /\
p.1.val = (rem.take p.2.val).foldl digitStep a.val)
(fun p => p.2.val = rem.length /\
p.1.val = digits.foldl digitStep initial.val)
(fun p =>
num.imp.dec2flt.parse.try_parse_digits_loop1.body t p.1 p.2)
(a, 0#usize)
· intro p hp
rcases p with ⟨x, count⟩
rcases hp with ⟨hcount, hx⟩
change count.val <= rem.length at hcount
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body, WP.spec_ok,
Slice.length]
split
· rename_i hcount_t
step
by_cases hinside : count.val < rem.length
· have hi_eq : i1 = rem[count.val]'hinside := by
rw [i1_post]
simp [ht, hinside]
have hi_mem : List.Mem i1 rem := by
rw [hi_eq]
exact List.getElem_mem _
have hi_digit := hrem i1 hi_mem
step
have hi2_val : i2.val = i1.val - 48 := by
rw [i2_post]
rw [core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
omega
have hi2_lt : i2.val < 10 := by omega
simp [hi2_lt]
step
step
step
step
step
have hnextCount : count1.val = count.val + 1 := by
simpa using count1_post
have hdigitVal : digit.val = i1.val - 48 := by
rw [digit_post]
rw [core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
omega
have hi4Val : i4.val = i1.val - 48 := by
have h := congrArg UScalar.val i4_post
simpa [hdigitVal] using h
have hprefix :
(rem.take (count.val + 1)).foldl digitStep a.val =
10 * x.val + (i1.val - 48) := by
rw [List.take_succ_eq_append_getElem hinside, List.foldl_append,
List.foldl_cons, List.foldl_nil, ← hi_eq, hx]
have hprefixBound :
(rem.take (count.val + 1)).foldl digitStep a.val <=
U64.max := by
have hdropGe := fold_ge (rem.drop (count.val + 1))
((rem.take (count.val + 1)).foldl digitStep a.val)
rw [← List.foldl_append, List.take_append_drop] at hdropGe
have hfull : rem.foldl digitStep a.val =
digits.foldl digitStep initial.val := by
rw [hpart, List.foldl_append, ← ha]
rw [hfull] at hdropGe
exact le_trans hdropGe hfinal
have hi3Val : i3.val = 10 * x.val := by
rw [i3_post, core.num.U64.wrapping_mul_val_eq]
simp [UScalar.size, U64.size_eq]
rw [hprefix] at hprefixBound
rw [U64.max_eq] at hprefixBound
rw [Nat.mod_eq_of_lt (by omega)]
omega
have hx1Val : x1.val =
(rem.take (count.val + 1)).foldl digitStep a.val := by
rw [x1_post, core.num.U64.wrapping_add_val_eq]
simp [UScalar.size, U64.size_eq, hi3Val, hi4Val]
rw [hprefix] at hprefixBound ⊢
rw [U64.max_eq] at hprefixBound
rw [Nat.mod_eq_of_lt (by omega)]
constructor
· rw [hnextCount]
omega
· constructor
· rw [hnextCount, hx1Val]
· rw [hnextCount]
omega
· have hcount_eq : count.val = rem.length := by omega
have htail_pos : 0 < tail.length := by
have hlen_eq := congrArg List.length ht
simp at hlen_eq
omega
obtain ⟨b, rest, htail_eq⟩ :=
List.exists_cons_of_length_pos htail_pos
have hi_eq : i1 = b := by
rw [i1_post]
simp [ht, htail_eq, hcount_eq]
have hb_not := htail b rest htail_eq
step
have hi2_not : Not (i2.val < 10) := by
rw [i2_post, hi_eq]
rw [core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
scalar_tac
simp [hi2_not, WP.spec_ok, hcount_eq]
rw [hpart, List.foldl_append, ← ha]
simpa [hcount_eq] using hx
· rename_i hcount_not
simp [WP.spec_ok]
have hlen_eq := congrArg List.length ht
simp at hlen_eq
have hcount_eq : count.val = rem.length := by omega
constructor
· exact hcount_eq
· rw [hpart, List.foldl_append, ← ha]
simpa [hcount_eq] using hx
· simp
unfold num.imp.dec2flt.parse.try_parse_digits
have hf := fast s initial [] digits (by simp) hs (by simp)
hdigits hlen
obtain ⟨p, hfast, hfp⟩ := Aeneas.Std.WP.spec_imp_exists hf
rcases p with ⟨s1, x1⟩
rcases hfp with
⟨used, rem, hpart, hs1, hx1, hrem, hs1len⟩
change s1.val = rem ++ tail at hs1
change s1.val.length <= 9223372036854775807 at hs1len
have hsc := scalar s1 x1 used rem hpart hs1 hx1 hrem hs1len
obtain ⟨q, hscalar, hq⟩ := Aeneas.Std.WP.spec_imp_exists hsc
rcases q with ⟨x2, count⟩
rcases hq with ⟨hcount, hx2⟩
change count.val = rem.length at hcount
have hcount_le : count.val <= s1.val.length := by
rw [hcount, hs1]
simp
simp [hfast, hscalar]
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, Slice.length, hcount_le]
constructor
· rw [hcount, hs1, List.drop_append_of_le_length (Nat.le_refl _)]
simp
· exact hx2
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.NumberHelperEightDigitWord
import Tablet.NumberHelperParseEightDigitsExact
import Tablet.NumberHelperReadEightBytes
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: NumberHelperDigitScanExact]
theorem NumberHelperDigitScanExact :
forall (s : Slice Std.U8) (initial : Std.U64)
(digits tail : List Std.U8),
s.val = digits ++ tail ->
(forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) ->
(forall b rest, tail = b :: rest ->
Not (48 <= b.val /\ b.val <= 57)) ->
s.val.length <= 9223372036854775807 ->
digits.foldl (fun a b => 10 * a + (b.val - 48)) initial.val <=
U64.max ->
exists (value : Std.U64) (rest : Slice Std.U8),
num.imp.dec2flt.parse.try_parse_digits s initial = ok (rest, value) /\
rest.val = tail /\
value.val = digits.foldl
(fun a b => 10 * a + (b.val - 48)) initial.val := by
-- BODY
intro s initial digits tail hs hdigits htail hlen hfinal
let digitStep : Nat -> Std.U8 -> Nat :=
fun a b => 10 * a + (b.val - 48)
have fold_ge : forall (l : List Std.U8) (a : Nat),
a <= l.foldl digitStep a := by
intro l
induction l with
| nil => intro a; simp
| cons b bs ih =>
intro a
simp only [List.foldl_cons]
exact le_trans (by simp [digitStep]; omega) (ih _)
have fast : forall (t : Slice Std.U8) (a : Std.U64)
(consumed rem : List Std.U8),
digits = consumed ++ rem ->
t.val = rem ++ tail ->
a.val = consumed.foldl digitStep initial.val ->
(forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) ->
t.val.length <= 9223372036854775807 ->
num.imp.dec2flt.parse.try_parse_digits_loop0 t a
⦃ p => exists used remaining : List Std.U8,
digits = used ++ remaining /\
p.1.val = remaining ++ tail /\
p.2.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
p.1.val.length <= 9223372036854775807 ⦄ := by
intro t a consumed rem hpartition ht hvalue hrem htlen
unfold num.imp.dec2flt.parse.try_parse_digits_loop0
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Slice Std.U8 × Std.U64 => p.1.length)
(fun p => exists used remaining : List Std.U8,
digits = used ++ remaining /\
p.1.val = remaining ++ tail /\
p.2.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
p.1.val.length <= 9223372036854775807)
(fun p => exists used remaining : List Std.U8,
digits = used ++ remaining /\
p.1.val = remaining ++ tail /\
p.2.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
p.1.val.length <= 9223372036854775807)
(fun p => num.imp.dec2flt.parse.try_parse_digits_loop0.body p.1 p.2)
(t, a)
· intro p hp
rcases p with ⟨u, x⟩
rcases hp with
⟨used, remaining, hpart, hurem, hx, hremaining, hulen⟩
change u.val = remaining ++ tail at hurem
change u.val.length <= 9223372036854775807 at hulen
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body, WP.spec_ok,
Slice.length]
split
· rename_i h8
obtain ⟨chunk, hread, hbyte⟩ := NumberHelperReadEightBytes u h8
rw [hread]
simp [num.imp.dec2flt.common.is_8digits, Aeneas.Std.lift]
split
· rename_i hacceptedRaw
have haccepted :
num.imp.dec2flt.common.is_8digits chunk = ok true := by
simp [num.imp.dec2flt.common.is_8digits, Aeneas.Std.lift,
hacceptedRaw]
have hrem8 : 8 <= remaining.length := by
by_contra hn
have hrem_lt : remaining.length < 8 := by omega
have htail_pos : 0 < tail.length := by
by_contra hzero
have ht0 : tail = [] := List.eq_nil_of_length_eq_zero (by omega)
have heq := congrArg List.length hurem
simp [ht0] at heq
omega
obtain ⟨b, rest, htail_eq⟩ :=
List.exists_cons_of_length_pos htail_pos
have hindex : remaining.length < u.val.length := by omega
have hbyte_eq := hbyte remaining.length hrem_lt
have hword_digit :=
NumberHelperEightDigitWord chunk haccepted remaining.length
hrem_lt
have hu_digit :
48 <= (u.val[remaining.length]'hindex).val /\
(u.val[remaining.length]'hindex).val <= 57 := by
omega
have hu_eq : (u.val[remaining.length]'hindex) = b := by
simp [hurem, htail_eq]
rw [hu_eq] at hu_digit
exact (htail b rest htail_eq) hu_digit
obtain ⟨z, hparse, hz⟩ :=
NumberHelperParseEightDigitsExact chunk haccepted
have hprefixShape : exists b0 b1 b2 b3 b4 b5 b6 b7 rest,
remaining = b0 :: b1 :: b2 :: b3 :: b4 :: b5 :: b6 ::
b7 :: rest := by
cases remaining with
| nil => simp at hrem8
| cons b0 r0 =>
cases r0 with
| nil => simp at hrem8
| cons b1 r1 =>
cases r1 with
| nil => simp at hrem8
| cons b2 r2 =>
cases r2 with
| nil => simp at hrem8
| cons b3 r3 =>
cases r3 with
| nil => simp at hrem8
| cons b4 r4 =>
cases r4 with
| nil => simp at hrem8
| cons b5 r5 =>
cases r5 with
| nil => simp at hrem8
| cons b6 r6 =>
cases r6 with
| nil => simp at hrem8
| cons b7 rest =>
exact ⟨b0, b1, b2, b3, b4, b5, b6, b7,
rest, rfl⟩
obtain ⟨b0, b1, b2, b3, b4, b5, b6, b7, more, hshape⟩ :=
hprefixShape
have hb0 := hbyte 0 (by omega)
have hb1 := hbyte 1 (by omega)
have hb2 := hbyte 2 (by omega)
have hb3 := hbyte 3 (by omega)
have hb4 := hbyte 4 (by omega)
have hb5 := hbyte 5 (by omega)
have hb6 := hbyte 6 (by omega)
have hb7 := hbyte 7 (by omega)
rw [hshape] at hurem
simp only [hurem, List.append_assoc, List.cons_append,
List.getElem_cons_zero, List.getElem_cons_succ] at hb0 hb1 hb2 hb3 hb4 hb5 hb6 hb7
have hblock :
([b0, b1, b2, b3, b4, b5, b6, b7] : List Std.U8).foldl
digitStep x.val =
100000000 * x.val + z.val := by
rw [hz]
simp only [hb0, hb1, hb2, hb3, hb4, hb5, hb6, hb7]
simp [digitStep]
omega
let used' := used ++ remaining.take 8
let remaining' := remaining.drop 8
have hpart' : digits = used' ++ remaining' := by
simp only [used', remaining', hpart, List.append_assoc]
rw [List.take_append_drop]
have husedValue : used'.foldl digitStep initial.val =
100000000 * x.val + z.val := by
simp only [used', List.foldl_append]
rw [← hx]
rw [hshape]
norm_num [hblock]
have hprefixBound : used'.foldl digitStep initial.val <= U64.max := by
have hrestGe := fold_ge remaining'
(used'.foldl digitStep initial.val)
rw [← List.foldl_append, ← hpart'] at hrestGe
exact le_trans hrestGe hfinal
let next := core.num.U64.wrapping_add
(core.num.U64.wrapping_mul x 100000000#u64) z
have hnext : next.val = used'.foldl digitStep initial.val := by
rw [husedValue]
simp only [next, core.num.U64.wrapping_add_val_eq,
core.num.U64.wrapping_mul_val_eq]
simp [UScalar.size, U64.size_eq]
have hsum : x.val * 100000000 + z.val <
18446744073709551616 := by
rw [husedValue] at hprefixBound
rw [U64.max_eq] at hprefixBound
omega
rw [Nat.mod_eq_of_lt hsum]
omega
rw [hparse]
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, Slice.length, WP.spec_ok, h8, next]
constructor
· refine ⟨used', remaining', hpart', ?_, ?_, ?_, ?_⟩
· simp [remaining', hurem, hshape]
· simpa [next, core.num.U64.wrapping_add_val_eq,
core.num.U64.wrapping_mul_val_eq, U64.size_eq] using hnext
· intro b hb
exact hremaining b (List.mem_of_mem_drop hb)
· omega
· omega
· simpa [WP.spec_ok] using
(show exists used remaining : List Std.U8,
digits = used ++ remaining /\
u.val = remaining ++ tail /\
x.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
u.val.length <= 9223372036854775807 from
⟨used, remaining, hpart, hurem, hx, hremaining, hulen⟩)
· simpa [WP.spec_ok] using
(show exists used remaining : List Std.U8,
digits = used ++ remaining /\
u.val = remaining ++ tail /\
x.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
u.val.length <= 9223372036854775807 from
⟨used, remaining, hpart, hurem, hx, hremaining, hulen⟩)
· simpa using
(show exists used remaining : List Std.U8,
digits = used ++ remaining /\
t.val = remaining ++ tail /\
a.val = used.foldl digitStep initial.val /\
(forall b, List.Mem b remaining ->
48 <= b.val /\ b.val <= 57) /\
t.val.length <= 9223372036854775807 from
⟨consumed, rem, hpartition, ht, hvalue, hrem, htlen⟩)
have scalar : forall (t : Slice Std.U8) (a : Std.U64)
(used rem : List Std.U8),
digits = used ++ rem ->
t.val = rem ++ tail ->
a.val = used.foldl digitStep initial.val ->
(forall b, List.Mem b rem -> 48 <= b.val /\ b.val <= 57) ->
t.val.length <= 9223372036854775807 ->
num.imp.dec2flt.parse.try_parse_digits_loop1 t a 0#usize
⦃ p => p.2.val = rem.length /\
p.1.val = digits.foldl digitStep initial.val ⦄ := by
intro t a used rem hpart ht ha hrem htlen
unfold num.imp.dec2flt.parse.try_parse_digits_loop1
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Std.U64 × Std.Usize => rem.length - p.2.val)
(fun p => p.2.val <= rem.length /\
p.1.val = (rem.take p.2.val).foldl digitStep a.val)
(fun p => p.2.val = rem.length /\
p.1.val = digits.foldl digitStep initial.val)
(fun p =>
num.imp.dec2flt.parse.try_parse_digits_loop1.body t p.1 p.2)
(a, 0#usize)
· intro p hp
rcases p with ⟨x, count⟩
rcases hp with ⟨hcount, hx⟩
change count.val <= rem.length at hcount
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body, WP.spec_ok,
Slice.length]
split
· rename_i hcount_t
step
by_cases hinside : count.val < rem.length
· have hi_eq : i1 = rem[count.val]'hinside := by
rw [i1_post]
simp [ht, hinside]
have hi_mem : List.Mem i1 rem := by
rw [hi_eq]
exact List.getElem_mem _
have hi_digit := hrem i1 hi_mem
step
have hi2_val : i2.val = i1.val - 48 := by
rw [i2_post]
rw [core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
omega
have hi2_lt : i2.val < 10 := by omega
simp [hi2_lt]
step
step
step
step
step
have hnextCount : count1.val = count.val + 1 := by
simpa using count1_post
have hdigitVal : digit.val = i1.val - 48 := by
rw [digit_post]
rw [core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
omega
have hi4Val : i4.val = i1.val - 48 := by
have h := congrArg UScalar.val i4_post
simpa [hdigitVal] using h
have hprefix :
(rem.take (count.val + 1)).foldl digitStep a.val =
10 * x.val + (i1.val - 48) := by
rw [List.take_succ_eq_append_getElem hinside, List.foldl_append,
List.foldl_cons, List.foldl_nil, ← hi_eq, hx]
have hprefixBound :
(rem.take (count.val + 1)).foldl digitStep a.val <=
U64.max := by
have hdropGe := fold_ge (rem.drop (count.val + 1))
((rem.take (count.val + 1)).foldl digitStep a.val)
rw [← List.foldl_append, List.take_append_drop] at hdropGe
have hfull : rem.foldl digitStep a.val =
digits.foldl digitStep initial.val := by
rw [hpart, List.foldl_append, ← ha]
rw [hfull] at hdropGe
exact le_trans hdropGe hfinal
have hi3Val : i3.val = 10 * x.val := by
rw [i3_post, core.num.U64.wrapping_mul_val_eq]
simp [UScalar.size, U64.size_eq]
rw [hprefix] at hprefixBound
rw [U64.max_eq] at hprefixBound
rw [Nat.mod_eq_of_lt (by omega)]
omega
have hx1Val : x1.val =
(rem.take (count.val + 1)).foldl digitStep a.val := by
rw [x1_post, core.num.U64.wrapping_add_val_eq]
simp [UScalar.size, U64.size_eq, hi3Val, hi4Val]
rw [hprefix] at hprefixBound ⊢
rw [U64.max_eq] at hprefixBound
rw [Nat.mod_eq_of_lt (by omega)]
constructor
· rw [hnextCount]
omega
· constructor
· rw [hnextCount, hx1Val]
· rw [hnextCount]
omega
· have hcount_eq : count.val = rem.length := by omega
have htail_pos : 0 < tail.length := by
have hlen_eq := congrArg List.length ht
simp at hlen_eq
omega
obtain ⟨b, rest, htail_eq⟩ :=
List.exists_cons_of_length_pos htail_pos
have hi_eq : i1 = b := by
rw [i1_post]
simp [ht, htail_eq, hcount_eq]
have hb_not := htail b rest htail_eq
step
have hi2_not : Not (i2.val < 10) := by
rw [i2_post, hi_eq]
rw [core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
scalar_tac
simp [hi2_not, WP.spec_ok, hcount_eq]
rw [hpart, List.foldl_append, ← ha]
simpa [hcount_eq] using hx
· rename_i hcount_not
simp [WP.spec_ok]
have hlen_eq := congrArg List.length ht
simp at hlen_eq
have hcount_eq : count.val = rem.length := by omega
constructor
· exact hcount_eq
· rw [hpart, List.foldl_append, ← ha]
simpa [hcount_eq] using hx
· simp
unfold num.imp.dec2flt.parse.try_parse_digits
have hf := fast s initial [] digits (by simp) hs (by simp)
hdigits hlen
obtain ⟨p, hfast, hfp⟩ := Aeneas.Std.WP.spec_imp_exists hf
rcases p with ⟨s1, x1⟩
rcases hfp with
⟨used, rem, hpart, hs1, hx1, hrem, hs1len⟩
change s1.val = rem ++ tail at hs1
change s1.val.length <= 9223372036854775807 at hs1len
have hsc := scalar s1 x1 used rem hpart hs1 hx1 hrem hs1len
obtain ⟨q, hscalar, hq⟩ := Aeneas.Std.WP.spec_imp_exists hsc
rcases q with ⟨x2, count⟩
rcases hq with ⟨hcount, hx2⟩
change count.val = rem.length at hcount
have hcount_le : count.val <= s1.val.length := by
rw [hcount, hs1]
simp
simp [hfast, hscalar]
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, Slice.length, hcount_le]
constructor
· rw [hcount, hs1, List.drop_append_of_le_length (Nat.le_refl _)]
simp
· exact hx2
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (55)
- try_parse_digits · dec2flt/parse.rs:30 Program Rust
- try_parse_digits_loop0 · dec2flt/parse.rs:33 Program Rust
- body · dec2flt/parse.rs:33 Program Rust
More program dependencies (22)
- try_parse_digits_loop1 · dec2flt/parse.rs:50 Program Rust
- body · dec2flt/parse.rs:50 Program Rust
- read_u64 · dec2flt/common.rs:22 Program Rust
- is_8digits · dec2flt/common.rs:44 Program Rust
- parse_8digits · dec2flt/parse.rs:18 Program Rust
- 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:56 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.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
- 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
- NumberHelperDigitScanExact
- NumberHelperEightDigitWord
- NumberHelperParseEightDigitsExact
- NumberHelperReadEightBytes
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- num imp dec2flt common is 8digits
All 11 entries
- NumberHelperDigitScanExact
- NumberHelperEightDigitWord
- NumberHelperParseEightDigitsExact
- NumberHelperReadEightBytes
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- num imp dec2flt common is 8digits
- num imp dec2flt parse parse 8digits
- num imp dec2flt parse parse 8digits MASK
- num imp dec2flt parse parse 8digits MUL1
- num imp dec2flt parse parse 8digits MUL2
- num imp dec2flt parse try parse digits
Technical checking records
Local closure summary
{
"node": "NumberHelperDigitScanExact",
"closure_version": "patch_c_v1",
"active_decl_hash": "b4813791708985eccea8591b89e1d33c74c4af940c7b32171bd1ce70c3f56687",
"active_statement_hash": "0b154f5da52ff3e4e9122a17b9b02427e7af2852e11472bc4b0c38f56f85729a",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "d5c04ffa333d9b33b238a527f5beaa2be82e021d3e9c0bbe01b1310280f7f55a",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-68",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperEightDigitWord": "a61cba9606484373",
"NumberHelperParseEightDigitsExact": "4b20c98a383aae52",
"NumberHelperReadEightBytes": "8738e3b807b9b2d9",
"num_imp_dec2flt_common_is_8digits": "effb8a26907859a5",
"num_imp_dec2flt_parse_try_parse_digits": "bcad6df678c024ae"
},
"strict_definition_deps": {
"SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64": "279b0c1cd8ec9e39",
"num_imp_dec2flt_common_is_8digits": "53e9de5212d69bf5",
"num_imp_dec2flt_parse_parse_8digits": "ae610d45d88851c6",
"num_imp_dec2flt_parse_try_parse_digits": "2b12615e16e91640"
}
}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:1a3d82431b686de977e09a0e26efdc294b8bbc49ed7aa96c15031f47db5b7ffb",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}