Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Helper · Exact semantics of the final decimal right-shift output loop
right_shift_loop2, started with Boolean b,
array a, shift k, cursor w, accumulator c, and mask m, returns
Boolean b', array a', and cursor w', then there is a finite list Z
of natural decimal digits. Writing
F(L)=\operatorname{fold}_{10}(L), it satisfies
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalRightShiftU64DyadicBridge
import Tablet.ResultLoopPartial
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: DecimalRightShiftFinalLoopSemantics]
theorem DecimalRightShiftFinalLoopSemantics
(a a' : Array Std.U8 768#usize) (b b' : Bool)
(shift write write' : Std.Usize) (pow mask acc : Std.U64)
(hshift : shift.val <= 60)
(hwrite : write.val <= 768)
(hacc : acc.val < 10 * 2 ^ shift.val)
(hpow : 1#u64 <<< shift = ok pow)
(hmask : pow - 1#u64 = ok mask)
(hloop :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
b a shift write acc mask = ok (b', a', write')) :
let F := fun ys : List Nat => ys.foldl (fun n z => 10 * n + z) 0
let B := 2 ^ shift.val
exists zs : List Nat,
(forall z, z ∈ zs -> z < 10) /\
acc.val * 10 ^ zs.length = B * (10 * F zs) /\
write'.val = min (write.val + zs.length) 768 /\
(forall j, j < zs.length -> write.val + j < 768 ->
(a'.val.map (fun z : Std.U8 => z.val))[write.val + j]? = zs[j]?) /\
(forall j, j < 768 -> j < write.val -> a'.val[j]? = a.val[j]?) /\
(forall j, j < 768 -> write'.val <= j -> a'.val[j]? = a.val[j]?) /\
(b' = true <-> b = true \/
exists j, j < zs.length /\ 768 <= write.val + j /\
zs[j]? != some 0) := 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
let F := fun ys : List Nat => ys.foldl (fun n z => 10 * n + z) 0
let B := 2 ^ shift.val
have hBpos : 0 < B := by simp [B]
let Inv := fun (x : Bool × Array Std.U8 768#usize × Std.Usize × Std.U64) =>
let (bc, ac, w, c) := x
c.val < 10 * B /\
exists zs : List Nat,
(forall z, z ∈ zs -> z < 10) /\
acc.val * 10 ^ zs.length = B * (10 * F zs) + c.val /\
w.val = min (write.val + zs.length) 768 /\
(forall j, j < zs.length -> write.val + j < 768 ->
(ac.val.map (fun z : Std.U8 => z.val))[write.val + j]? = zs[j]?) /\
(forall j, j < 768 -> j < write.val -> ac.val[j]? = a.val[j]?) /\
(forall j, j < 768 -> w.val <= j -> ac.val[j]? = a.val[j]?) /\
(bc = true <-> b = true \/
exists j, j < zs.length /\ 768 <= write.val + j /\
zs[j]? != some 0)
let Post := fun (x : Bool × Array Std.U8 768#usize × Std.Usize) =>
let (bc, ac, w) := x
exists zs : List Nat,
(forall z, z ∈ zs -> z < 10) /\
acc.val * 10 ^ zs.length = B * (10 * F zs) /\
w.val = min (write.val + zs.length) 768 /\
(forall j, j < zs.length -> write.val + j < 768 ->
(ac.val.map (fun z : Std.U8 => z.val))[write.val + j]? = zs[j]?) /\
(forall j, j < 768 -> j < write.val -> ac.val[j]? = a.val[j]?) /\
(forall j, j < 768 -> w.val <= j -> ac.val[j]? = a.val[j]?) /\
(bc = true <-> b = true \/
exists j, j < zs.length /\ 768 <= write.val + j /\
zs[j]? != some 0)
let Body := fun (x : Bool × Array Std.U8 768#usize × Std.Usize × Std.U64) =>
let (bc, ac, w, c) := x
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body
shift mask bc ac w c
have hp : Post (b', a', write') := by
refine ResultLoopPartial Inv Post Body ?_ (b, a, write, acc)
(b', a', write') ?_ ?_
· intro x hx out hout
rcases x with ⟨bc, ac, w, c⟩
simp only [Inv] at hx
rcases hx with ⟨hc10, zs, hzsdigit, hnum, hw, harr, hbelow, houtside,
hsticky⟩
simp only [Body,
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body] at hout
by_cases hc0 : c.val = 0
· have hcEq : c = 0#u64 := UScalar.eq_of_val_eq (by simpa using hc0)
have hnotgt : ¬ c > 0#u64 := by simp [hcEq]
simp [hnotgt] at hout
subst out
simp only [Post]
refine ⟨zs, hzsdigit, ?_, hw, harr, hbelow, houtside, hsticky⟩
simpa [hc0] using hnum
· have hcpos : 0 < c.val := by omega
have hgt : c > 0#u64 := by
change 0 < c.val
exact hcpos
simp only [hgt, if_true] at hout
obtain ⟨q, hq, hqSpec⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.ShiftRight_spec c shift (by
norm_num [U64.numBits]
omega))
rw [hq] at hout
simp only [bind_tc_ok, lift] at hout
let newDigit : Std.U8 := UScalar.cast .U8 q
rw [show UScalar.cast .U8 q = newDigit by rfl] at hout
let rem : Std.U64 := c &&& mask
rw [show c &&& mask = rem by rfl] at hout
have hbridge := DecimalRightShiftU64DyadicBridge shift c pow mask q rem
hshift hpow hmask hq (by rfl)
simp only [B] at hbridge
rcases hbridge with ⟨_, _, hqVal, hremVal, heuc, hremB, _, hbound⟩
have hq10 : q.val < 10 := by
rw [hqVal]
exact (Nat.div_lt_iff_lt_mul hBpos).2 (by
simpa [Nat.mul_comm] using hc10)
have hnewDigitVal : newDigit.val = q.val := by
simp [newDigit, UScalar.cast_val_eq,
Nat.mod_eq_of_lt (by omega : q.val < 256)]
have hmulBound : 10 * rem.val <= U64.max := by
have hlt := hbound 0 (by omega)
norm_num [U64.max, U64.numBits] at hlt ⊢
omega
obtain ⟨c1, hc1, hc1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(U64.mul_spec (x := 10#u64) (y := rem) (by simpa using hmulBound))
rw [hc1] at hout
simp only [bind_tc_ok] at hout
have hc1Exact : c1.val = 10 * rem.val := by simpa using hc1Val
have hc1ten : c1.val < 10 * B := by rw [hc1Exact]; omega
let newZs := zs ++ [q.val]
have hnewLen : newZs.length = zs.length + 1 := by simp [newZs]
have hnewDigit : forall z, z ∈ newZs -> z < 10 := by
intro z hz
simp only [newZs, List.mem_append, List.mem_singleton] at hz
rcases hz with hz | rfl
· exact hzsdigit z hz
· exact hq10
have hnewFold : F newZs = 10 * F zs + q.val := by
simp [newZs, F]
have hnumNew :
acc.val * 10 ^ newZs.length =
B * (10 * F newZs) + c1.val := by
rw [hnewLen, pow_succ, hnewFold, hc1Exact]
calc
acc.val * (10 ^ zs.length * 10) =
(acc.val * 10 ^ zs.length) * 10 := by ring
_ = (B * (10 * F zs) + c.val) * 10 := by rw [hnum]
_ = B * (10 * (10 * F zs + q.val)) + 10 * rem.val := by
rw [heuc]
ring
by_cases hcap : w.val < 768
· have hcapWord : w <
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
UScalar.lt_equiv] using hcap
simp only [hcapWord, if_true] at hout
have hwArray : w.val < ac.val.length := by
rw [ac.property]
exact hcap
obtain ⟨ac1, hac1, hac1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(Array.update_spec ac w newDigit
(by simpa [Array.length] using hwArray))
rw [hac1] at hout
simp only [bind_tc_ok] at hout
have hwBound : w.val + 1 <= Usize.max := by
simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨w1, hw1, hw1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(Usize.add_spec (x := w) (y := 1#usize) (by simpa using hwBound))
rw [hw1] at hout
simp only [bind_tc_ok] at hout
cases hout
simp only [Inv]
have hwExact : w.val = write.val + zs.length := by
rw [hw] at hcap
rw [Nat.min_eq_left (by omega : write.val + zs.length <= 768)] at hw
exact hw
have hw1Exact : w1.val = w.val + 1 := by simpa using hw1Val
have hcursor : w1.val = min (write.val + newZs.length) 768 := by
rw [hw1Exact, hwExact, hnewLen]
rw [Nat.min_eq_left (by omega)]
omega
refine ⟨hc1ten, newZs, hnewDigit, hnumNew, hcursor, ?_, ?_, ?_, ?_⟩
· intro j hj hjphys
rw [hac1Val]
simp only [Aeneas.Std.Array.set, List.map_set, List.getElem?_set]
by_cases hjold : j < zs.length
· have hne : w.val ≠ write.val + j := by omega
simp only [hne, if_false]
rw [List.getElem?_append_left (by simpa using hjold)]
exact harr j hjold hjphys
· have hjlast : j = zs.length := by
simp [newZs] at hj
omega
subst j
simpa [hwExact, newZs, hnewDigitVal] using hjphys
· intro j hj hjwrite
rw [hac1Val]
simp only [Aeneas.Std.Array.set, List.getElem?_set]
have hne : w.val ≠ j := by omega
simp [hne]
exact hbelow j hj hjwrite
· intro j hj hw1j
rw [hac1Val]
simp only [Aeneas.Std.Array.set, List.getElem?_set]
have hne : w.val ≠ j := by omega
simp [hne]
exact houtside j hj (by omega)
· constructor
· intro htrue
rcases hsticky.mp htrue with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
refine ⟨j, by simpa [newZs] using Nat.lt_succ_of_lt hj, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hj)]
exact hjnz
· intro h
apply hsticky.mpr
rcases h with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
omega
refine ⟨j, hjold, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hjold)] at hjnz
exact hjnz
· have hcapWord : ¬ w <
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
UScalar.lt_equiv] using hcap
simp only [hcapWord, if_false] at hout
have hwCap : w.val = 768 := by
rw [hw]
exact Nat.min_eq_right (by omega)
have hdestCap : 768 <= write.val + zs.length := by
rw [hw] at hwCap
omega
have hcursor : w.val = min (write.val + newZs.length) 768 := by
rw [hwCap, Nat.min_eq_right]
rw [hnewLen]
omega
by_cases hq0 : q.val = 0
· have hnewDigitEq : newDigit = 0#u8 :=
UScalar.eq_of_val_eq (by simpa [hnewDigitVal] using hq0)
have hnotgt : ¬ newDigit > 0#u8 := by simp [hnewDigitEq]
simp [hnotgt] at hout
subst out
simp only [Inv]
refine ⟨hc1ten, newZs, hnewDigit, hnumNew, hcursor, ?_, hbelow,
?_, ?_⟩
· intro j hj hjphys
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
omega
rw [List.getElem?_append_left (by simpa using hjold)]
exact harr j hjold hjphys
· intro j hj hwj
exact houtside j hj hwj
· constructor
· intro htrue
rcases hsticky.mp htrue with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
refine ⟨j, by simpa [newZs] using Nat.lt_succ_of_lt hj, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hj)]
exact hjnz
· intro h
apply hsticky.mpr
rcases h with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
simp [newZs, hq0] at hjnz
refine ⟨j, hjold, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hjold)] at hjnz
exact hjnz
· have hgtDigit : newDigit > 0#u8 := by
change 0 < newDigit.val
rw [hnewDigitVal]
omega
simp [hgtDigit] at hout
subst out
simp only [Inv]
refine ⟨hc1ten, newZs, hnewDigit, hnumNew, hcursor, ?_, hbelow,
?_, ?_⟩
· intro j hj hjphys
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
omega
rw [List.getElem?_append_left (by simpa using hjold)]
exact harr j hjold hjphys
· intro j hj hwj
exact houtside j hj hwj
· constructor
· intro _
right
refine ⟨zs.length, by simp [newZs], hdestCap, ?_⟩
simp [newZs, hq0]
· intro _
trivial
· simp only [Inv]
refine ⟨hacc, [], ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
· simp
· simp [F]
· simp [Nat.min_eq_left hwrite]
· intro j hj
simp at hj
· intro j hj hjwrite
trivial
· intro j hj hwj
trivial
· simp
· exact hloop
simpa [Post, F, B] using hp
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.DecimalRightShiftU64DyadicBridge
import Tablet.ResultLoopPartial
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: DecimalRightShiftFinalLoopSemantics]
theorem DecimalRightShiftFinalLoopSemantics
(a a' : Array Std.U8 768#usize) (b b' : Bool)
(shift write write' : Std.Usize) (pow mask acc : Std.U64)
(hshift : shift.val <= 60)
(hwrite : write.val <= 768)
(hacc : acc.val < 10 * 2 ^ shift.val)
(hpow : 1#u64 <<< shift = ok pow)
(hmask : pow - 1#u64 = ok mask)
(hloop :
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
b a shift write acc mask = ok (b', a', write')) :
let F := fun ys : List Nat => ys.foldl (fun n z => 10 * n + z) 0
let B := 2 ^ shift.val
exists zs : List Nat,
(forall z, z ∈ zs -> z < 10) /\
acc.val * 10 ^ zs.length = B * (10 * F zs) /\
write'.val = min (write.val + zs.length) 768 /\
(forall j, j < zs.length -> write.val + j < 768 ->
(a'.val.map (fun z : Std.U8 => z.val))[write.val + j]? = zs[j]?) /\
(forall j, j < 768 -> j < write.val -> a'.val[j]? = a.val[j]?) /\
(forall j, j < 768 -> write'.val <= j -> a'.val[j]? = a.val[j]?) /\
(b' = true <-> b = true \/
exists j, j < zs.length /\ 768 <= write.val + j /\
zs[j]? != some 0) := by
-- BODY
dsimp only
let F := fun ys : List Nat => ys.foldl (fun n z => 10 * n + z) 0
let B := 2 ^ shift.val
have hBpos : 0 < B := by simp [B]
let Inv := fun (x : Bool × Array Std.U8 768#usize × Std.Usize × Std.U64) =>
let (bc, ac, w, c) := x
c.val < 10 * B /\
exists zs : List Nat,
(forall z, z ∈ zs -> z < 10) /\
acc.val * 10 ^ zs.length = B * (10 * F zs) + c.val /\
w.val = min (write.val + zs.length) 768 /\
(forall j, j < zs.length -> write.val + j < 768 ->
(ac.val.map (fun z : Std.U8 => z.val))[write.val + j]? = zs[j]?) /\
(forall j, j < 768 -> j < write.val -> ac.val[j]? = a.val[j]?) /\
(forall j, j < 768 -> w.val <= j -> ac.val[j]? = a.val[j]?) /\
(bc = true <-> b = true \/
exists j, j < zs.length /\ 768 <= write.val + j /\
zs[j]? != some 0)
let Post := fun (x : Bool × Array Std.U8 768#usize × Std.Usize) =>
let (bc, ac, w) := x
exists zs : List Nat,
(forall z, z ∈ zs -> z < 10) /\
acc.val * 10 ^ zs.length = B * (10 * F zs) /\
w.val = min (write.val + zs.length) 768 /\
(forall j, j < zs.length -> write.val + j < 768 ->
(ac.val.map (fun z : Std.U8 => z.val))[write.val + j]? = zs[j]?) /\
(forall j, j < 768 -> j < write.val -> ac.val[j]? = a.val[j]?) /\
(forall j, j < 768 -> w.val <= j -> ac.val[j]? = a.val[j]?) /\
(bc = true <-> b = true \/
exists j, j < zs.length /\ 768 <= write.val + j /\
zs[j]? != some 0)
let Body := fun (x : Bool × Array Std.U8 768#usize × Std.Usize × Std.U64) =>
let (bc, ac, w, c) := x
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body
shift mask bc ac w c
have hp : Post (b', a', write') := by
refine ResultLoopPartial Inv Post Body ?_ (b, a, write, acc)
(b', a', write') ?_ ?_
· intro x hx out hout
rcases x with ⟨bc, ac, w, c⟩
simp only [Inv] at hx
rcases hx with ⟨hc10, zs, hzsdigit, hnum, hw, harr, hbelow, houtside,
hsticky⟩
simp only [Body,
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body] at hout
by_cases hc0 : c.val = 0
· have hcEq : c = 0#u64 := UScalar.eq_of_val_eq (by simpa using hc0)
have hnotgt : ¬ c > 0#u64 := by simp [hcEq]
simp [hnotgt] at hout
subst out
simp only [Post]
refine ⟨zs, hzsdigit, ?_, hw, harr, hbelow, houtside, hsticky⟩
simpa [hc0] using hnum
· have hcpos : 0 < c.val := by omega
have hgt : c > 0#u64 := by
change 0 < c.val
exact hcpos
simp only [hgt, if_true] at hout
obtain ⟨q, hq, hqSpec⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.ShiftRight_spec c shift (by
norm_num [U64.numBits]
omega))
rw [hq] at hout
simp only [bind_tc_ok, lift] at hout
let newDigit : Std.U8 := UScalar.cast .U8 q
rw [show UScalar.cast .U8 q = newDigit by rfl] at hout
let rem : Std.U64 := c &&& mask
rw [show c &&& mask = rem by rfl] at hout
have hbridge := DecimalRightShiftU64DyadicBridge shift c pow mask q rem
hshift hpow hmask hq (by rfl)
simp only [B] at hbridge
rcases hbridge with ⟨_, _, hqVal, hremVal, heuc, hremB, _, hbound⟩
have hq10 : q.val < 10 := by
rw [hqVal]
exact (Nat.div_lt_iff_lt_mul hBpos).2 (by
simpa [Nat.mul_comm] using hc10)
have hnewDigitVal : newDigit.val = q.val := by
simp [newDigit, UScalar.cast_val_eq,
Nat.mod_eq_of_lt (by omega : q.val < 256)]
have hmulBound : 10 * rem.val <= U64.max := by
have hlt := hbound 0 (by omega)
norm_num [U64.max, U64.numBits] at hlt ⊢
omega
obtain ⟨c1, hc1, hc1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(U64.mul_spec (x := 10#u64) (y := rem) (by simpa using hmulBound))
rw [hc1] at hout
simp only [bind_tc_ok] at hout
have hc1Exact : c1.val = 10 * rem.val := by simpa using hc1Val
have hc1ten : c1.val < 10 * B := by rw [hc1Exact]; omega
let newZs := zs ++ [q.val]
have hnewLen : newZs.length = zs.length + 1 := by simp [newZs]
have hnewDigit : forall z, z ∈ newZs -> z < 10 := by
intro z hz
simp only [newZs, List.mem_append, List.mem_singleton] at hz
rcases hz with hz | rfl
· exact hzsdigit z hz
· exact hq10
have hnewFold : F newZs = 10 * F zs + q.val := by
simp [newZs, F]
have hnumNew :
acc.val * 10 ^ newZs.length =
B * (10 * F newZs) + c1.val := by
rw [hnewLen, pow_succ, hnewFold, hc1Exact]
calc
acc.val * (10 ^ zs.length * 10) =
(acc.val * 10 ^ zs.length) * 10 := by ring
_ = (B * (10 * F zs) + c.val) * 10 := by rw [hnum]
_ = B * (10 * (10 * F zs + q.val)) + 10 * rem.val := by
rw [heuc]
ring
by_cases hcap : w.val < 768
· have hcapWord : w <
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
UScalar.lt_equiv] using hcap
simp only [hcapWord, if_true] at hout
have hwArray : w.val < ac.val.length := by
rw [ac.property]
exact hcap
obtain ⟨ac1, hac1, hac1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(Array.update_spec ac w newDigit
(by simpa [Array.length] using hwArray))
rw [hac1] at hout
simp only [bind_tc_ok] at hout
have hwBound : w.val + 1 <= Usize.max := by
simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨w1, hw1, hw1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(Usize.add_spec (x := w) (y := 1#usize) (by simpa using hwBound))
rw [hw1] at hout
simp only [bind_tc_ok] at hout
cases hout
simp only [Inv]
have hwExact : w.val = write.val + zs.length := by
rw [hw] at hcap
rw [Nat.min_eq_left (by omega : write.val + zs.length <= 768)] at hw
exact hw
have hw1Exact : w1.val = w.val + 1 := by simpa using hw1Val
have hcursor : w1.val = min (write.val + newZs.length) 768 := by
rw [hw1Exact, hwExact, hnewLen]
rw [Nat.min_eq_left (by omega)]
omega
refine ⟨hc1ten, newZs, hnewDigit, hnumNew, hcursor, ?_, ?_, ?_, ?_⟩
· intro j hj hjphys
rw [hac1Val]
simp only [Aeneas.Std.Array.set, List.map_set, List.getElem?_set]
by_cases hjold : j < zs.length
· have hne : w.val ≠ write.val + j := by omega
simp only [hne, if_false]
rw [List.getElem?_append_left (by simpa using hjold)]
exact harr j hjold hjphys
· have hjlast : j = zs.length := by
simp [newZs] at hj
omega
subst j
simpa [hwExact, newZs, hnewDigitVal] using hjphys
· intro j hj hjwrite
rw [hac1Val]
simp only [Aeneas.Std.Array.set, List.getElem?_set]
have hne : w.val ≠ j := by omega
simp [hne]
exact hbelow j hj hjwrite
· intro j hj hw1j
rw [hac1Val]
simp only [Aeneas.Std.Array.set, List.getElem?_set]
have hne : w.val ≠ j := by omega
simp [hne]
exact houtside j hj (by omega)
· constructor
· intro htrue
rcases hsticky.mp htrue with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
refine ⟨j, by simpa [newZs] using Nat.lt_succ_of_lt hj, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hj)]
exact hjnz
· intro h
apply hsticky.mpr
rcases h with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
omega
refine ⟨j, hjold, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hjold)] at hjnz
exact hjnz
· have hcapWord : ¬ w <
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
UScalar.lt_equiv] using hcap
simp only [hcapWord, if_false] at hout
have hwCap : w.val = 768 := by
rw [hw]
exact Nat.min_eq_right (by omega)
have hdestCap : 768 <= write.val + zs.length := by
rw [hw] at hwCap
omega
have hcursor : w.val = min (write.val + newZs.length) 768 := by
rw [hwCap, Nat.min_eq_right]
rw [hnewLen]
omega
by_cases hq0 : q.val = 0
· have hnewDigitEq : newDigit = 0#u8 :=
UScalar.eq_of_val_eq (by simpa [hnewDigitVal] using hq0)
have hnotgt : ¬ newDigit > 0#u8 := by simp [hnewDigitEq]
simp [hnotgt] at hout
subst out
simp only [Inv]
refine ⟨hc1ten, newZs, hnewDigit, hnumNew, hcursor, ?_, hbelow,
?_, ?_⟩
· intro j hj hjphys
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
omega
rw [List.getElem?_append_left (by simpa using hjold)]
exact harr j hjold hjphys
· intro j hj hwj
exact houtside j hj hwj
· constructor
· intro htrue
rcases hsticky.mp htrue with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
refine ⟨j, by simpa [newZs] using Nat.lt_succ_of_lt hj, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hj)]
exact hjnz
· intro h
apply hsticky.mpr
rcases h with hbtrue | ⟨j, hj, hjcap, hjnz⟩
· exact Or.inl hbtrue
· right
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
simp [newZs, hq0] at hjnz
refine ⟨j, hjold, hjcap, ?_⟩
rw [List.getElem?_append_left (by simpa using hjold)] at hjnz
exact hjnz
· have hgtDigit : newDigit > 0#u8 := by
change 0 < newDigit.val
rw [hnewDigitVal]
omega
simp [hgtDigit] at hout
subst out
simp only [Inv]
refine ⟨hc1ten, newZs, hnewDigit, hnumNew, hcursor, ?_, hbelow,
?_, ?_⟩
· intro j hj hjphys
have hjold : j < zs.length := by
by_contra hn
have : j = zs.length := by simp [newZs] at hj; omega
subst j
omega
rw [List.getElem?_append_left (by simpa using hjold)]
exact harr j hjold hjphys
· intro j hj hwj
exact houtside j hj hwj
· constructor
· intro _
right
refine ⟨zs.length, by simp [newZs], hdestCap, ?_⟩
simp [newZs, hq0]
· intro _
trivial
· simp only [Inv]
refine ⟨hacc, [], ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
· simp
· simp [F]
· simp [Nat.min_eq_left hwrite]
· intro j hj
simp at hj
· intro j hj hjwrite
trivial
· intro j hj hwj
trivial
· simp
· exact hloop
simpa [Post, F, B] using hp
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (116)
- MAX_DIGITS · dec2flt/decimal_seq.rs:63 Program Rust
- right_shift · dec2flt/decimal_seq.rs:175 Program Rust
- right_shift_loop0 · dec2flt/decimal_seq.rs:180 Program Rust
More program dependencies (83)
- 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
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:67 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
- DecimalRightShiftU64DyadicBridge
- ResultLoopPartial
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq DECIMAL POINT RANGE
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
All 8 entries
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftU64DyadicBridge
- 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": "DecimalRightShiftFinalLoopSemantics",
"closure_version": "patch_c_v1",
"active_decl_hash": "5365b01d8facef4e1d1315b6cec7be11c2dc983cef4acdecbc2b31d93026c07c",
"active_statement_hash": "5f52a75102c14cf4603d5ae3fcef00a05523e78b48ea785b997bb6a0882d7444",
"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-161",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalRightShiftU64DyadicBridge": "253d7e344ffc70a6",
"ResultLoopPartial": "566d2aeb76ed9100",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "0eb6fb2627d0ff5c",
"num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "0f3e5cc6a65d812e"
},
"strict_definition_deps": {
"ResultLoopPartial": "1b58e96ad00b23c2",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
"num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "caa3dd29328f3731"
}
}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:251ca0468efe2b54613a0c2e9feeeef225aa93540933a6395a11f9e17007c45c",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}