Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Returned-record semantics of decimal right shift
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalSeqTrimSemantics
import Tablet.DecimalRightShiftPrefixLoopSemantics
import Tablet.DecimalRightShiftMainLoopSemantics
import Tablet.DecimalRightShiftU64DyadicBridge
import Tablet.DecimalRightShiftFinalLoopSemantics
import Tablet.ResultLoopPartial
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqRightShiftRecordSemantics]
theorem DecimalSeqRightShiftRecordSemantics :
let value := fun d : num.imp.dec2flt.decimal_seq.DecimalSeq =>
let digits :=
(d.digits.val.take d.num_digits.val).map (fun z => z.val)
let integer : Nat := digits.foldl (fun a z => 10 * a + z) 0
(integer : Real) * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int))
forall (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
(shift : Std.Usize),
shift.val <= 60 ->
0 < value d ->
(forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) ->
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift = ok d' ->
(d'.num_digits.val = 0 /\ d'.decimal_point.val = 0 /\
d'.truncated = false) \/
exists rho : Real,
0 <= rho /\
rho < (10 : Real) ^ (d'.decimal_point.val - 768) /\
value d' = value d / (2 : Real) ^ shift.val - rho /\
(d'.truncated = true <->
d.truncated = true \/ 0 < rho) := 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
intro d d' shift hshift hvalue hdigit hcall
let xs := d.digits.val.map (fun z => z.val)
let F := fun ys : List Nat => ys.foldl (fun n z => 10 * n + z) 0
let I := F (xs.take d.num_digits.val)
let B := 2 ^ shift.val
have hscale : 0 < (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int)) :=
zpow_pos (by norm_num) _
have hIreal : 0 < (I : Real) := by
have hv : 0 < (I : Real) * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int)) := by
simpa [I, F, xs, List.map_take] using hvalue
nlinarith
have hIpos : 0 < I := by exact_mod_cast hIreal
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift at hcall
cases hloop0 :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0
d shift 0#usize 0#u64 false with
| fail e => simp [hloop0] at hcall
| div => simp [hloop0] at hcall
| ok out0 =>
rcases out0 with ⟨d0, read, acc, allZero⟩
simp only [hloop0, bind_tc_ok] at hcall
have hpref := DecimalRightShiftPrefixLoopSemantics d d0 shift read acc
allZero hshift (by simpa [I, F, xs, List.map_take] using hIpos) hdigit hloop0
dsimp only at hpref
rcases hpref with ⟨rfl, rfl, hreadpos, hBacc, hacc10, hphase⟩
let reset : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := 0#usize,
decimal_point := 0#i32,
truncated := false,
digits := d0.digits }
change (do
let i ← lift (UScalar.hcast .I32 read)
let i1 ← i - 1#i32
let i2 ← d0.decimal_point - i1
let i3 ← -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
if i2 < i3 then
ok reset
else
let i4 ← 1#u64 <<< shift
let mask ← i4 - 1#u64
let (ac, wi, n1) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
d0.num_digits d0.digits shift read 0#usize acc mask
let (bc, ac1, wi1) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
d0.truncated ac shift wi n1 mask
num.imp.dec2flt.decimal_seq.DecimalSeq.trim
{ num_digits := wi1, decimal_point := i2, truncated := bc,
digits := ac1 }) = ok d' at hcall
let readI : Std.I32 := UScalar.hcast .I32 read
rw [show UScalar.hcast .I32 read = readI by rfl] at hcall
simp only [lift, bind_tc_ok] at hcall
have hreadBound : read.val <= d0.num_digits.val + shift.val := by
rcases hphase with hphase | hphase
· omega
· omega
have hread828 : read.val <= 828 := by
rcases hphase with hphase | hphase <;> omega
have hreadIVal : readI.val = (read.val : Int) := by
have hs := UScalar.hcast_inBounds_spec .I32 read (by
rw [IScalar.max_I32_eq]
omega)
simp only [lift, WP.spec_ok] at hs
exact hs
cases hsub : readI - 1#i32 with
| fail e =>
rw [hsub] at hcall
simp at hcall
| div =>
rw [hsub] at hcall
simp at hcall
| ok readMinus =>
rw [hsub] at hcall
simp only [bind_tc_ok] at hcall
have hsubVal : readMinus.val = readI.val - 1 := by
have hs := IScalar.sub_equiv readI 1#i32
rw [hsub] at hs
exact hs.2.1
cases hpoint : d0.decimal_point - readMinus with
| fail e => simp [hpoint] at hcall
| div => simp [hpoint] at hcall
| ok point =>
rw [hpoint] at hcall
simp only [bind_tc_ok] at hcall
have hpointVal : point.val = d0.decimal_point.val - (read.val : Int) + 1 := by
have hs := IScalar.sub_equiv d0.decimal_point readMinus
rw [hpoint] at hs
rw [hsubVal, hreadIVal] at hs
omega
cases hnegRange : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE with
| fail e => simp [hnegRange] at hcall
| div => simp [hnegRange] at hcall
| ok negRange =>
rw [hnegRange] at hcall
simp only [bind_tc_ok] at hcall
by_cases hreset : point < negRange
· simp only [hreset, if_true] at hcall
have hd' : d' = reset := by simpa using hcall.symm
subst d'
exact Or.inl ⟨by simp [reset], by simp [reset], by simp [reset]⟩
· simp only [hreset, if_false] at hcall
cases hpow : 1#u64 <<< shift with
| fail e => simp [hpow] at hcall
| div => simp [hpow] at hcall
| ok pow =>
rw [hpow] at hcall
simp only [bind_tc_ok] at hcall
cases hmask : pow - 1#u64 with
| fail e => simp [hmask] at hcall
| div => simp [hmask] at hcall
| ok mask =>
rw [hmask] at hcall
simp only [bind_tc_ok] at hcall
cases hloop1 :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
d0.num_digits d0.digits shift read 0#usize acc mask with
| fail e => simp [hloop1] at hcall
| div => simp [hloop1] at hcall
| ok out1 =>
rcases out1 with ⟨a1, write1, acc1⟩
rw [hloop1] at hcall
simp only [bind_tc_ok] at hcall
have hmain : d0.num_digits.val <= 768 /\
exists low : List Nat,
low.length = d0.num_digits.val - read.val /\
(forall z, z ∈ low -> z < 10) /\
write1.val = d0.num_digits.val - read.val /\
acc1.val < 10 * B /\
acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val) =
B * (10 * F low) + acc1.val /\
(forall j, j < low.length ->
(a1.val.map (fun z : Std.U8 => z.val))[j]? = low[j]?) /\
(forall j, j < 768 -> write1.val <= j ->
a1.val[j]? = d0.digits.val[j]?) /\
(forall j, j < 768 -> d0.num_digits.val <= j ->
a1.val[j]? = d0.digits.val[j]?) := by
by_cases hrn : read.val < d0.num_digits.val
· have hm := DecimalRightShiftMainLoopSemantics
d0.digits a1 shift read d0.num_digits write1 pow mask acc acc1
hshift hreadpos (by omega) (by omega) hacc10 hdigit hpow hmask
hloop1
simpa [xs, F, B] using hm
· have hreadGe : d0.num_digits.val <= read.val := by omega
have hreadWord : ¬ read < d0.num_digits := by
simpa [UScalar.lt_equiv] using hrn
have hloop1Direct :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
d0.num_digits d0.digits shift read 0#usize acc mask =
ok (d0.digits, 0#usize, acc) := by
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1.body,
hreadWord]
rw [hloop1Direct] at hloop1
cases hloop1
have hnBound : d0.num_digits.val <= 768 := by
rcases hphase with hp | hp <;> omega
refine ⟨hnBound, [], by simp [Nat.sub_eq_zero_of_le hreadGe],
by simp, by simp [Nat.sub_eq_zero_of_le hreadGe], hacc10,
?_, ?_, ?_, ?_⟩
· have hdrop : (xs.take d0.num_digits.val).drop read.val = [] :=
List.drop_eq_nil_of_le (by simp; omega)
have hsubzero : d0.num_digits.val - read.val = 0 :=
Nat.sub_eq_zero_of_le hreadGe
simp [F, hdrop, hsubzero]
· intro j hj
simp at hj
· intro j hj _
rfl
· intro j hj _
rfl
rcases hmain with ⟨_, low, hlowLen, hlowDigit, hwrite1,
hacc1, hmainNum, hlowArray, houtside1, hhigh1⟩
cases hloop2 :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
d0.truncated a1 shift write1 acc1 mask with
| fail e => simp [hloop2] at hcall
| div => simp [hloop2] at hcall
| ok out2 =>
rcases out2 with ⟨b2, a2, write2⟩
change (do
let (bc, ac, wi) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
d0.truncated a1 shift write1 acc1 mask
num.imp.dec2flt.decimal_seq.DecimalSeq.trim
{ num_digits := wi, decimal_point := point,
truncated := bc, digits := ac }) = ok d' at hcall
rw [hloop2] at hcall
simp only [bind_tc_ok] at hcall
have hfinal := DecimalRightShiftFinalLoopSemantics
a1 a2 d0.truncated b2 shift write1 write2 pow mask acc1
hshift (by omega) hacc1 hpow hmask hloop2
dsimp only at hfinal
rcases hfinal with ⟨high, hhighDigit, hfinalNum, hwrite2,
hhighArray, hbelow2, houtside2, hsticky2⟩
let all := low ++ high
have hallDigit : forall z, z ∈ all -> z < 10 := by
intro z hz
simp only [all, List.mem_append] at hz
rcases hz with hz | hz
· exact hlowDigit z hz
· exact hhighDigit z hz
have hallLen : all.length = low.length + high.length := by simp [all]
have hallFold : F all = F low * 10 ^ high.length + F high := by
simp only [all, F, List.foldl_append]
have foldFrom (ys : List Nat) (n : Nat) :
ys.foldl (fun x z => 10 * x + z) n =
n * 10 ^ ys.length + F ys := by
induction ys generalizing n with
| nil => simp [F]
| cons y ys ih =>
simp only [List.foldl_cons, List.length_cons]
rw [ih, pow_succ]
change (10 * n + y) * 10 ^ ys.length + F ys =
n * (10 ^ ys.length * 10) +
(y :: ys).foldl (fun x z => 10 * x + z) 0
simp only [List.foldl_cons]
rw [ih]
ring
simpa using foldFrom high (F low)
have hcombined :
acc.val * 10 ^ (d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length =
B * (10 * F all) := by
rw [hallFold]
calc
acc.val * 10 ^ (d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length =
(acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val)) *
10 ^ high.length := by rw [pow_add]; ring
_ = (B * (10 * F low) + acc1.val) *
10 ^ high.length := by rw [hmainNum]
_ = B * (10 * F low) * 10 ^ high.length +
acc1.val * 10 ^ high.length := by ring
_ = B * (10 * (F low * 10 ^ high.length + F high)) := by
rw [hfinalNum]
ring
let extra := read.val - d0.num_digits.val + high.length
have foldFrom2 (ys : List Nat) (n : Nat) :
ys.foldl (fun x z => 10 * x + z) n =
n * 10 ^ ys.length + F ys := by
induction ys generalizing n with
| nil => simp [F]
| cons y ys ih =>
simp only [List.foldl_cons, List.length_cons]
rw [ih, pow_succ]
change (10 * n + y) * 10 ^ ys.length + F ys =
n * (10 ^ ys.length * 10) +
(y :: ys).foldl (fun x z => 10 * x + z) 0
simp only [List.foldl_cons]
rw [ih]
ring
have hterminal : I * 10 ^ extra = B * (10 * F all) := by
rcases hphase with hp | hp
· rcases hp with ⟨hrn, _, haccPrefix⟩
have htake : (xs.take d0.num_digits.val).take read.val =
xs.take read.val := by
rw [List.take_take]
simp [Nat.min_eq_left hrn]
have hsplit : I =
acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val) := by
have hdropLen :
((xs.take d0.num_digits.val).drop read.val).length =
d0.num_digits.val - read.val := by
simp [xs, d0.digits.property]
omega
change F (xs.take d0.num_digits.val) = _
conv_lhs =>
rw [← List.take_append_drop read.val
(xs.take d0.num_digits.val)]
simp only [F, List.foldl_append]
rw [foldFrom2, htake, hdropLen]
rw [← haccPrefix]
have hrsub : read.val - d0.num_digits.val = 0 :=
Nat.sub_eq_zero_of_le hrn
rw [show extra = high.length by simp [extra, hrsub]]
calc
I * 10 ^ high.length =
(acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val)) *
10 ^ high.length := by rw [hsplit]
_ = acc.val * 10 ^
(d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length := by rw [pow_add]; ring
_ = B * (10 * F all) := hcombined
· rcases hp with ⟨hnr, _, _, haccExtended⟩
have hnsub : d0.num_digits.val - read.val = 0 :=
Nat.sub_eq_zero_of_le (by omega)
have hdrop :
(xs.take d0.num_digits.val).drop read.val = [] :=
List.drop_eq_nil_of_le (by simp; omega)
calc
I * 10 ^ extra =
(I * 10 ^ (read.val - d0.num_digits.val)) *
10 ^ high.length := by
rw [show extra =
(read.val - d0.num_digits.val) + high.length by rfl,
pow_add]
ring
_ = acc.val * 10 ^ high.length := by rw [haccExtended]
_ = acc.val * 10 ^
(d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length := by simp [hnsub, hdrop, F]
_ = B * (10 * F all) := hcombined
have hlowWrite : write1.val = low.length := by omega
have hlowCap : low.length <= 768 := by omega
have hwriteAll : write2.val = min all.length 768 := by
rw [hwrite2, hwrite1, hallLen, hlowLen]
have hwriteCap : write2.val <= 768 := by
rw [hwriteAll]
exact Nat.min_le_right _ _
have hwriteLen : write2.val <= all.length := by
rw [hwriteAll]
exact Nat.min_le_left _ _
let kept := all.take write2.val
let tail := all.drop write2.val
have hpreDigits :
(a2.val.take write2.val).map (fun z => z.val) = kept := by
simp only [kept, List.map_take]
apply List.ext_getElem
· simp [hwriteCap, hwriteLen, a2.property]
· intro j hj1 hj2
have hjm : j < write2.val := by
simpa [List.length_take, hwriteCap, a2.property] using hj1
have hj768 : j < 768 := by omega
by_cases hjlow : j < low.length
· have ha1 := hlowArray j hjlow
have ha2raw := hbelow2 j hj768 (by omega)
have ha2 :
(a2.val.map (fun z : Std.U8 => z.val))[j]? = low[j]? := by
rw [List.getElem?_map, ha2raw]
simpa [List.getElem?_map] using ha1
have hall : all[j]? = low[j]? := by
rw [List.getElem?_append_left (by simpa using hjlow)]
have hmapBound :
j < (a2.val.map (fun z : Std.U8 => z.val)).length := by
simp [a2.property]
exact hj768
have hallBound : j < all.length := by omega
rw [show ((a2.val.map (fun z : Std.U8 => z.val)).take
write2.val)[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j] by simp]
rw [show (all.take write2.val)[j] = all[j] by simp]
apply Option.some.inj
calc
some (a2.val.map (fun z : Std.U8 => z.val))[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j]? :=
(List.getElem?_eq_getElem hmapBound).symm
_ = low[j]? := ha2
_ = all[j]? := hall.symm
_ = some all[j] := List.getElem?_eq_getElem hallBound
· let t := j - low.length
have ht : t < high.length := by
simp only [t]
simp [all] at hj2
omega
have hjEq : write1.val + t = j := by
simp only [t]
omega
have ha2 := hhighArray t ht (by omega)
have hall : all[j]? = high[t]? := by
rw [List.getElem?_append_right (by simpa using hjlow)]
have hmapBound :
j < (a2.val.map (fun z : Std.U8 => z.val)).length := by
simp [a2.property]
exact hj768
have hallBound : j < all.length := by omega
rw [show ((a2.val.map (fun z : Std.U8 => z.val)).take
write2.val)[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j] by simp]
rw [show (all.take write2.val)[j] = all[j] by simp]
rw [hjEq] at ha2
apply Option.some.inj
calc
some (a2.val.map (fun z : Std.U8 => z.val))[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j]? :=
(List.getElem?_eq_getElem hmapBound).symm
_ = high[t]? := ha2
_ = all[j]? := hall.symm
_ = some all[j] := List.getElem?_eq_getElem hallBound
have foldPos (ys : List Nat) :
0 < F ys <->
exists j, j < ys.length /\ ys[j]? != some 0 := by
induction ys with
| nil => simp [F]
| cons y ys ih =>
have hform : F (y :: ys) =
y * 10 ^ ys.length + F ys := by
simpa [F] using foldFrom2 ys y
rw [hform]
constructor
· intro hp
by_cases hy : y = 0
· have ht : 0 < F ys := by simpa [hy] using hp
rcases ih.mp ht with ⟨j, hj, hjnz⟩
exact ⟨j + 1, by simp; omega, by simpa using hjnz⟩
· exact ⟨0, by simp, by simp [hy]⟩
· rintro ⟨j, hj, hjnz⟩
cases j with
| zero =>
have hyne : y ≠ 0 := by
intro hy
subst y
simp at hjnz
have hy : 0 < y := Nat.pos_of_ne_zero hyne
have hpow : 0 < 10 ^ ys.length := by positivity
positivity
| succ j =>
have hjlt : j < ys.length := by simp at hj; omega
have ht : 0 < F ys :=
ih.mpr ⟨j, hjlt, by simpa using hjnz⟩
omega
have htailSticky :
(exists t, t < tail.length /\ tail[t]? != some 0) <->
(exists j, j < high.length /\
768 <= write1.val + j /\ high[j]? != some 0) := by
constructor
· rintro ⟨t, ht, htnz⟩
have ht' : t < all.length - write2.val := by
simpa [tail] using ht
have hwriteEq : write2.val = 768 := by
rw [hwriteAll]
omega
let g := write2.val + t
have hgall : g < all.length := by simp [g]; omega
have hglow : low.length <= g := by
simp [g, hwriteEq]
omega
let j := g - low.length
have hj : j < high.length := by
simp [all] at hgall
simp [j]
omega
have hdest : write1.val + j = g := by
rw [hlowWrite]
simp [j]
omega
have htailGet : tail[t]? = all[g]? := by
simp [tail, g, List.getElem?_drop]
have hallHigh : all[g]? = high[j]? := by
simp only [all, List.getElem?_append_right (by omega)]
simp [j]
refine ⟨j, hj, ?_, ?_⟩
· rw [hdest]
simp [g, hwriteEq]
· rw [htailGet, hallHigh] at htnz
exact htnz
· rintro ⟨j, hj, hjcap, hjnz⟩
let g := low.length + j
have hgall : g < all.length := by simp [g, all, hj]
have hdest : write1.val + j = g := by simp [g, hlowWrite]
have hgcap : 768 <= g := by simpa [hdest] using hjcap
have hwriteEq : write2.val = 768 := by
rw [hwriteAll]
omega
let t := g - write2.val
have ht : t < tail.length := by
simp [tail, t]
omega
have htailGet : tail[t]? = all[g]? := by
rw [List.getElem?_drop]
simp [t]
congr 1
omega
have hallHigh : all[g]? = high[j]? := by
simp only [all]
rw [List.getElem?_append_right (by simp [g])]
simp [g]
refine ⟨t, ht, ?_⟩
rw [htailGet, hallHigh]
exact hjnz
have decimalScale (I0 Q0 B0 extra0 L0 n0 : Nat)
(p0 point0 : Int) (hB0 : 0 < B0)
(hnum0 : I0 * 10 ^ extra0 = B0 * (10 * Q0))
(hexp0 : point0 - (L0 : Int) + (extra0 : Int) =
p0 - (n0 : Int) + 1) :
(Q0 : Real) * (10 : Real) ^ (point0 - (L0 : Int)) =
(I0 : Real) * (10 : Real) ^ (p0 - (n0 : Int)) /
(B0 : Real) := by
have hnumR : (I0 : Real) * (10 : Real) ^ extra0 =
(B0 : Real) * (10 * (Q0 : Real)) := by
exact_mod_cast hnum0
have h10 : (10 : Real) ≠ 0 := by norm_num
have hBR : (B0 : Real) ≠ 0 := by positivity
apply (eq_div_iff hBR).2
have hpows :
(10 : Real) ^ (point0 - (L0 : Int)) *
(10 : Real) ^ (extra0 : Int) =
(10 : Real) ^ (p0 - (n0 : Int) + 1) := by
rw [← zpow_add₀ h10, hexp0]
have hpowExtra : (10 : Real) ^ (extra0 : Int) =
(10 : Real) ^ extra0 := by
norm_num only [zpow_natCast]
have hp : (10 : Real) ^ (p0 - (n0 : Int) + 1) =
(10 : Real) ^ (p0 - (n0 : Int)) * 10 := by
rw [zpow_add₀ h10]
norm_num
calc
(Q0 : Real) * (10 : Real) ^ (point0 - (L0 : Int)) *
(B0 : Real) =
((B0 : Real) * (10 * (Q0 : Real))) / 10 *
(10 : Real) ^ (point0 - (L0 : Int)) := by ring
_ = ((I0 : Real) * (10 : Real) ^ extra0) / 10 *
(10 : Real) ^ (point0 - (L0 : Int)) := by
rw [hnumR]
_ = (I0 : Real) *
((10 : Real) ^ (point0 - (L0 : Int)) *
(10 : Real) ^ (extra0 : Int)) / 10 := by
rw [hpowExtra]
ring
_ = (I0 : Real) *
(10 : Real) ^ (p0 - (n0 : Int)) := by
rw [hpows, hp]
ring
have hexp : point.val - (all.length : Int) + (extra : Int) =
d0.decimal_point.val - (d0.num_digits.val : Int) + 1 := by
rw [hpointVal, hallLen, hlowLen]
simp only [extra, Nat.cast_add]
rcases hphase with hp | hp
· have hrsub : read.val - d0.num_digits.val = 0 :=
Nat.sub_eq_zero_of_le hp.1
rw [hrsub]
simp
rw [Nat.cast_sub hp.1]
omega
· have hnle : d0.num_digits.val <= read.val := by omega
have hnsub : d0.num_digits.val - read.val = 0 :=
Nat.sub_eq_zero_of_le hnle
rw [hnsub]
simp
rw [Nat.cast_sub hnle]
omega
have hBpos : 0 < B := by simp [B]
have hfullValue :
(F all : Real) *
(10 : Real) ^ (point.val - (all.length : Int)) =
(I : Real) * (10 : Real) ^
(d0.decimal_point.val -
(d0.num_digits.val : Int)) / (B : Real) :=
decimalScale I (F all) B extra all.length
d0.num_digits.val d0.decimal_point.val point.val hBpos
hterminal hexp
have capSplit (ys : List Nat) (m : Nat) (p0 : Int)
(hm : m <= ys.length) :
(F ys : Real) *
(10 : Real) ^ (p0 - (ys.length : Int)) =
(F (ys.take m) : Real) *
(10 : Real) ^ (p0 - (m : Int)) +
(F (ys.drop m) : Real) *
(10 : Real) ^ (p0 - (ys.length : Int)) := by
have hfold : F ys = F (ys.take m) * 10 ^ (ys.length - m) +
F (ys.drop m) := by
conv_lhs => rw [← List.take_append_drop m ys]
simp only [F, List.foldl_append]
rw [foldFrom2]
congr 2
simp
have hexp' : p0 - (m : Int) =
(p0 - (ys.length : Int)) +
((ys.length - m : Nat) : Int) := by
rw [Nat.cast_sub hm]
omega
have hpow : (10 : Real) ^ (p0 - (m : Int)) =
(10 : Real) ^ (p0 - (ys.length : Int)) *
(10 : Real) ^ (ys.length - m) := by
rw [hexp', zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
norm_num only [zpow_natCast]
rw [show (F ys : Real) =
(F (ys.take m) : Real) *
(10 : Real) ^ (ys.length - m) +
(F (ys.drop m) : Real) by exact_mod_cast hfold]
rw [hpow]
ring
have hcapSplit :
(F all : Real) *
(10 : Real) ^ (point.val - (all.length : Int)) =
(F kept : Real) *
(10 : Real) ^ (point.val - (write2.val : Int)) +
(F tail : Real) *
(10 : Real) ^ (point.val - (all.length : Int)) := by
simpa [kept, tail] using
capSplit all write2.val point.val hwriteLen
let rho : Real := (F tail : Real) *
(10 : Real) ^ (point.val - (all.length : Int))
have hrho0 : 0 <= rho := by
dsimp only [rho]
exact mul_nonneg (Nat.cast_nonneg _) (le_of_lt
(zpow_pos (by norm_num : (0 : Real) < 10) _))
have hrhoPos : 0 < rho <-> 0 < F tail := by
dsimp only [rho]
have hp : 0 < (10 : Real) ^
(point.val - (all.length : Int)) :=
zpow_pos (by norm_num) _
constructor
· intro h
have : 0 < (F tail : Real) := by nlinarith
exact_mod_cast this
· intro h
have hc : 0 < (F tail : Real) := by exact_mod_cast h
positivity
have hrhoSticky :
0 < rho <->
exists j, j < high.length /\
768 <= write1.val + j /\ high[j]? != some 0 := by
rw [hrhoPos, foldPos, htailSticky]
have foldBound (ys : List Nat)
(hd : forall z, z ∈ ys -> z < 10) :
F ys < 10 ^ ys.length := by
induction ys with
| nil => simp [F]
| cons y ys ih =>
have hy : y < 10 := hd y (by simp)
have hys : forall z, z ∈ ys -> z < 10 := by
intro z hz
exact hd z (by simp [hz])
have hi := ih hys
rw [show F (y :: ys) =
y * 10 ^ ys.length + F ys by
simpa [F] using foldFrom2 ys y,
List.length_cons, pow_succ]
have hmul : y * 10 ^ ys.length <=
9 * 10 ^ ys.length :=
Nat.mul_le_mul_right _ (by omega)
calc
y * 10 ^ ys.length + F ys <
y * 10 ^ ys.length + 10 ^ ys.length :=
Nat.add_lt_add_left hi _
_ <= 9 * 10 ^ ys.length + 10 ^ ys.length :=
Nat.add_le_add_right hmul _
_ = 10 ^ ys.length * 10 := by ring
have htailDigit : forall z, z ∈ tail -> z < 10 := by
intro z hz
exact hallDigit z (List.mem_of_mem_drop hz)
have htailBound : F tail < 10 ^ tail.length :=
foldBound tail htailDigit
let pre : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := write2, decimal_point := point,
truncated := b2, digits := a2 }
have htrim :
num.imp.dec2flt.decimal_seq.DecimalSeq.trim pre = ok d' := by
simpa [pre] using hcall
have hpreBound : pre.num_digits.val <= pre.digits.val.length := by
simp [pre, a2.property]
exact hwriteCap
have htrimSem := DecimalSeqTrimSemantics pre d' hpreBound htrim
dsimp only at htrimSem
rcases htrimSem with
⟨_, hpointTrim, htrunc, _, _, _, htrimValue⟩
have hrhoCell :
rho < (10 : Real) ^ (d'.decimal_point.val - 768) := by
by_cases htailZero : F tail = 0
· simp only [rho, htailZero, Nat.cast_zero, zero_mul]
exact zpow_pos (by norm_num) _
· have htailPos : 0 < F tail := Nat.pos_of_ne_zero htailZero
have htailNonempty : 0 < tail.length := by
by_contra hlen
have : tail = [] := List.eq_nil_of_length_eq_zero (by omega)
simp [this, F] at htailPos
have hwriteEq : write2.val = 768 := by
simp [tail] at htailNonempty
rw [Nat.min_def] at hwriteAll
split at hwriteAll
· omega
· omega
have hexpCell :
point.val - (all.length : Int) +
(tail.length : Int) =
d'.decimal_point.val - 768 := by
rw [show tail.length = all.length - write2.val by
simp [tail]]
rw [Nat.cast_sub hwriteLen, hwriteEq]
rw [hpointTrim]
simp only [pre]
omega
have hcastBound :
(F tail : Real) < (10 : Real) ^ tail.length := by
exact_mod_cast htailBound
have hscalePos : 0 < (10 : Real) ^
(point.val - (all.length : Int)) :=
zpow_pos (by norm_num) _
calc
rho = (F tail : Real) * (10 : Real) ^
(point.val - (all.length : Int)) := rfl
_ < (10 : Real) ^ tail.length * (10 : Real) ^
(point.val - (all.length : Int)) :=
mul_lt_mul_of_pos_right hcastBound hscalePos
_ = (10 : Real) ^
(d'.decimal_point.val - 768) := by
norm_num only [← zpow_natCast]
rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
rw [add_comm, hexpCell]
right
refine ⟨rho, hrho0, hrhoCell, ?_, ?_⟩
· rw [htrimValue]
simp only [pre]
rw [hpreDigits]
have hOrigFold :
((d0.digits.val.take d0.num_digits.val).map
(fun z => z.val)).foldl
(fun n z => 10 * n + z) 0 = I := by
simp [I, F, xs, List.map_take]
rw [hOrigFold]
change (F kept : Real) *
(10 : Real) ^ (point.val - (write2.val : Int)) =
(I : Real) * (10 : Real) ^
(d0.decimal_point.val -
(d0.num_digits.val : Int)) /
(2 : Real) ^ shift.val - rho
have hBReal : (B : Real) = (2 : Real) ^ shift.val := by
simp [B]
rw [← hBReal, ← hfullValue]
rw [hcapSplit]
simp [rho]
· rw [htrunc, hsticky2, hrhoSticky]
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.DecimalSeqTrimSemantics
import Tablet.DecimalRightShiftPrefixLoopSemantics
import Tablet.DecimalRightShiftMainLoopSemantics
import Tablet.DecimalRightShiftU64DyadicBridge
import Tablet.DecimalRightShiftFinalLoopSemantics
import Tablet.ResultLoopPartial
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqRightShiftRecordSemantics]
theorem DecimalSeqRightShiftRecordSemantics :
let value := fun d : num.imp.dec2flt.decimal_seq.DecimalSeq =>
let digits :=
(d.digits.val.take d.num_digits.val).map (fun z => z.val)
let integer : Nat := digits.foldl (fun a z => 10 * a + z) 0
(integer : Real) * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int))
forall (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq)
(shift : Std.Usize),
shift.val <= 60 ->
0 < value d ->
(forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) ->
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d shift = ok d' ->
(d'.num_digits.val = 0 /\ d'.decimal_point.val = 0 /\
d'.truncated = false) \/
exists rho : Real,
0 <= rho /\
rho < (10 : Real) ^ (d'.decimal_point.val - 768) /\
value d' = value d / (2 : Real) ^ shift.val - rho /\
(d'.truncated = true <->
d.truncated = true \/ 0 < rho) := by
-- BODY
dsimp only
intro d d' shift hshift hvalue hdigit hcall
let xs := d.digits.val.map (fun z => z.val)
let F := fun ys : List Nat => ys.foldl (fun n z => 10 * n + z) 0
let I := F (xs.take d.num_digits.val)
let B := 2 ^ shift.val
have hscale : 0 < (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int)) :=
zpow_pos (by norm_num) _
have hIreal : 0 < (I : Real) := by
have hv : 0 < (I : Real) * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int)) := by
simpa [I, F, xs, List.map_take] using hvalue
nlinarith
have hIpos : 0 < I := by exact_mod_cast hIreal
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift at hcall
cases hloop0 :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0
d shift 0#usize 0#u64 false with
| fail e => simp [hloop0] at hcall
| div => simp [hloop0] at hcall
| ok out0 =>
rcases out0 with ⟨d0, read, acc, allZero⟩
simp only [hloop0, bind_tc_ok] at hcall
have hpref := DecimalRightShiftPrefixLoopSemantics d d0 shift read acc
allZero hshift (by simpa [I, F, xs, List.map_take] using hIpos) hdigit hloop0
dsimp only at hpref
rcases hpref with ⟨rfl, rfl, hreadpos, hBacc, hacc10, hphase⟩
let reset : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := 0#usize,
decimal_point := 0#i32,
truncated := false,
digits := d0.digits }
change (do
let i ← lift (UScalar.hcast .I32 read)
let i1 ← i - 1#i32
let i2 ← d0.decimal_point - i1
let i3 ← -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
if i2 < i3 then
ok reset
else
let i4 ← 1#u64 <<< shift
let mask ← i4 - 1#u64
let (ac, wi, n1) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
d0.num_digits d0.digits shift read 0#usize acc mask
let (bc, ac1, wi1) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
d0.truncated ac shift wi n1 mask
num.imp.dec2flt.decimal_seq.DecimalSeq.trim
{ num_digits := wi1, decimal_point := i2, truncated := bc,
digits := ac1 }) = ok d' at hcall
let readI : Std.I32 := UScalar.hcast .I32 read
rw [show UScalar.hcast .I32 read = readI by rfl] at hcall
simp only [lift, bind_tc_ok] at hcall
have hreadBound : read.val <= d0.num_digits.val + shift.val := by
rcases hphase with hphase | hphase
· omega
· omega
have hread828 : read.val <= 828 := by
rcases hphase with hphase | hphase <;> omega
have hreadIVal : readI.val = (read.val : Int) := by
have hs := UScalar.hcast_inBounds_spec .I32 read (by
rw [IScalar.max_I32_eq]
omega)
simp only [lift, WP.spec_ok] at hs
exact hs
cases hsub : readI - 1#i32 with
| fail e =>
rw [hsub] at hcall
simp at hcall
| div =>
rw [hsub] at hcall
simp at hcall
| ok readMinus =>
rw [hsub] at hcall
simp only [bind_tc_ok] at hcall
have hsubVal : readMinus.val = readI.val - 1 := by
have hs := IScalar.sub_equiv readI 1#i32
rw [hsub] at hs
exact hs.2.1
cases hpoint : d0.decimal_point - readMinus with
| fail e => simp [hpoint] at hcall
| div => simp [hpoint] at hcall
| ok point =>
rw [hpoint] at hcall
simp only [bind_tc_ok] at hcall
have hpointVal : point.val = d0.decimal_point.val - (read.val : Int) + 1 := by
have hs := IScalar.sub_equiv d0.decimal_point readMinus
rw [hpoint] at hs
rw [hsubVal, hreadIVal] at hs
omega
cases hnegRange : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE with
| fail e => simp [hnegRange] at hcall
| div => simp [hnegRange] at hcall
| ok negRange =>
rw [hnegRange] at hcall
simp only [bind_tc_ok] at hcall
by_cases hreset : point < negRange
· simp only [hreset, if_true] at hcall
have hd' : d' = reset := by simpa using hcall.symm
subst d'
exact Or.inl ⟨by simp [reset], by simp [reset], by simp [reset]⟩
· simp only [hreset, if_false] at hcall
cases hpow : 1#u64 <<< shift with
| fail e => simp [hpow] at hcall
| div => simp [hpow] at hcall
| ok pow =>
rw [hpow] at hcall
simp only [bind_tc_ok] at hcall
cases hmask : pow - 1#u64 with
| fail e => simp [hmask] at hcall
| div => simp [hmask] at hcall
| ok mask =>
rw [hmask] at hcall
simp only [bind_tc_ok] at hcall
cases hloop1 :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
d0.num_digits d0.digits shift read 0#usize acc mask with
| fail e => simp [hloop1] at hcall
| div => simp [hloop1] at hcall
| ok out1 =>
rcases out1 with ⟨a1, write1, acc1⟩
rw [hloop1] at hcall
simp only [bind_tc_ok] at hcall
have hmain : d0.num_digits.val <= 768 /\
exists low : List Nat,
low.length = d0.num_digits.val - read.val /\
(forall z, z ∈ low -> z < 10) /\
write1.val = d0.num_digits.val - read.val /\
acc1.val < 10 * B /\
acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val) =
B * (10 * F low) + acc1.val /\
(forall j, j < low.length ->
(a1.val.map (fun z : Std.U8 => z.val))[j]? = low[j]?) /\
(forall j, j < 768 -> write1.val <= j ->
a1.val[j]? = d0.digits.val[j]?) /\
(forall j, j < 768 -> d0.num_digits.val <= j ->
a1.val[j]? = d0.digits.val[j]?) := by
by_cases hrn : read.val < d0.num_digits.val
· have hm := DecimalRightShiftMainLoopSemantics
d0.digits a1 shift read d0.num_digits write1 pow mask acc acc1
hshift hreadpos (by omega) (by omega) hacc10 hdigit hpow hmask
hloop1
simpa [xs, F, B] using hm
· have hreadGe : d0.num_digits.val <= read.val := by omega
have hreadWord : ¬ read < d0.num_digits := by
simpa [UScalar.lt_equiv] using hrn
have hloop1Direct :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
d0.num_digits d0.digits shift read 0#usize acc mask =
ok (d0.digits, 0#usize, acc) := by
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1.body,
hreadWord]
rw [hloop1Direct] at hloop1
cases hloop1
have hnBound : d0.num_digits.val <= 768 := by
rcases hphase with hp | hp <;> omega
refine ⟨hnBound, [], by simp [Nat.sub_eq_zero_of_le hreadGe],
by simp, by simp [Nat.sub_eq_zero_of_le hreadGe], hacc10,
?_, ?_, ?_, ?_⟩
· have hdrop : (xs.take d0.num_digits.val).drop read.val = [] :=
List.drop_eq_nil_of_le (by simp; omega)
have hsubzero : d0.num_digits.val - read.val = 0 :=
Nat.sub_eq_zero_of_le hreadGe
simp [F, hdrop, hsubzero]
· intro j hj
simp at hj
· intro j hj _
rfl
· intro j hj _
rfl
rcases hmain with ⟨_, low, hlowLen, hlowDigit, hwrite1,
hacc1, hmainNum, hlowArray, houtside1, hhigh1⟩
cases hloop2 :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
d0.truncated a1 shift write1 acc1 mask with
| fail e => simp [hloop2] at hcall
| div => simp [hloop2] at hcall
| ok out2 =>
rcases out2 with ⟨b2, a2, write2⟩
change (do
let (bc, ac, wi) ←
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
d0.truncated a1 shift write1 acc1 mask
num.imp.dec2flt.decimal_seq.DecimalSeq.trim
{ num_digits := wi, decimal_point := point,
truncated := bc, digits := ac }) = ok d' at hcall
rw [hloop2] at hcall
simp only [bind_tc_ok] at hcall
have hfinal := DecimalRightShiftFinalLoopSemantics
a1 a2 d0.truncated b2 shift write1 write2 pow mask acc1
hshift (by omega) hacc1 hpow hmask hloop2
dsimp only at hfinal
rcases hfinal with ⟨high, hhighDigit, hfinalNum, hwrite2,
hhighArray, hbelow2, houtside2, hsticky2⟩
let all := low ++ high
have hallDigit : forall z, z ∈ all -> z < 10 := by
intro z hz
simp only [all, List.mem_append] at hz
rcases hz with hz | hz
· exact hlowDigit z hz
· exact hhighDigit z hz
have hallLen : all.length = low.length + high.length := by simp [all]
have hallFold : F all = F low * 10 ^ high.length + F high := by
simp only [all, F, List.foldl_append]
have foldFrom (ys : List Nat) (n : Nat) :
ys.foldl (fun x z => 10 * x + z) n =
n * 10 ^ ys.length + F ys := by
induction ys generalizing n with
| nil => simp [F]
| cons y ys ih =>
simp only [List.foldl_cons, List.length_cons]
rw [ih, pow_succ]
change (10 * n + y) * 10 ^ ys.length + F ys =
n * (10 ^ ys.length * 10) +
(y :: ys).foldl (fun x z => 10 * x + z) 0
simp only [List.foldl_cons]
rw [ih]
ring
simpa using foldFrom high (F low)
have hcombined :
acc.val * 10 ^ (d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length =
B * (10 * F all) := by
rw [hallFold]
calc
acc.val * 10 ^ (d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length =
(acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val)) *
10 ^ high.length := by rw [pow_add]; ring
_ = (B * (10 * F low) + acc1.val) *
10 ^ high.length := by rw [hmainNum]
_ = B * (10 * F low) * 10 ^ high.length +
acc1.val * 10 ^ high.length := by ring
_ = B * (10 * (F low * 10 ^ high.length + F high)) := by
rw [hfinalNum]
ring
let extra := read.val - d0.num_digits.val + high.length
have foldFrom2 (ys : List Nat) (n : Nat) :
ys.foldl (fun x z => 10 * x + z) n =
n * 10 ^ ys.length + F ys := by
induction ys generalizing n with
| nil => simp [F]
| cons y ys ih =>
simp only [List.foldl_cons, List.length_cons]
rw [ih, pow_succ]
change (10 * n + y) * 10 ^ ys.length + F ys =
n * (10 ^ ys.length * 10) +
(y :: ys).foldl (fun x z => 10 * x + z) 0
simp only [List.foldl_cons]
rw [ih]
ring
have hterminal : I * 10 ^ extra = B * (10 * F all) := by
rcases hphase with hp | hp
· rcases hp with ⟨hrn, _, haccPrefix⟩
have htake : (xs.take d0.num_digits.val).take read.val =
xs.take read.val := by
rw [List.take_take]
simp [Nat.min_eq_left hrn]
have hsplit : I =
acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val) := by
have hdropLen :
((xs.take d0.num_digits.val).drop read.val).length =
d0.num_digits.val - read.val := by
simp [xs, d0.digits.property]
omega
change F (xs.take d0.num_digits.val) = _
conv_lhs =>
rw [← List.take_append_drop read.val
(xs.take d0.num_digits.val)]
simp only [F, List.foldl_append]
rw [foldFrom2, htake, hdropLen]
rw [← haccPrefix]
have hrsub : read.val - d0.num_digits.val = 0 :=
Nat.sub_eq_zero_of_le hrn
rw [show extra = high.length by simp [extra, hrsub]]
calc
I * 10 ^ high.length =
(acc.val * 10 ^ (d0.num_digits.val - read.val) +
F ((xs.take d0.num_digits.val).drop read.val)) *
10 ^ high.length := by rw [hsplit]
_ = acc.val * 10 ^
(d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length := by rw [pow_add]; ring
_ = B * (10 * F all) := hcombined
· rcases hp with ⟨hnr, _, _, haccExtended⟩
have hnsub : d0.num_digits.val - read.val = 0 :=
Nat.sub_eq_zero_of_le (by omega)
have hdrop :
(xs.take d0.num_digits.val).drop read.val = [] :=
List.drop_eq_nil_of_le (by simp; omega)
calc
I * 10 ^ extra =
(I * 10 ^ (read.val - d0.num_digits.val)) *
10 ^ high.length := by
rw [show extra =
(read.val - d0.num_digits.val) + high.length by rfl,
pow_add]
ring
_ = acc.val * 10 ^ high.length := by rw [haccExtended]
_ = acc.val * 10 ^
(d0.num_digits.val - read.val + high.length) +
F ((xs.take d0.num_digits.val).drop read.val) *
10 ^ high.length := by simp [hnsub, hdrop, F]
_ = B * (10 * F all) := hcombined
have hlowWrite : write1.val = low.length := by omega
have hlowCap : low.length <= 768 := by omega
have hwriteAll : write2.val = min all.length 768 := by
rw [hwrite2, hwrite1, hallLen, hlowLen]
have hwriteCap : write2.val <= 768 := by
rw [hwriteAll]
exact Nat.min_le_right _ _
have hwriteLen : write2.val <= all.length := by
rw [hwriteAll]
exact Nat.min_le_left _ _
let kept := all.take write2.val
let tail := all.drop write2.val
have hpreDigits :
(a2.val.take write2.val).map (fun z => z.val) = kept := by
simp only [kept, List.map_take]
apply List.ext_getElem
· simp [hwriteCap, hwriteLen, a2.property]
· intro j hj1 hj2
have hjm : j < write2.val := by
simpa [List.length_take, hwriteCap, a2.property] using hj1
have hj768 : j < 768 := by omega
by_cases hjlow : j < low.length
· have ha1 := hlowArray j hjlow
have ha2raw := hbelow2 j hj768 (by omega)
have ha2 :
(a2.val.map (fun z : Std.U8 => z.val))[j]? = low[j]? := by
rw [List.getElem?_map, ha2raw]
simpa [List.getElem?_map] using ha1
have hall : all[j]? = low[j]? := by
rw [List.getElem?_append_left (by simpa using hjlow)]
have hmapBound :
j < (a2.val.map (fun z : Std.U8 => z.val)).length := by
simp [a2.property]
exact hj768
have hallBound : j < all.length := by omega
rw [show ((a2.val.map (fun z : Std.U8 => z.val)).take
write2.val)[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j] by simp]
rw [show (all.take write2.val)[j] = all[j] by simp]
apply Option.some.inj
calc
some (a2.val.map (fun z : Std.U8 => z.val))[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j]? :=
(List.getElem?_eq_getElem hmapBound).symm
_ = low[j]? := ha2
_ = all[j]? := hall.symm
_ = some all[j] := List.getElem?_eq_getElem hallBound
· let t := j - low.length
have ht : t < high.length := by
simp only [t]
simp [all] at hj2
omega
have hjEq : write1.val + t = j := by
simp only [t]
omega
have ha2 := hhighArray t ht (by omega)
have hall : all[j]? = high[t]? := by
rw [List.getElem?_append_right (by simpa using hjlow)]
have hmapBound :
j < (a2.val.map (fun z : Std.U8 => z.val)).length := by
simp [a2.property]
exact hj768
have hallBound : j < all.length := by omega
rw [show ((a2.val.map (fun z : Std.U8 => z.val)).take
write2.val)[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j] by simp]
rw [show (all.take write2.val)[j] = all[j] by simp]
rw [hjEq] at ha2
apply Option.some.inj
calc
some (a2.val.map (fun z : Std.U8 => z.val))[j] =
(a2.val.map (fun z : Std.U8 => z.val))[j]? :=
(List.getElem?_eq_getElem hmapBound).symm
_ = high[t]? := ha2
_ = all[j]? := hall.symm
_ = some all[j] := List.getElem?_eq_getElem hallBound
have foldPos (ys : List Nat) :
0 < F ys <->
exists j, j < ys.length /\ ys[j]? != some 0 := by
induction ys with
| nil => simp [F]
| cons y ys ih =>
have hform : F (y :: ys) =
y * 10 ^ ys.length + F ys := by
simpa [F] using foldFrom2 ys y
rw [hform]
constructor
· intro hp
by_cases hy : y = 0
· have ht : 0 < F ys := by simpa [hy] using hp
rcases ih.mp ht with ⟨j, hj, hjnz⟩
exact ⟨j + 1, by simp; omega, by simpa using hjnz⟩
· exact ⟨0, by simp, by simp [hy]⟩
· rintro ⟨j, hj, hjnz⟩
cases j with
| zero =>
have hyne : y ≠ 0 := by
intro hy
subst y
simp at hjnz
have hy : 0 < y := Nat.pos_of_ne_zero hyne
have hpow : 0 < 10 ^ ys.length := by positivity
positivity
| succ j =>
have hjlt : j < ys.length := by simp at hj; omega
have ht : 0 < F ys :=
ih.mpr ⟨j, hjlt, by simpa using hjnz⟩
omega
have htailSticky :
(exists t, t < tail.length /\ tail[t]? != some 0) <->
(exists j, j < high.length /\
768 <= write1.val + j /\ high[j]? != some 0) := by
constructor
· rintro ⟨t, ht, htnz⟩
have ht' : t < all.length - write2.val := by
simpa [tail] using ht
have hwriteEq : write2.val = 768 := by
rw [hwriteAll]
omega
let g := write2.val + t
have hgall : g < all.length := by simp [g]; omega
have hglow : low.length <= g := by
simp [g, hwriteEq]
omega
let j := g - low.length
have hj : j < high.length := by
simp [all] at hgall
simp [j]
omega
have hdest : write1.val + j = g := by
rw [hlowWrite]
simp [j]
omega
have htailGet : tail[t]? = all[g]? := by
simp [tail, g, List.getElem?_drop]
have hallHigh : all[g]? = high[j]? := by
simp only [all, List.getElem?_append_right (by omega)]
simp [j]
refine ⟨j, hj, ?_, ?_⟩
· rw [hdest]
simp [g, hwriteEq]
· rw [htailGet, hallHigh] at htnz
exact htnz
· rintro ⟨j, hj, hjcap, hjnz⟩
let g := low.length + j
have hgall : g < all.length := by simp [g, all, hj]
have hdest : write1.val + j = g := by simp [g, hlowWrite]
have hgcap : 768 <= g := by simpa [hdest] using hjcap
have hwriteEq : write2.val = 768 := by
rw [hwriteAll]
omega
let t := g - write2.val
have ht : t < tail.length := by
simp [tail, t]
omega
have htailGet : tail[t]? = all[g]? := by
rw [List.getElem?_drop]
simp [t]
congr 1
omega
have hallHigh : all[g]? = high[j]? := by
simp only [all]
rw [List.getElem?_append_right (by simp [g])]
simp [g]
refine ⟨t, ht, ?_⟩
rw [htailGet, hallHigh]
exact hjnz
have decimalScale (I0 Q0 B0 extra0 L0 n0 : Nat)
(p0 point0 : Int) (hB0 : 0 < B0)
(hnum0 : I0 * 10 ^ extra0 = B0 * (10 * Q0))
(hexp0 : point0 - (L0 : Int) + (extra0 : Int) =
p0 - (n0 : Int) + 1) :
(Q0 : Real) * (10 : Real) ^ (point0 - (L0 : Int)) =
(I0 : Real) * (10 : Real) ^ (p0 - (n0 : Int)) /
(B0 : Real) := by
have hnumR : (I0 : Real) * (10 : Real) ^ extra0 =
(B0 : Real) * (10 * (Q0 : Real)) := by
exact_mod_cast hnum0
have h10 : (10 : Real) ≠ 0 := by norm_num
have hBR : (B0 : Real) ≠ 0 := by positivity
apply (eq_div_iff hBR).2
have hpows :
(10 : Real) ^ (point0 - (L0 : Int)) *
(10 : Real) ^ (extra0 : Int) =
(10 : Real) ^ (p0 - (n0 : Int) + 1) := by
rw [← zpow_add₀ h10, hexp0]
have hpowExtra : (10 : Real) ^ (extra0 : Int) =
(10 : Real) ^ extra0 := by
norm_num only [zpow_natCast]
have hp : (10 : Real) ^ (p0 - (n0 : Int) + 1) =
(10 : Real) ^ (p0 - (n0 : Int)) * 10 := by
rw [zpow_add₀ h10]
norm_num
calc
(Q0 : Real) * (10 : Real) ^ (point0 - (L0 : Int)) *
(B0 : Real) =
((B0 : Real) * (10 * (Q0 : Real))) / 10 *
(10 : Real) ^ (point0 - (L0 : Int)) := by ring
_ = ((I0 : Real) * (10 : Real) ^ extra0) / 10 *
(10 : Real) ^ (point0 - (L0 : Int)) := by
rw [hnumR]
_ = (I0 : Real) *
((10 : Real) ^ (point0 - (L0 : Int)) *
(10 : Real) ^ (extra0 : Int)) / 10 := by
rw [hpowExtra]
ring
_ = (I0 : Real) *
(10 : Real) ^ (p0 - (n0 : Int)) := by
rw [hpows, hp]
ring
have hexp : point.val - (all.length : Int) + (extra : Int) =
d0.decimal_point.val - (d0.num_digits.val : Int) + 1 := by
rw [hpointVal, hallLen, hlowLen]
simp only [extra, Nat.cast_add]
rcases hphase with hp | hp
· have hrsub : read.val - d0.num_digits.val = 0 :=
Nat.sub_eq_zero_of_le hp.1
rw [hrsub]
simp
rw [Nat.cast_sub hp.1]
omega
· have hnle : d0.num_digits.val <= read.val := by omega
have hnsub : d0.num_digits.val - read.val = 0 :=
Nat.sub_eq_zero_of_le hnle
rw [hnsub]
simp
rw [Nat.cast_sub hnle]
omega
have hBpos : 0 < B := by simp [B]
have hfullValue :
(F all : Real) *
(10 : Real) ^ (point.val - (all.length : Int)) =
(I : Real) * (10 : Real) ^
(d0.decimal_point.val -
(d0.num_digits.val : Int)) / (B : Real) :=
decimalScale I (F all) B extra all.length
d0.num_digits.val d0.decimal_point.val point.val hBpos
hterminal hexp
have capSplit (ys : List Nat) (m : Nat) (p0 : Int)
(hm : m <= ys.length) :
(F ys : Real) *
(10 : Real) ^ (p0 - (ys.length : Int)) =
(F (ys.take m) : Real) *
(10 : Real) ^ (p0 - (m : Int)) +
(F (ys.drop m) : Real) *
(10 : Real) ^ (p0 - (ys.length : Int)) := by
have hfold : F ys = F (ys.take m) * 10 ^ (ys.length - m) +
F (ys.drop m) := by
conv_lhs => rw [← List.take_append_drop m ys]
simp only [F, List.foldl_append]
rw [foldFrom2]
congr 2
simp
have hexp' : p0 - (m : Int) =
(p0 - (ys.length : Int)) +
((ys.length - m : Nat) : Int) := by
rw [Nat.cast_sub hm]
omega
have hpow : (10 : Real) ^ (p0 - (m : Int)) =
(10 : Real) ^ (p0 - (ys.length : Int)) *
(10 : Real) ^ (ys.length - m) := by
rw [hexp', zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
norm_num only [zpow_natCast]
rw [show (F ys : Real) =
(F (ys.take m) : Real) *
(10 : Real) ^ (ys.length - m) +
(F (ys.drop m) : Real) by exact_mod_cast hfold]
rw [hpow]
ring
have hcapSplit :
(F all : Real) *
(10 : Real) ^ (point.val - (all.length : Int)) =
(F kept : Real) *
(10 : Real) ^ (point.val - (write2.val : Int)) +
(F tail : Real) *
(10 : Real) ^ (point.val - (all.length : Int)) := by
simpa [kept, tail] using
capSplit all write2.val point.val hwriteLen
let rho : Real := (F tail : Real) *
(10 : Real) ^ (point.val - (all.length : Int))
have hrho0 : 0 <= rho := by
dsimp only [rho]
exact mul_nonneg (Nat.cast_nonneg _) (le_of_lt
(zpow_pos (by norm_num : (0 : Real) < 10) _))
have hrhoPos : 0 < rho <-> 0 < F tail := by
dsimp only [rho]
have hp : 0 < (10 : Real) ^
(point.val - (all.length : Int)) :=
zpow_pos (by norm_num) _
constructor
· intro h
have : 0 < (F tail : Real) := by nlinarith
exact_mod_cast this
· intro h
have hc : 0 < (F tail : Real) := by exact_mod_cast h
positivity
have hrhoSticky :
0 < rho <->
exists j, j < high.length /\
768 <= write1.val + j /\ high[j]? != some 0 := by
rw [hrhoPos, foldPos, htailSticky]
have foldBound (ys : List Nat)
(hd : forall z, z ∈ ys -> z < 10) :
F ys < 10 ^ ys.length := by
induction ys with
| nil => simp [F]
| cons y ys ih =>
have hy : y < 10 := hd y (by simp)
have hys : forall z, z ∈ ys -> z < 10 := by
intro z hz
exact hd z (by simp [hz])
have hi := ih hys
rw [show F (y :: ys) =
y * 10 ^ ys.length + F ys by
simpa [F] using foldFrom2 ys y,
List.length_cons, pow_succ]
have hmul : y * 10 ^ ys.length <=
9 * 10 ^ ys.length :=
Nat.mul_le_mul_right _ (by omega)
calc
y * 10 ^ ys.length + F ys <
y * 10 ^ ys.length + 10 ^ ys.length :=
Nat.add_lt_add_left hi _
_ <= 9 * 10 ^ ys.length + 10 ^ ys.length :=
Nat.add_le_add_right hmul _
_ = 10 ^ ys.length * 10 := by ring
have htailDigit : forall z, z ∈ tail -> z < 10 := by
intro z hz
exact hallDigit z (List.mem_of_mem_drop hz)
have htailBound : F tail < 10 ^ tail.length :=
foldBound tail htailDigit
let pre : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := write2, decimal_point := point,
truncated := b2, digits := a2 }
have htrim :
num.imp.dec2flt.decimal_seq.DecimalSeq.trim pre = ok d' := by
simpa [pre] using hcall
have hpreBound : pre.num_digits.val <= pre.digits.val.length := by
simp [pre, a2.property]
exact hwriteCap
have htrimSem := DecimalSeqTrimSemantics pre d' hpreBound htrim
dsimp only at htrimSem
rcases htrimSem with
⟨_, hpointTrim, htrunc, _, _, _, htrimValue⟩
have hrhoCell :
rho < (10 : Real) ^ (d'.decimal_point.val - 768) := by
by_cases htailZero : F tail = 0
· simp only [rho, htailZero, Nat.cast_zero, zero_mul]
exact zpow_pos (by norm_num) _
· have htailPos : 0 < F tail := Nat.pos_of_ne_zero htailZero
have htailNonempty : 0 < tail.length := by
by_contra hlen
have : tail = [] := List.eq_nil_of_length_eq_zero (by omega)
simp [this, F] at htailPos
have hwriteEq : write2.val = 768 := by
simp [tail] at htailNonempty
rw [Nat.min_def] at hwriteAll
split at hwriteAll
· omega
· omega
have hexpCell :
point.val - (all.length : Int) +
(tail.length : Int) =
d'.decimal_point.val - 768 := by
rw [show tail.length = all.length - write2.val by
simp [tail]]
rw [Nat.cast_sub hwriteLen, hwriteEq]
rw [hpointTrim]
simp only [pre]
omega
have hcastBound :
(F tail : Real) < (10 : Real) ^ tail.length := by
exact_mod_cast htailBound
have hscalePos : 0 < (10 : Real) ^
(point.val - (all.length : Int)) :=
zpow_pos (by norm_num) _
calc
rho = (F tail : Real) * (10 : Real) ^
(point.val - (all.length : Int)) := rfl
_ < (10 : Real) ^ tail.length * (10 : Real) ^
(point.val - (all.length : Int)) :=
mul_lt_mul_of_pos_right hcastBound hscalePos
_ = (10 : Real) ^
(d'.decimal_point.val - 768) := by
norm_num only [← zpow_natCast]
rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
rw [add_comm, hexpCell]
right
refine ⟨rho, hrho0, hrhoCell, ?_, ?_⟩
· rw [htrimValue]
simp only [pre]
rw [hpreDigits]
have hOrigFold :
((d0.digits.val.take d0.num_digits.val).map
(fun z => z.val)).foldl
(fun n z => 10 * n + z) 0 = I := by
simp [I, F, xs, List.map_take]
rw [hOrigFold]
change (F kept : Real) *
(10 : Real) ^ (point.val - (write2.val : Int)) =
(I : Real) * (10 : Real) ^
(d0.decimal_point.val -
(d0.num_digits.val : Int)) /
(2 : Real) ^ shift.val - rho
have hBReal : (B : Real) = (2 : Real) ^ shift.val := by
simp [B]
rw [← hBReal, ← hfullValue]
rw [hcapSplit]
simp [rho]
· rw [htrunc, hsticky2, hrhoSticky]
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalRightShiftU64DyadicBridge
- DecimalSeqTrimSemantics
- ResultLoopPartial
All 10 entries
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalRightShiftU64DyadicBridge
- DecimalSeqTrimSemantics
- ResultLoopPartial
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq DECIMAL POINT RANGE
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
- num imp dec2flt decimal seq DecimalSeq right shift
Inspect related source (116)
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:67 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:63 Program Rust
More program dependencies (83)
- right_shift · dec2flt/decimal_seq.rs:175 Program Rust
- right_shift_loop0 · dec2flt/decimal_seq.rs:180 Program Rust
- body · dec2flt/decimal_seq.rs:180 Program Rust
- right_shift_loop0_loop0 · dec2flt/decimal_seq.rs:190 Program Rust
- body · dec2flt/decimal_seq.rs:190 Program Rust
- right_shift_loop1 · dec2flt/decimal_seq.rs:209 Program Rust
- body · dec2flt/decimal_seq.rs:209 Program Rust
- right_shift_loop2 · dec2flt/decimal_seq.rs:216 Program Rust
- body · dec2flt/decimal_seq.rs:216 Program Rust
- trim · dec2flt/decimal_seq.rs:82 Program Rust
- trim_loop · dec2flt/decimal_seq.rs:91 Program Rust
- body · dec2flt/decimal_seq.rs:91 Program Rust
- parse_long_mantissa · dec2flt/slow.rs:27 Program Rust
- parse_long_mantissa_loop0 · dec2flt/slow.rs:51 Program Rust
- body · dec2flt/slow.rs:51 Program Rust
- parse_long_mantissa_loop1 · dec2flt/slow.rs:69 Program Rust
- body · dec2flt/slow.rs:69 Program Rust
- parse_long_mantissa_loop2 · dec2flt/slow.rs:94 Program Rust
- body · dec2flt/slow.rs:94 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
- zero_pow2 · dec2flt/common.rs:62 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- left_shift · dec2flt/decimal_seq.rs:129 Program Rust
- left_shift_loop0 · dec2flt/decimal_seq.rs:138 Program Rust
- body · dec2flt/decimal_seq.rs:138 Program Rust
- left_shift_loop1 · dec2flt/decimal_seq.rs:152 Program Rust
- body · dec2flt/decimal_seq.rs:152 Program Rust
- round · dec2flt/decimal_seq.rs:96 Program Rust
- round_loop · dec2flt/decimal_seq.rs:106 Program Rust
- body · dec2flt/decimal_seq.rs:106 Program Rust
- 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
- 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
- MAX_SHIFT · dec2flt/slow.rs:28 Program Rust
- call · dec2flt/slow.rs:33 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
- read_u64 · dec2flt/common.rs:18 Program Rust
- write_u64 · dec2flt/common.rs:25 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
- default · dec2flt/decimal_seq.rs:33 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:66 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
- number_of_digits_decimal_left_shift · dec2flt/decimal_seq.rs:368 Program Rust
- number_of_digits_decimal_left_shift_loop · dec2flt/decimal_seq.rs:434 Program Rust
- body · dec2flt/decimal_seq.rs:434 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
- 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
- NUM_POWERS · dec2flt/slow.rs:29 Program Rust
- POWERS · dec2flt/slow.rs:30 Program Rust
- closure · dec2flt/slow.rs:33 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:73 Program Rust
- TABLE · dec2flt/decimal_seq.rs:370 Program Rust
- TABLE_POW5 · dec2flt/decimal_seq.rs:379 Program Rust
Standard-library dependencies (30)
- bitand · core/src/ops/bit.rs:178 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- 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
- bitor · core/src/ops/bit.rs:282 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
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalRightShiftU64DyadicBridge
- DecimalSeqRightShiftRecordSemantics
- DecimalSeqTrimSemantics
All 12 entries
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalRightShiftU64DyadicBridge
- DecimalSeqRightShiftRecordSemantics
- DecimalSeqTrimSemantics
- ResultLoopPartial
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq DECIMAL POINT RANGE
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
- num imp dec2flt decimal seq DecimalSeq right shift
- num imp dec2flt decimal seq DecimalSeq trim
Technical checking records
Local closure summary
{
"node": "DecimalSeqRightShiftRecordSemantics",
"closure_version": "patch_c_v1",
"active_decl_hash": "b4817e2753d0bdeb8e231eef8e5ad2a8f217c46ee88fba87ed8d76ab986950e8",
"active_statement_hash": "142a2960d3006c1adca23ea0e34c1c25b546c5154a9c2ecfc299b21b15c7218f",
"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": "revalidate-cycle-188",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalRightShiftFinalLoopSemantics": "79a214a5ee500eac",
"DecimalRightShiftMainLoopSemantics": "647cdcc98ff47e21",
"DecimalRightShiftPrefixLoopSemantics": "0d5cb25f18eedbfb",
"DecimalSeqTrimSemantics": "e4b2cbb62f7171af",
"num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "0eb6fb2627d0ff5c"
},
"strict_definition_deps": {
"num_imp_dec2flt_decimal_seq_DecimalSeq": "6799fe6525ddb761",
"num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "0cc5155758bc976a",
"num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "c3a2fd15a88a3d38",
"num_imp_dec2flt_decimal_seq_DecimalSeq_trim": "faa9fd92b8c29c14"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "differs from current fingerprint",
"assessment_fingerprint": "sound-v2:489005e88e2eb403dffac908f15b1a78af8ed7c00754c1e30055e4d8da93e10c",
"current_fingerprint": "sound-v2:d717858529d457e10eba5e1e5611b591e34d460ba72e88023479af7f54b122b9",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}