Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Helper · Exact digit scans for the long decimal witness
0. followed by 65{,}535 zero bytes and
1e655360, the extracted digit scanner first consumes exactly the
initial 0, returns accumulator zero, and leaves the point. Starting
after that point, it consumes exactly the 65{,}535 zero bytes and the final
1, returns accumulator one, and leaves e655360.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.NumberHelperReadEightBytes
import Tablet.NumberHelperEightDigitWordAccepted
import Tablet.NumberHelperParseEightDigitsSafe
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 1000000
namespace dec2flt_model
-- [TABLET NODE: ParserExactRoundingDigitScans]
theorem ParserExactRoundingDigitScans :
(forall s : Slice Std.U8,
s.val = List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] ->
exists rest : Slice Std.U8,
num.imp.dec2flt.parse.try_parse_digits s 0#u64 =
ok (rest, 1#u64) /\
rest.val = [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) /\
(forall s : Slice Std.U8,
s.val = [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] ->
exists point : Slice Std.U8,
num.imp.dec2flt.parse.try_parse_digits s 0#u64 =
ok (point, 0#u64) /\
point.val = 46#u8 :: List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := 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
0, updates
the accumulator from zero to zero, increments the index to one, then stops at
the point byte. Dropping one byte therefore leaves exactly the claimed point
suffix.1, then e655360, and the accumulator is zero.
When j>0, NumberHelperReadEightBytes identifies the next word as
eight ASCII zeros. Its bytes satisfy the acceptance condition of
NumberHelperEightDigitWordAccepted, and direct evaluation of the
extracted eight-digit arithmetic gives zero, so dropping eight bytes
establishes the invariant with j-1. When j=0, the final word is seven
zeros followed by one; the same read and acceptance facts apply, and direct
evaluation gives accumulator one. The fast loop then leaves precisely
e655360; the scalar loop immediately stops because e is not
a decimal digit. The remaining-block count, equivalently the slice length,
strictly decreases on every continuing iteration, proving termination.Lean proof
constructor
· intro s hs
let tail : List Std.U8 :=
[101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]
have readZeros (u : Slice Std.U8) (r : List Std.U8)
(hu : u.val = List.replicate 8 48#u8 ++ r) :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 u =
ok 3472328296227680304#u64 := by
have hlen : 8 <= u.val.length := by simp [hu]
obtain ⟨w, hw, hb⟩ := NumberHelperReadEightBytes u hlen
have h0 := hb 0 (by omega)
have h1 := hb 1 (by omega)
have h2 := hb 2 (by omega)
have h3 := hb 3 (by omega)
have h4 := hb 4 (by omega)
have h5 := hb 5 (by omega)
have h6 := hb 6 (by omega)
have h7 := hb 7 (by omega)
simp [hu, List.replicate_succ] at h0 h1 h2 h3 h4 h5 h6 h7
have hweq : w = 3472328296227680304#u64 := by
apply UScalar.eq_of_val_eq
change w.val = 3472328296227680304
have hwbound := UScalar.hrBounds w
simp [UScalar.rMax_eq_max, U64.max_eq] at hwbound
omega
simpa [hweq] using hw
have readTerminal (u : Slice Std.U8) (r : List Std.U8)
(hu : u.val = List.replicate 7 48#u8 ++ 49#u8 :: r) :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 u =
ok 3544385890265608240#u64 := by
have hlen : 8 <= u.val.length := by simp [hu]
obtain ⟨w, hw, hb⟩ := NumberHelperReadEightBytes u hlen
have h0 := hb 0 (by omega)
have h1 := hb 1 (by omega)
have h2 := hb 2 (by omega)
have h3 := hb 3 (by omega)
have h4 := hb 4 (by omega)
have h5 := hb 5 (by omega)
have h6 := hb 6 (by omega)
have h7 := hb 7 (by omega)
simp [hu, List.replicate_succ] at h0 h1 h2 h3 h4 h5 h6 h7
have hweq : w = 3544385890265608240#u64 := by
apply UScalar.eq_of_val_eq
change w.val = 3544385890265608240
have hwbound := UScalar.hrBounds w
simp [UScalar.rMax_eq_max, U64.max_eq] at hwbound
omega
simpa [hweq] using hw
have hisZero :
num.imp.dec2flt.common.is_8digits 3472328296227680304#u64 =
ok true := by
apply NumberHelperEightDigitWordAccepted
intro i hi
interval_cases i <;> norm_num
have hisTerminal :
num.imp.dec2flt.common.is_8digits 3544385890265608240#u64 =
ok true := by
apply NumberHelperEightDigitWordAccepted
intro i hi
interval_cases i <;> norm_num
have hparseZero :
num.imp.dec2flt.parse.parse_8digits 3472328296227680304#u64 =
ok 0#u64 := by
unfold num.imp.dec2flt.parse.parse_8digits
rw [num.imp.dec2flt.parse.parse_8digits.MASK.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL1.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL2.eq_def]
rfl
have hparseTerminal :
num.imp.dec2flt.parse.parse_8digits 3544385890265608240#u64 =
ok 1#u64 := by
unfold num.imp.dec2flt.parse.parse_8digits
rw [num.imp.dec2flt.parse.parse_8digits.MASK.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL1.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL2.eq_def]
rfl
have hfast : num.imp.dec2flt.parse.try_parse_digits_loop0 s 0#u64
⦃ p => p.1.val = tail /\ p.2 = 1#u64 ⦄ := by
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.val.length)
(fun p =>
(exists j : Nat, j <= 8191 /\
p.1.val = List.replicate (8*j + 7) 48#u8 ++ 49#u8 :: tail /\
p.2 = 0#u64) \/
(p.1.val = tail /\ p.2 = 1#u64))
(fun p => p.1.val = tail /\ p.2 = 1#u64)
(fun p => num.imp.dec2flt.parse.try_parse_digits_loop0.body p.1 p.2)
(s, 0#u64)
· intro p hp
rcases p with ⟨u, a⟩
rcases hp with ⟨j, hj, hu, ha⟩ | ⟨hu, ha⟩
· simp only [Prod.fst, Prod.snd] at hu ha ⊢
by_cases hj0 : j = 0
· subst j
have hu' : u.val = List.replicate 7 48#u8 ++
49#u8 :: tail := by simpa using hu
have hread := readTerminal u tail hu'
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, ha, hu', hread, hisTerminal, hparseTerminal,
core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, WP.spec_ok, Aeneas.Std.lift,
core.num.U64.wrapping_mul, core.num.U64.wrapping_add]
constructor
· right
rfl
· omega
· obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hj0
have hu' : u.val = List.replicate 8 48#u8 ++
(List.replicate (8*k + 7) 48#u8 ++ 49#u8 :: tail) := by
rw [hu, show 8 * k.succ + 7 = 8 + (8*k + 7) by omega,
List.replicate_add, List.append_assoc]
have hread := readZeros u
(List.replicate (8*k + 7) 48#u8 ++ 49#u8 :: tail) hu'
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, ha, hu', hread, hisZero, hparseZero,
core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, WP.spec_ok]
constructor
· exact Or.inl ⟨k, by omega, rfl, rfl⟩
· simp [Slice.length, List.length_append, List.length_replicate]
omega
· simp only [Prod.fst, Prod.snd] at hu ha ⊢
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, ha, hu, tail, WP.spec_ok]
· left
refine ⟨8191, by omega, ?_, rfl⟩
rw [hs]
obtain ⟨p, hp, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hfast
rcases p with ⟨afterFast, fastValue⟩
rcases hpost with ⟨hafterFast, hfastValue⟩
simp only [Prod.fst, Prod.snd] at hafterFast hfastValue
subst fastValue
have hscalar :
num.imp.dec2flt.parse.try_parse_digits_loop1 afterFast 1#u64 0#usize =
ok (1#u64, 0#usize) := by
unfold num.imp.dec2flt.parse.try_parse_digits_loop1
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body,
Slice.length, hafterFast, tail, Slice.index_usize,
core.num.U8.wrapping_sub, Aeneas.Std.lift, U8.size_eq]
have hdrop : core.slice.index.SliceIndexRangeFromUsizeSlice.index
{ start := 0#usize } afterFast = ok afterFast := by
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, Slice.length]
refine ⟨afterFast, ?_, ?_⟩
· unfold num.imp.dec2flt.parse.try_parse_digits
simp [hp, hscalar, hdrop]
· simpa [tail] using hafterFast
· intro s hs
let afterPoint : List Std.U8 := List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]
have hsHead : s.val = 48#u8 :: 46#u8 :: afterPoint := by
dsimp only [afterPoint]
rw [hs]
rfl
have hafterPrefix : afterPoint = List.replicate 6 48#u8 ++
(List.replicate 65529 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
dsimp only [afterPoint]
rw [show 65535 = 6 + 65529 by omega, List.replicate_add,
List.append_assoc]
have hsPrefix : s.val = 48#u8 :: 46#u8 :: 48#u8 :: 48#u8 ::
48#u8 :: 48#u8 :: 48#u8 :: 48#u8 ::
(List.replicate 65529 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
rw [hsHead, hafterPrefix]
rfl
have hread :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 s =
ok 3472328296227679792#u64 := by
have hlen : 8 <= s.val.length := by
rw [hsPrefix]
simp only [List.length_cons]
omega
obtain ⟨w, hw, hb⟩ := NumberHelperReadEightBytes s hlen
have h0 := hb 0 (by omega)
have h1 := hb 1 (by omega)
have h2 := hb 2 (by omega)
have h3 := hb 3 (by omega)
have h4 := hb 4 (by omega)
have h5 := hb 5 (by omega)
have h6 := hb 6 (by omega)
have h7 := hb 7 (by omega)
simp only [hsPrefix, List.getElem_cons_zero,
List.getElem_cons_succ] at h0 h1 h2 h3 h4 h5 h6 h7
norm_num at h0 h1 h2 h3 h4 h5 h6 h7
have hweq : w = 3472328296227679792#u64 := by
apply UScalar.eq_of_val_eq
change w.val = 3472328296227679792
have hwbound := UScalar.hrBounds w
simp [UScalar.rMax_eq_max, U64.max_eq] at hwbound
omega
simpa [hweq] using hw
have hnotDigits :
num.imp.dec2flt.common.is_8digits 3472328296227679792#u64 =
ok false := by
unfold num.imp.dec2flt.common.is_8digits
rfl
have hfast :
num.imp.dec2flt.parse.try_parse_digits_loop0 s 0#u64 =
ok (s, 0#u64) := by
have hlen : 8 <= s.val.length := by
rw [hsPrefix]
simp only [List.length_cons]
omega
unfold num.imp.dec2flt.parse.try_parse_digits_loop0
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, hlen, hread, hnotDigits]
have hscalar :
num.imp.dec2flt.parse.try_parse_digits_loop1 s 0#u64 0#usize =
ok (0#u64, 1#usize) := by
unfold num.imp.dec2flt.parse.try_parse_digits_loop1
have hlen : 2 <= s.val.length := by rw [hsHead]; simp
have hpos : 0 < s.val.length := by omega
have hidx0 : Slice.index_usize s 0#usize = ok 48#u8 := by
simp [Slice.index_usize, hsHead]
have hidx1 : Slice.index_usize s 1#usize = ok 46#u8 := by
simp [Slice.index_usize, hsHead]
have hbody0 :
num.imp.dec2flt.parse.try_parse_digits_loop1.body
s 0#u64 0#usize = ok (cont (0#u64, 1#usize)) := by
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body,
Slice.length, hpos, hidx0, core.num.U8.wrapping_sub,
Aeneas.Std.lift, U8.size_eq]
rw [show 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
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [Result.ofOption, UScalar.check_bounds, hbits]]
rfl
rw [Aeneas.Std.loop.eq_1]
simp only [Prod.fst, Prod.snd]
rw [hbody0]
simp
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body,
Slice.length, hlen, hidx1, core.num.U8.wrapping_sub,
Aeneas.Std.lift, U8.size_eq]
have hdrop : exists point : Slice Std.U8,
core.slice.index.SliceIndexRangeFromUsizeSlice.index
{ start := 1#usize } s = ok point /\
point.val = 46#u8 :: List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] := by
let point : Slice Std.U8 := ⟨46#u8 :: afterPoint, by
have hp := s.property
rw [hsHead] at hp
exact Nat.le_trans (by simp) hp⟩
refine ⟨point, ?_, ?_⟩
· have hdropEq : s.drop 1#usize = point := by
apply (Slice.eq_iff _ _).2
simp [Slice.drop, hsHead, point]
have hone : 1 <= s.val.length := by rw [hsHead]; simp
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.length, hdropEq, hone]
· rfl
obtain ⟨point, hdrop, hpoint⟩ := hdrop
refine ⟨point, ?_, hpoint⟩
unfold num.imp.dec2flt.parse.try_parse_digits
simp [hfast, hscalar, hdrop]
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.NumberHelperReadEightBytes
import Tablet.NumberHelperEightDigitWordAccepted
import Tablet.NumberHelperParseEightDigitsSafe
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 1000000
namespace dec2flt_model
-- [TABLET NODE: ParserExactRoundingDigitScans]
theorem ParserExactRoundingDigitScans :
(forall s : Slice Std.U8,
s.val = List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] ->
exists rest : Slice Std.U8,
num.imp.dec2flt.parse.try_parse_digits s 0#u64 =
ok (rest, 1#u64) /\
rest.val = [101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) /\
(forall s : Slice Std.U8,
s.val = [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] ->
exists point : Slice Std.U8,
num.imp.dec2flt.parse.try_parse_digits s 0#u64 =
ok (point, 0#u64) /\
point.val = 46#u8 :: List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
-- BODY
constructor
· intro s hs
let tail : List Std.U8 :=
[101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]
have readZeros (u : Slice Std.U8) (r : List Std.U8)
(hu : u.val = List.replicate 8 48#u8 ++ r) :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 u =
ok 3472328296227680304#u64 := by
have hlen : 8 <= u.val.length := by simp [hu]
obtain ⟨w, hw, hb⟩ := NumberHelperReadEightBytes u hlen
have h0 := hb 0 (by omega)
have h1 := hb 1 (by omega)
have h2 := hb 2 (by omega)
have h3 := hb 3 (by omega)
have h4 := hb 4 (by omega)
have h5 := hb 5 (by omega)
have h6 := hb 6 (by omega)
have h7 := hb 7 (by omega)
simp [hu, List.replicate_succ] at h0 h1 h2 h3 h4 h5 h6 h7
have hweq : w = 3472328296227680304#u64 := by
apply UScalar.eq_of_val_eq
change w.val = 3472328296227680304
have hwbound := UScalar.hrBounds w
simp [UScalar.rMax_eq_max, U64.max_eq] at hwbound
omega
simpa [hweq] using hw
have readTerminal (u : Slice Std.U8) (r : List Std.U8)
(hu : u.val = List.replicate 7 48#u8 ++ 49#u8 :: r) :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 u =
ok 3544385890265608240#u64 := by
have hlen : 8 <= u.val.length := by simp [hu]
obtain ⟨w, hw, hb⟩ := NumberHelperReadEightBytes u hlen
have h0 := hb 0 (by omega)
have h1 := hb 1 (by omega)
have h2 := hb 2 (by omega)
have h3 := hb 3 (by omega)
have h4 := hb 4 (by omega)
have h5 := hb 5 (by omega)
have h6 := hb 6 (by omega)
have h7 := hb 7 (by omega)
simp [hu, List.replicate_succ] at h0 h1 h2 h3 h4 h5 h6 h7
have hweq : w = 3544385890265608240#u64 := by
apply UScalar.eq_of_val_eq
change w.val = 3544385890265608240
have hwbound := UScalar.hrBounds w
simp [UScalar.rMax_eq_max, U64.max_eq] at hwbound
omega
simpa [hweq] using hw
have hisZero :
num.imp.dec2flt.common.is_8digits 3472328296227680304#u64 =
ok true := by
apply NumberHelperEightDigitWordAccepted
intro i hi
interval_cases i <;> norm_num
have hisTerminal :
num.imp.dec2flt.common.is_8digits 3544385890265608240#u64 =
ok true := by
apply NumberHelperEightDigitWordAccepted
intro i hi
interval_cases i <;> norm_num
have hparseZero :
num.imp.dec2flt.parse.parse_8digits 3472328296227680304#u64 =
ok 0#u64 := by
unfold num.imp.dec2flt.parse.parse_8digits
rw [num.imp.dec2flt.parse.parse_8digits.MASK.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL1.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL2.eq_def]
rfl
have hparseTerminal :
num.imp.dec2flt.parse.parse_8digits 3544385890265608240#u64 =
ok 1#u64 := by
unfold num.imp.dec2flt.parse.parse_8digits
rw [num.imp.dec2flt.parse.parse_8digits.MASK.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL1.eq_def,
num.imp.dec2flt.parse.parse_8digits.MUL2.eq_def]
rfl
have hfast : num.imp.dec2flt.parse.try_parse_digits_loop0 s 0#u64
⦃ p => p.1.val = tail /\ p.2 = 1#u64 ⦄ := by
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.val.length)
(fun p =>
(exists j : Nat, j <= 8191 /\
p.1.val = List.replicate (8*j + 7) 48#u8 ++ 49#u8 :: tail /\
p.2 = 0#u64) \/
(p.1.val = tail /\ p.2 = 1#u64))
(fun p => p.1.val = tail /\ p.2 = 1#u64)
(fun p => num.imp.dec2flt.parse.try_parse_digits_loop0.body p.1 p.2)
(s, 0#u64)
· intro p hp
rcases p with ⟨u, a⟩
rcases hp with ⟨j, hj, hu, ha⟩ | ⟨hu, ha⟩
· simp only [Prod.fst, Prod.snd] at hu ha ⊢
by_cases hj0 : j = 0
· subst j
have hu' : u.val = List.replicate 7 48#u8 ++
49#u8 :: tail := by simpa using hu
have hread := readTerminal u tail hu'
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, ha, hu', hread, hisTerminal, hparseTerminal,
core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, WP.spec_ok, Aeneas.Std.lift,
core.num.U64.wrapping_mul, core.num.U64.wrapping_add]
constructor
· right
rfl
· omega
· obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hj0
have hu' : u.val = List.replicate 8 48#u8 ++
(List.replicate (8*k + 7) 48#u8 ++ 49#u8 :: tail) := by
rw [hu, show 8 * k.succ + 7 = 8 + (8*k + 7) by omega,
List.replicate_add, List.append_assoc]
have hread := readZeros u
(List.replicate (8*k + 7) 48#u8 ++ 49#u8 :: tail) hu'
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, ha, hu', hread, hisZero, hparseZero,
core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, WP.spec_ok]
constructor
· exact Or.inl ⟨k, by omega, rfl, rfl⟩
· simp [Slice.length, List.length_append, List.length_replicate]
omega
· simp only [Prod.fst, Prod.snd] at hu ha ⊢
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, ha, hu, tail, WP.spec_ok]
· left
refine ⟨8191, by omega, ?_, rfl⟩
rw [hs]
obtain ⟨p, hp, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hfast
rcases p with ⟨afterFast, fastValue⟩
rcases hpost with ⟨hafterFast, hfastValue⟩
simp only [Prod.fst, Prod.snd] at hafterFast hfastValue
subst fastValue
have hscalar :
num.imp.dec2flt.parse.try_parse_digits_loop1 afterFast 1#u64 0#usize =
ok (1#u64, 0#usize) := by
unfold num.imp.dec2flt.parse.try_parse_digits_loop1
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body,
Slice.length, hafterFast, tail, Slice.index_usize,
core.num.U8.wrapping_sub, Aeneas.Std.lift, U8.size_eq]
have hdrop : core.slice.index.SliceIndexRangeFromUsizeSlice.index
{ start := 0#usize } afterFast = ok afterFast := by
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, Slice.length]
refine ⟨afterFast, ?_, ?_⟩
· unfold num.imp.dec2flt.parse.try_parse_digits
simp [hp, hscalar, hdrop]
· simpa [tail] using hafterFast
· intro s hs
let afterPoint : List Std.U8 := List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]
have hsHead : s.val = 48#u8 :: 46#u8 :: afterPoint := by
dsimp only [afterPoint]
rw [hs]
rfl
have hafterPrefix : afterPoint = List.replicate 6 48#u8 ++
(List.replicate 65529 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
dsimp only [afterPoint]
rw [show 65535 = 6 + 65529 by omega, List.replicate_add,
List.append_assoc]
have hsPrefix : s.val = 48#u8 :: 46#u8 :: 48#u8 :: 48#u8 ::
48#u8 :: 48#u8 :: 48#u8 :: 48#u8 ::
(List.replicate 65529 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) := by
rw [hsHead, hafterPrefix]
rfl
have hread :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 s =
ok 3472328296227679792#u64 := by
have hlen : 8 <= s.val.length := by
rw [hsPrefix]
simp only [List.length_cons]
omega
obtain ⟨w, hw, hb⟩ := NumberHelperReadEightBytes s hlen
have h0 := hb 0 (by omega)
have h1 := hb 1 (by omega)
have h2 := hb 2 (by omega)
have h3 := hb 3 (by omega)
have h4 := hb 4 (by omega)
have h5 := hb 5 (by omega)
have h6 := hb 6 (by omega)
have h7 := hb 7 (by omega)
simp only [hsPrefix, List.getElem_cons_zero,
List.getElem_cons_succ] at h0 h1 h2 h3 h4 h5 h6 h7
norm_num at h0 h1 h2 h3 h4 h5 h6 h7
have hweq : w = 3472328296227679792#u64 := by
apply UScalar.eq_of_val_eq
change w.val = 3472328296227679792
have hwbound := UScalar.hrBounds w
simp [UScalar.rMax_eq_max, U64.max_eq] at hwbound
omega
simpa [hweq] using hw
have hnotDigits :
num.imp.dec2flt.common.is_8digits 3472328296227679792#u64 =
ok false := by
unfold num.imp.dec2flt.common.is_8digits
rfl
have hfast :
num.imp.dec2flt.parse.try_parse_digits_loop0 s 0#u64 =
ok (s, 0#u64) := by
have hlen : 8 <= s.val.length := by
rw [hsPrefix]
simp only [List.length_cons]
omega
unfold num.imp.dec2flt.parse.try_parse_digits_loop0
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.try_parse_digits_loop0.body,
Slice.length, hlen, hread, hnotDigits]
have hscalar :
num.imp.dec2flt.parse.try_parse_digits_loop1 s 0#u64 0#usize =
ok (0#u64, 1#usize) := by
unfold num.imp.dec2flt.parse.try_parse_digits_loop1
have hlen : 2 <= s.val.length := by rw [hsHead]; simp
have hpos : 0 < s.val.length := by omega
have hidx0 : Slice.index_usize s 0#usize = ok 48#u8 := by
simp [Slice.index_usize, hsHead]
have hidx1 : Slice.index_usize s 1#usize = ok 46#u8 := by
simp [Slice.index_usize, hsHead]
have hbody0 :
num.imp.dec2flt.parse.try_parse_digits_loop1.body
s 0#u64 0#usize = ok (cont (0#u64, 1#usize)) := by
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body,
Slice.length, hpos, hidx0, core.num.U8.wrapping_sub,
Aeneas.Std.lift, U8.size_eq]
rw [show 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
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [Result.ofOption, UScalar.check_bounds, hbits]]
rfl
rw [Aeneas.Std.loop.eq_1]
simp only [Prod.fst, Prod.snd]
rw [hbody0]
simp
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.try_parse_digits_loop1.body,
Slice.length, hlen, hidx1, core.num.U8.wrapping_sub,
Aeneas.Std.lift, U8.size_eq]
have hdrop : exists point : Slice Std.U8,
core.slice.index.SliceIndexRangeFromUsizeSlice.index
{ start := 1#usize } s = ok point /\
point.val = 46#u8 :: List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8] := by
let point : Slice Std.U8 := ⟨46#u8 :: afterPoint, by
have hp := s.property
rw [hsHead] at hp
exact Nat.le_trans (by simp) hp⟩
refine ⟨point, ?_, ?_⟩
· have hdropEq : s.drop 1#usize = point := by
apply (Slice.eq_iff _ _).2
simp [Slice.drop, hsHead, point]
have hone : 1 <= s.val.length := by rw [hsHead]; simp
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.length, hdropEq, hone]
· rfl
obtain ⟨point, hdrop, hpoint⟩ := hdrop
refine ⟨point, ?_, hpoint⟩
unfold num.imp.dec2flt.parse.try_parse_digits
simp [hfast, hscalar, hdrop]
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Used by
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:18 Program Rust
- is_8digits · dec2flt/common.rs:40 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: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
- 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
- NumberHelperEightDigitWordAccepted
- NumberHelperReadEightBytes
- ParserExactRoundingDigitScans
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- num imp dec2flt common is 8digits
- num imp dec2flt parse parse 8digits
All 10 entries
- NumberHelperEightDigitWordAccepted
- NumberHelperReadEightBytes
- ParserExactRoundingDigitScans
- 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": "ParserExactRoundingDigitScans",
"closure_version": "patch_c_v1",
"active_decl_hash": "77057f4c4b77efb4adf078ed2b9b563786b6025d86429adab36e50968de3306c",
"active_statement_hash": "1db03d98315b63dba1939d8bc26cc1fdac5650eca7330cfe13f537a50028c9ff",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-128",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperEightDigitWordAccepted": "eb5cd4fd1f7849dc",
"NumberHelperReadEightBytes": "8738e3b807b9b2d9",
"num_imp_dec2flt_common_is_8digits": "effb8a26907859a5",
"num_imp_dec2flt_parse_parse_8digits": "ed1fe14ecad23531",
"num_imp_dec2flt_parse_parse_8digits_MASK": "7ca2021b20f34521",
"num_imp_dec2flt_parse_parse_8digits_MUL1": "152948ead6b79a6c",
"num_imp_dec2flt_parse_parse_8digits_MUL2": "4e8db7500927acde",
"num_imp_dec2flt_parse_try_parse_digits": "5f4488c177675662"
},
"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_parse_8digits_MASK": "00fd2cbc66eea03b",
"num_imp_dec2flt_parse_parse_8digits_MUL1": "14171ee9dc4177db",
"num_imp_dec2flt_parse_parse_8digits_MUL2": "52fae8265919fe4b",
"num_imp_dec2flt_parse_try_parse_digits": "e70a7a64db07f781"
}
}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:fab816b6104561a5e7775c35ca5738dc5c1ce1d4b148fa70a606202497b61993",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}