Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Exact integer-only decimal-sequence state
parse_decimal_seq succeeds with
record d. Let S be I after its maximal leading zero run and let R
be S after its maximal terminal zero run. Then d has logical count
\min(|R|,768), its retained array prefix is R up to that count, and its
truncation flag is true exactly when 768<|R|. Moreover
d.\texttt{decimal\_point} is congruent to |S| modulo 2^{32}.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalDigitTrimDecomposition
import Tablet.DecimalSeqLeadingZeroLoopExact
import Tablet.DecimalSeqScalarScanExact
import Tablet.DecimalSeqTrailingZeroValues
import Tablet.DecimalSeqFillPrefixPreserved
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.DecimalSeqI32HCastCongruence
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqIntegerNoExponentState]
theorem DecimalSeqIntegerNoExponentState (s : Slice Std.U8) (I : List Nat)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq)
(hsrc : SourceValidByteSlice s)
(hdig : forall z, z ∈ I -> z < 10)
(hne : I ≠ [])
(hs : s.val.map (fun b => b.val) = I.map (fun z => 48 + z))
(hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d) :
let significant := I.dropWhile (fun digit => digit == 0)
let trimmed :=
(significant.reverse.dropWhile (fun digit => digit == 0)).reverse
(d.num_digits.val = min trimmed.length 768 /\
(d.digits.val.take d.num_digits.val).map (fun z => z.val) =
trimmed.take d.num_digits.val /\
(d.truncated = true <-> 768 < trimmed.length)) /\
exists k : Int,
d.decimal_point.val = (significant.length : Int) + k * 4294967296 := 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
dsimp only
obtain ⟨z, q, hz, hq, hI, hsig, hsigstop, htrimstop⟩ :=
DecimalDigitTrimDecomposition I
let sig := I.dropWhile (fun digit => digit == 0)
let trim := (sig.reverse.dropWhile (fun digit => digit == 0)).reverse
change (_ = min trim.length 768 /\ _ = trim.take _ /\ _) /\ _
have hzmap : (List.replicate z 0).map (fun n => 48 + n) =
List.replicate z 48 := by simp
have hslead : s.val.map (fun b => b.val) =
List.replicate z 48 ++ sig.map (fun n => 48 + n) := by
rw [hs, hI, List.map_append, hzmap]
have hleadstop : sig.map (fun n => 48 + n) = [] \/
(sig.map (fun n => 48 + n))[0]? ≠ some 48 := by
rcases hsigstop with h | h
· left; simp [sig, h]
· right
intro heq
apply h
cases hsigeq : sig with
| nil => simp [sig, hsigeq] at heq
| cons a xs =>
have ha : a = 0 := by
simp [hsigeq] at heq
omega
subst a
simpa [sig, hsigeq]
obtain ⟨s1, hlead, hs1⟩ := DecimalSeqLeadingZeroLoopExact s z
(sig.map (fun n => 48 + n)) hslead hleadstop
let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq := {
num_digits := 0#usize
decimal_point := 0#i32
truncated := false
digits := Array.repeat 768#usize 0#u8 }
have hbound : sig.length <= UScalar.max .Usize := by
unfold SourceValidByteSlice at hsrc
have hlen := congrArg List.length hs
simp at hlen
have hsigle : sig.length <= I.length := by
apply List.length_dropWhile_le
simp [UScalar.max, Usize.max, Usize.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨rest, d1, hscan, hrest, hd1count, hd1point, hd1trunc,
hd1old, hd1written, hd1outside⟩ :=
DecimalSeqScalarScanExact s1 d0 sig [] (by simpa using hs1)
(fun n hn => hdig n (by
rw [hI]
exact List.mem_append_right _ hn)) (by simp) (by simpa [d0] using hbound)
have hrestnil : rest.val = [] := by
apply List.eq_nil_of_length_eq_zero
have h := congrArg List.length hrest
simpa using h
obtain ⟨afill, hfill, hafill⟩ := DecimalSeqFillPrefixPreserved
d1.num_digits d1.digits
by_cases hempty : sig = []
· have hd10 : d1.num_digits = 0#usize := by
apply UScalar.eq_of_val_eq
simp [hd1count, d0, hempty]
have htrim : trim = [] := by simp [trim, hempty]
unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq at hparse
rw [show num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
ok d0 by rfl] at hparse
simp only [bind_tc_ok] at hparse
rw [hlead] at hparse
simp only [bind_tc_ok] at hparse
rw [hscan] at hparse
simp [hrestnil, hd10] at hparse
have hfill0 :
num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
{ start := 0#usize,
«end» := num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
d1.digits = ok afill := by simpa [hd10] using hfill
rw [hfill0] at hparse
simp at hparse
subst d
constructor
· constructor
· change 0 = min trim.length 768
simp [htrim]
constructor
· change (afill.val.take 0).map (fun z => z.val) = trim.take 0
simp
· change d1.truncated = true ↔ 768 < trim.length
rw [hd1trunc]
simp [d0, htrim]
· refine ⟨0, ?_⟩
change d1.decimal_point.val = (sig.length : Int)
simp [hd1point, d0, hempty]
· have htrimne : trim ≠ [] := by
have hsig' : sig = trim ++ List.replicate q 0 := by
simpa [sig, trim] using hsig
intro ht
have hzsig : sig = List.replicate q 0 := by
simpa [ht] using hsig'
rcases hsigstop with hs0 | hs0
· exact hempty (by simpa [sig] using hs0)
· cases q with
| zero => apply hempty; simpa [hzsig]
| succ q =>
apply hs0
simp [sig, hzsig, List.replicate_succ]
have htrimlast : trim.getLast? ≠ some 0 := by
rcases htrimstop with h | h
· exact (htrimne (by simpa [trim] using h)).elim
· simpa [trim] using h
let prefx := List.replicate z 48 ++ trim.map (fun n => 48 + n)
let suffix := List.replicate q 48
have hsig' : sig = trim ++ List.replicate q 0 := by
simpa [sig, trim] using hsig
have hstart : s.val.map (fun b => b.val) = prefx ++ suffix := by
rw [hs, hI]
change _ = _
rw [show I.dropWhile (fun digit => digit == 0) = sig by rfl, hsig',
List.map_append, List.map_append]
simp [prefx, suffix, sig, trim, List.append_assoc]
have hprefx : prefx = [] \/ exists pre b,
prefx = pre ++ [b] /\ b ≠ 48 /\ b ≠ 46 := by
right
let last := trim.getLast htrimne
refine ⟨List.replicate z 48 ++
trim.dropLast.map (fun n => 48 + n), 48 + last, ?_, ?_, ?_⟩
· dsimp [prefx]
rw [List.append_assoc]
congr 1
have ht := congrArg (List.map (fun n => 48 + n))
(List.dropLast_append_getLast htrimne)
simpa [last, List.map_append] using ht.symm
· have hlast0 : last ≠ 0 := by
intro h
apply htrimlast
have hget : trim.getLast? = some last := by
rw [List.getLast?_eq_getLast htrimne]
rw [hget, h]
omega
· omega
have hsuffix : forall b, b ∈ suffix -> b = 48 \/ b = 46 := by
intro b hb
left
have hb' := hb
simp [suffix] at hb'
exact hb'.2
have hlenS : s.val.length = I.length := by
have := congrArg List.length hs
simpa using this
have hlenRest : rest.val.length = 0 := by simp [hrestnil]
have hsubbound : (Slice.len rest).val <= (Slice.len s).val := by
simp [Slice.len, hlenS, hlenRest]
obtain ⟨consumed, hconsumed, hconsumedVal, hconsumedLe⟩ :=
Aeneas.Std.WP.spec_imp_exists
(UScalar.sub_spec (x := Slice.len s) (y := Slice.len rest) hsubbound)
have hconsumedI : consumed.val = I.length := by
simpa [Slice.len, hlenS, hlenRest] using hconsumedVal
have htrailBound : suffix.count 48 <= UScalar.max .Usize := by
have hqle : q <= sig.length := by
have hh := congrArg List.length hsig'
simp at hh
omega
simpa [suffix] using le_trans hqle hbound
obtain ⟨trailing, htrailLoop, htrailingVal⟩ :=
DecimalSeqTrailingZeroValues s prefx suffix [] 0#usize consumed
(by simpa using hstart) hprefx hsuffix (by
rw [hconsumedI]
have hlen := congrArg List.length hstart
simp at hlen
simp only [List.length_append]
omega) (by simpa using htrailBound)
have htrailingQ : trailing.val = q := by
simpa [suffix] using htrailingVal
have htrail :
num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed =
ok trailing := by
unfold num.imp.dec2flt.decimal_seq.count_trailing_zeros
simpa using htrailLoop
unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq at hparse
rw [show num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
ok d0 by rfl] at hparse
simp only [bind_tc_ok] at hparse
rw [hlead] at hparse
simp only [bind_tc_ok] at hparse
rw [hscan] at hparse
simp [hrestnil] at hparse
rw [hconsumed] at hparse
simp only [bind_tc_ok] at hparse
rw [htrail] at hparse
have htrailLe : trailing.val <= d1.num_digits.val := by
rw [htrailingQ, hd1count]
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
omega
obtain ⟨kept, hkeep, hkeepVal, hkeepLe⟩ :=
Aeneas.Std.WP.spec_imp_exists
(UScalar.sub_spec (x := d1.num_digits) (y := trailing) htrailLe)
have hkeepTrim : kept.val = trim.length := by
rw [hkeepVal, htrailingQ, hd1count]
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
omega
simp [hd1count, d0, hempty] at hparse
simp only [Aeneas.Std.lift, bind_tc_ok] at hparse
cases ha : d1.decimal_point + UScalar.hcast .I32 trailing with
| fail e => rw [ha] at hparse; simp at hparse
| div => rw [ha] at hparse; simp at hparse
| ok p1 =>
rw [ha] at hparse
simp only [bind_tc_ok] at hparse
rw [hkeep] at hparse
simp only [bind_tc_ok] at hparse
cases hp : p1 + UScalar.hcast .I32 kept with
| fail e => rw [hp] at hparse; simp at hparse
| div => rw [hp] at hparse; simp at hparse
| ok point =>
rw [hp] at hparse
simp only [bind_tc_ok] at hparse
have hdigitPrefix :
(d1.digits.val.take (min trim.length 768)).map
(fun b => b.val) =
trim.take (min trim.length 768) := by
apply List.ext_getElem?
intro j
by_cases hj : j < min trim.length 768
· rw [List.getElem?_map, List.getElem?_take,
List.getElem?_take]
simp only [hj, if_true]
have hjsig : j < min (d0.num_digits.val + sig.length) 768 := by
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
omega
have hw := hd1written j (by simp [d0]) hjsig
simpa [d0, hsig', List.getElem?_append, (Nat.lt_min.mp hj).1]
using hw
· simp [List.getElem?_map, List.getElem?_take, hj]
obtain ⟨kq, hkq⟩ := DecimalSeqI32HCastCongruence trailing
obtain ⟨kt, hkt⟩ := DecimalSeqI32HCastCongruence kept
have haVal : p1.val = d1.decimal_point.val +
(UScalar.hcast .I32 trailing).val := by
have hh := IScalar.add_equiv d1.decimal_point
(UScalar.hcast .I32 trailing)
rw [ha] at hh
exact hh.2.1
have hpVal : point.val = p1.val +
(UScalar.hcast .I32 kept).val := by
have hh := IScalar.add_equiv p1 (UScalar.hcast .I32 kept)
rw [hp] at hh
exact hh.2.1
have hpointCong : exists k : Int,
point.val = (sig.length : Int) + k * 4294967296 := by
refine ⟨kq + kt, ?_⟩
rw [hpVal, haVal, hd1point, hkq, hkt, htrailingQ, hkeepTrim]
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
push_cast
ring_nf
omega
by_cases hcap : 768 < trim.length
· obtain ⟨a', hfill', hpref'⟩ := DecimalSeqFillPrefixPreserved
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS d1.digits
simp [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
hkeepTrim, hcap] at hparse
have hfill768 :
num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
{ start := 768#usize,
«end» := num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
d1.digits = ok a' := by
simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
using hfill'
rw [hfill768] at hparse
simp at hparse
subst d
constructor
· constructor
· change 768 = min trim.length 768
omega
constructor
· change (a'.val.take 768).map (fun z => z.val) =
trim.take 768
have hpref768 : a'.val.take 768 =
d1.digits.val.take 768 := by
simpa [
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
using hpref'
rw [hpref768]
have hd := hdigitPrefix
rw [Nat.min_eq_right (by omega)] at hd
exact hd
· simp only [Bool.true_eq, true_iff]
simpa [trim, sig] using hcap
· exact hpointCong
· obtain ⟨a', hfill', hpref'⟩ :=
DecimalSeqFillPrefixPreserved kept d1.digits
have hle : trim.length <= 768 := by omega
simp [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
hkeepTrim, hcap] at hparse
rw [hfill'] at hparse
simp at hparse
subst d
constructor
· constructor
· change kept.val = min trim.length 768
rw [hkeepTrim, Nat.min_eq_left hle]
constructor
· rw [hpref']
simpa [hkeepTrim, Nat.min_eq_left hle] using hdigitPrefix
· simp [hd1trunc, d0]
simpa [trim, sig] using hle
· exact hpointCong
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.DecimalDigitTrimDecomposition
import Tablet.DecimalSeqLeadingZeroLoopExact
import Tablet.DecimalSeqScalarScanExact
import Tablet.DecimalSeqTrailingZeroValues
import Tablet.DecimalSeqFillPrefixPreserved
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.DecimalSeqI32HCastCongruence
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqIntegerNoExponentState]
theorem DecimalSeqIntegerNoExponentState (s : Slice Std.U8) (I : List Nat)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq)
(hsrc : SourceValidByteSlice s)
(hdig : forall z, z ∈ I -> z < 10)
(hne : I ≠ [])
(hs : s.val.map (fun b => b.val) = I.map (fun z => 48 + z))
(hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d) :
let significant := I.dropWhile (fun digit => digit == 0)
let trimmed :=
(significant.reverse.dropWhile (fun digit => digit == 0)).reverse
(d.num_digits.val = min trimmed.length 768 /\
(d.digits.val.take d.num_digits.val).map (fun z => z.val) =
trimmed.take d.num_digits.val /\
(d.truncated = true <-> 768 < trimmed.length)) /\
exists k : Int,
d.decimal_point.val = (significant.length : Int) + k * 4294967296 := by
-- BODY
dsimp only
obtain ⟨z, q, hz, hq, hI, hsig, hsigstop, htrimstop⟩ :=
DecimalDigitTrimDecomposition I
let sig := I.dropWhile (fun digit => digit == 0)
let trim := (sig.reverse.dropWhile (fun digit => digit == 0)).reverse
change (_ = min trim.length 768 /\ _ = trim.take _ /\ _) /\ _
have hzmap : (List.replicate z 0).map (fun n => 48 + n) =
List.replicate z 48 := by simp
have hslead : s.val.map (fun b => b.val) =
List.replicate z 48 ++ sig.map (fun n => 48 + n) := by
rw [hs, hI, List.map_append, hzmap]
have hleadstop : sig.map (fun n => 48 + n) = [] \/
(sig.map (fun n => 48 + n))[0]? ≠ some 48 := by
rcases hsigstop with h | h
· left; simp [sig, h]
· right
intro heq
apply h
cases hsigeq : sig with
| nil => simp [sig, hsigeq] at heq
| cons a xs =>
have ha : a = 0 := by
simp [hsigeq] at heq
omega
subst a
simpa [sig, hsigeq]
obtain ⟨s1, hlead, hs1⟩ := DecimalSeqLeadingZeroLoopExact s z
(sig.map (fun n => 48 + n)) hslead hleadstop
let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq := {
num_digits := 0#usize
decimal_point := 0#i32
truncated := false
digits := Array.repeat 768#usize 0#u8 }
have hbound : sig.length <= UScalar.max .Usize := by
unfold SourceValidByteSlice at hsrc
have hlen := congrArg List.length hs
simp at hlen
have hsigle : sig.length <= I.length := by
apply List.length_dropWhile_le
simp [UScalar.max, Usize.max, Usize.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨rest, d1, hscan, hrest, hd1count, hd1point, hd1trunc,
hd1old, hd1written, hd1outside⟩ :=
DecimalSeqScalarScanExact s1 d0 sig [] (by simpa using hs1)
(fun n hn => hdig n (by
rw [hI]
exact List.mem_append_right _ hn)) (by simp) (by simpa [d0] using hbound)
have hrestnil : rest.val = [] := by
apply List.eq_nil_of_length_eq_zero
have h := congrArg List.length hrest
simpa using h
obtain ⟨afill, hfill, hafill⟩ := DecimalSeqFillPrefixPreserved
d1.num_digits d1.digits
by_cases hempty : sig = []
· have hd10 : d1.num_digits = 0#usize := by
apply UScalar.eq_of_val_eq
simp [hd1count, d0, hempty]
have htrim : trim = [] := by simp [trim, hempty]
unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq at hparse
rw [show num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
ok d0 by rfl] at hparse
simp only [bind_tc_ok] at hparse
rw [hlead] at hparse
simp only [bind_tc_ok] at hparse
rw [hscan] at hparse
simp [hrestnil, hd10] at hparse
have hfill0 :
num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
{ start := 0#usize,
«end» := num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
d1.digits = ok afill := by simpa [hd10] using hfill
rw [hfill0] at hparse
simp at hparse
subst d
constructor
· constructor
· change 0 = min trim.length 768
simp [htrim]
constructor
· change (afill.val.take 0).map (fun z => z.val) = trim.take 0
simp
· change d1.truncated = true ↔ 768 < trim.length
rw [hd1trunc]
simp [d0, htrim]
· refine ⟨0, ?_⟩
change d1.decimal_point.val = (sig.length : Int)
simp [hd1point, d0, hempty]
· have htrimne : trim ≠ [] := by
have hsig' : sig = trim ++ List.replicate q 0 := by
simpa [sig, trim] using hsig
intro ht
have hzsig : sig = List.replicate q 0 := by
simpa [ht] using hsig'
rcases hsigstop with hs0 | hs0
· exact hempty (by simpa [sig] using hs0)
· cases q with
| zero => apply hempty; simpa [hzsig]
| succ q =>
apply hs0
simp [sig, hzsig, List.replicate_succ]
have htrimlast : trim.getLast? ≠ some 0 := by
rcases htrimstop with h | h
· exact (htrimne (by simpa [trim] using h)).elim
· simpa [trim] using h
let prefx := List.replicate z 48 ++ trim.map (fun n => 48 + n)
let suffix := List.replicate q 48
have hsig' : sig = trim ++ List.replicate q 0 := by
simpa [sig, trim] using hsig
have hstart : s.val.map (fun b => b.val) = prefx ++ suffix := by
rw [hs, hI]
change _ = _
rw [show I.dropWhile (fun digit => digit == 0) = sig by rfl, hsig',
List.map_append, List.map_append]
simp [prefx, suffix, sig, trim, List.append_assoc]
have hprefx : prefx = [] \/ exists pre b,
prefx = pre ++ [b] /\ b ≠ 48 /\ b ≠ 46 := by
right
let last := trim.getLast htrimne
refine ⟨List.replicate z 48 ++
trim.dropLast.map (fun n => 48 + n), 48 + last, ?_, ?_, ?_⟩
· dsimp [prefx]
rw [List.append_assoc]
congr 1
have ht := congrArg (List.map (fun n => 48 + n))
(List.dropLast_append_getLast htrimne)
simpa [last, List.map_append] using ht.symm
· have hlast0 : last ≠ 0 := by
intro h
apply htrimlast
have hget : trim.getLast? = some last := by
rw [List.getLast?_eq_getLast htrimne]
rw [hget, h]
omega
· omega
have hsuffix : forall b, b ∈ suffix -> b = 48 \/ b = 46 := by
intro b hb
left
have hb' := hb
simp [suffix] at hb'
exact hb'.2
have hlenS : s.val.length = I.length := by
have := congrArg List.length hs
simpa using this
have hlenRest : rest.val.length = 0 := by simp [hrestnil]
have hsubbound : (Slice.len rest).val <= (Slice.len s).val := by
simp [Slice.len, hlenS, hlenRest]
obtain ⟨consumed, hconsumed, hconsumedVal, hconsumedLe⟩ :=
Aeneas.Std.WP.spec_imp_exists
(UScalar.sub_spec (x := Slice.len s) (y := Slice.len rest) hsubbound)
have hconsumedI : consumed.val = I.length := by
simpa [Slice.len, hlenS, hlenRest] using hconsumedVal
have htrailBound : suffix.count 48 <= UScalar.max .Usize := by
have hqle : q <= sig.length := by
have hh := congrArg List.length hsig'
simp at hh
omega
simpa [suffix] using le_trans hqle hbound
obtain ⟨trailing, htrailLoop, htrailingVal⟩ :=
DecimalSeqTrailingZeroValues s prefx suffix [] 0#usize consumed
(by simpa using hstart) hprefx hsuffix (by
rw [hconsumedI]
have hlen := congrArg List.length hstart
simp at hlen
simp only [List.length_append]
omega) (by simpa using htrailBound)
have htrailingQ : trailing.val = q := by
simpa [suffix] using htrailingVal
have htrail :
num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed =
ok trailing := by
unfold num.imp.dec2flt.decimal_seq.count_trailing_zeros
simpa using htrailLoop
unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq at hparse
rw [show num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
ok d0 by rfl] at hparse
simp only [bind_tc_ok] at hparse
rw [hlead] at hparse
simp only [bind_tc_ok] at hparse
rw [hscan] at hparse
simp [hrestnil] at hparse
rw [hconsumed] at hparse
simp only [bind_tc_ok] at hparse
rw [htrail] at hparse
have htrailLe : trailing.val <= d1.num_digits.val := by
rw [htrailingQ, hd1count]
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
omega
obtain ⟨kept, hkeep, hkeepVal, hkeepLe⟩ :=
Aeneas.Std.WP.spec_imp_exists
(UScalar.sub_spec (x := d1.num_digits) (y := trailing) htrailLe)
have hkeepTrim : kept.val = trim.length := by
rw [hkeepVal, htrailingQ, hd1count]
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
omega
simp [hd1count, d0, hempty] at hparse
simp only [Aeneas.Std.lift, bind_tc_ok] at hparse
cases ha : d1.decimal_point + UScalar.hcast .I32 trailing with
| fail e => rw [ha] at hparse; simp at hparse
| div => rw [ha] at hparse; simp at hparse
| ok p1 =>
rw [ha] at hparse
simp only [bind_tc_ok] at hparse
rw [hkeep] at hparse
simp only [bind_tc_ok] at hparse
cases hp : p1 + UScalar.hcast .I32 kept with
| fail e => rw [hp] at hparse; simp at hparse
| div => rw [hp] at hparse; simp at hparse
| ok point =>
rw [hp] at hparse
simp only [bind_tc_ok] at hparse
have hdigitPrefix :
(d1.digits.val.take (min trim.length 768)).map
(fun b => b.val) =
trim.take (min trim.length 768) := by
apply List.ext_getElem?
intro j
by_cases hj : j < min trim.length 768
· rw [List.getElem?_map, List.getElem?_take,
List.getElem?_take]
simp only [hj, if_true]
have hjsig : j < min (d0.num_digits.val + sig.length) 768 := by
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
omega
have hw := hd1written j (by simp [d0]) hjsig
simpa [d0, hsig', List.getElem?_append, (Nat.lt_min.mp hj).1]
using hw
· simp [List.getElem?_map, List.getElem?_take, hj]
obtain ⟨kq, hkq⟩ := DecimalSeqI32HCastCongruence trailing
obtain ⟨kt, hkt⟩ := DecimalSeqI32HCastCongruence kept
have haVal : p1.val = d1.decimal_point.val +
(UScalar.hcast .I32 trailing).val := by
have hh := IScalar.add_equiv d1.decimal_point
(UScalar.hcast .I32 trailing)
rw [ha] at hh
exact hh.2.1
have hpVal : point.val = p1.val +
(UScalar.hcast .I32 kept).val := by
have hh := IScalar.add_equiv p1 (UScalar.hcast .I32 kept)
rw [hp] at hh
exact hh.2.1
have hpointCong : exists k : Int,
point.val = (sig.length : Int) + k * 4294967296 := by
refine ⟨kq + kt, ?_⟩
rw [hpVal, haVal, hd1point, hkq, hkt, htrailingQ, hkeepTrim]
simp [d0]
have hh := congrArg List.length hsig'
simp at hh
push_cast
ring_nf
omega
by_cases hcap : 768 < trim.length
· obtain ⟨a', hfill', hpref'⟩ := DecimalSeqFillPrefixPreserved
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS d1.digits
simp [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
hkeepTrim, hcap] at hparse
have hfill768 :
num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
{ start := 768#usize,
«end» := num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
d1.digits = ok a' := by
simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
using hfill'
rw [hfill768] at hparse
simp at hparse
subst d
constructor
· constructor
· change 768 = min trim.length 768
omega
constructor
· change (a'.val.take 768).map (fun z => z.val) =
trim.take 768
have hpref768 : a'.val.take 768 =
d1.digits.val.take 768 := by
simpa [
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def]
using hpref'
rw [hpref768]
have hd := hdigitPrefix
rw [Nat.min_eq_right (by omega)] at hd
exact hd
· simp only [Bool.true_eq, true_iff]
simpa [trim, sig] using hcap
· exact hpointCong
· obtain ⟨a', hfill', hpref'⟩ :=
DecimalSeqFillPrefixPreserved kept d1.digits
have hle : trim.length <= 768 := by omega
simp [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
hkeepTrim, hcap] at hparse
rw [hfill'] at hparse
simp at hparse
subst d
constructor
· constructor
· change kept.val = min trim.length 768
rw [hkeepTrim, Nat.min_eq_left hle]
constructor
· rw [hpref']
simpa [hkeepTrim, Nat.min_eq_left hle] using hdigitPrefix
· simp [hd1trunc, d0]
simpa [trim, sig] using hle
· exact hpointCong
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Used by
Inspect related source (77)
- parse_decimal_seq · dec2flt/decimal_seq.rs:283 Program Rust
- parse_decimal_seq_loop0 · dec2flt/decimal_seq.rs:290 Program Rust
- body · dec2flt/decimal_seq.rs:290 Program Rust
More program dependencies (44)
- parse_decimal_seq_loop1 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop2 · dec2flt/decimal_seq.rs:303 Program Rust
- body · dec2flt/decimal_seq.rs:303 Program Rust
- parse_decimal_seq_loop3 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop4 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop5 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop6 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop7 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_digits_into_seq · dec2flt/decimal_seq.rs:256 Program Rust
- parse_digits_into_seq_loop · dec2flt/decimal_seq.rs:258 Program Rust
- body · dec2flt/decimal_seq.rs:258 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
- write_u64 · dec2flt/common.rs:25 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
- is_8digits · dec2flt/common.rs:40 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- default · dec2flt/decimal_seq.rs:33 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:63 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:66 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:73 Program Rust
- count_trailing_zeros · dec2flt/decimal_seq.rs:235 Program Rust
- count_trailing_zeros_loop · dec2flt/decimal_seq.rs:239 Program Rust
- body · dec2flt/decimal_seq.rs:239 Program Rust
- parse_decimal_exponent · dec2flt/decimal_seq.rs:269 Program Rust
- parse_decimal_exponent_loop · dec2flt/decimal_seq.rs:272 Program Rust
- body · dec2flt/decimal_seq.rs:272 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
- DecimalDigitTrimDecomposition
- DecimalSeqFillPrefixPreserved
- DecimalSeqI32HCastCongruence
- DecimalSeqIntegerNoExponentState
- DecimalSeqLeadingZeroLoopExact
- DecimalSeqPrimitiveSemantics
All 22 entries
- DecimalDigitTrimDecomposition
- DecimalSeqFillPrefixPreserved
- DecimalSeqI32HCastCongruence
- DecimalSeqIntegerNoExponentState
- DecimalSeqLeadingZeroLoopExact
- DecimalSeqPrimitiveSemantics
- DecimalSeqScalarScanExact
- DecimalSeqTrailingZeroLoopExact
- DecimalSeqTrailingZeroValues
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64
- SourceValidByteSlice
- num imp dec2flt common is 8digits
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq Insts CoreDefaultDefault default
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS WITHOUT OVERFLOW
- num imp dec2flt decimal seq DecimalSeq try add digit
- num imp dec2flt decimal seq count trailing zeros
- num imp dec2flt decimal seq parse decimal exponent
- num imp dec2flt decimal seq parse decimal seq
- num imp dec2flt decimal seq parse digits into seq
Technical checking records
Local closure summary
{
"node": "DecimalSeqIntegerNoExponentState",
"closure_version": "patch_c_v1",
"active_decl_hash": "61d54760345677b1f420d31de55a547706816bca811ddf03f2186d3c41af2456",
"active_statement_hash": "5ae14a37e3b6a66c8585638a6277091c1fe4f2f0e9db52214521f5a60125dcf7",
"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": "worker-result-local-closure-issuance-cycle-169",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalDigitTrimDecomposition": "74d5424585de54f0",
"DecimalSeqFillPrefixPreserved": "4eabf1d65bab5e95",
"DecimalSeqI32HCastCongruence": "bedcc032e9d40104",
"DecimalSeqLeadingZeroLoopExact": "afa2b1ae59f7e9a8",
"DecimalSeqScalarScanExact": "a9ff88a04accf0ed",
"DecimalSeqTrailingZeroValues": "9bf98eea90c6e7c3",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "0eb6fb2627d0ff5c",
"num_imp_dec2flt_decimal_seq_parse_decimal_seq": "39417be39e20ce5d"
},
"strict_definition_deps": {
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
"num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default": "7b9921904495bc2a",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
"num_imp_dec2flt_decimal_seq_count_trailing_zeros": "7a77bc9e01c1a09b",
"num_imp_dec2flt_decimal_seq_parse_decimal_exponent": "e22eec67a6a49ff8",
"num_imp_dec2flt_decimal_seq_parse_decimal_seq": "244cf8318357caab",
"num_imp_dec2flt_decimal_seq_parse_digits_into_seq": "8b2cc3a350f40ce1"
}
}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:d0159b0ae8fbadf8c1c8f9017134d31dfc739314464c7f5c766c5c85ccd5bf7e",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}