Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Helper · Exact adjustment for the long decimal witness
start contain the ASCII bytes 0., followed by exactly
65{,}535 zero bytes, and then 1e655360. When the extracted
adjust_many_digit_count operation starts with count 65{,}518,
it returns the signed count -18.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 1000000
namespace dec2flt_model
-- [TABLET NODE: ParserExactRoundingAdjustment]
theorem ParserExactRoundingAdjustment (start : Slice Std.U8)
(hs : start.val = [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
num.imp.dec2flt.parse.adjust_many_digit_count start 65518#isize =
ok (-18)#isize := by
Proof
Natural-language proof
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Proof
0; subtracting 47 saturatingly from its byte value produces one,
so the checked signed subtraction changes the count from 65{,}518 to
65{,}517. The next byte is the point. Its saturating difference from
47 is zero, so the count remains 65{,}517. Both checked index increments
remain within either possible model usize bound.1. It is neither
the point nor zero, so the loop preserves the count
65{,}517-65{,}535=-18 and changes the scanning flag to false. The next
loop body returns that count. Termination follows from the decreasing
measure twice the distance from index 65{,}537, plus one exactly while
scanning is true. Hence the extracted operation returns -18 as claimed.Lean proof
have read_zero (index : Std.Usize) (k : Nat)
(hi : index.val = 2 + k) (hk : k < 65535) :
Slice.index_usize start index = ok 48#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq]
rw [hs, hi]
rw [List.getElem?_append_left (by
simp only [List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
omega)]
rw [List.getElem?_append_right (by norm_num)]
simp only [List.length_cons, List.length_nil, Nat.add_sub_cancel_left]
rw [List.getElem?_replicate_of_lt hk]
have read_one (index : Std.Usize) (hi : index.val = 65537) :
Slice.index_usize start index = ok 49#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq]
rw [hs, hi]
rw [List.getElem?_append_right (by norm_num)]
simp only [List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
rfl
have adjust_loop_exact :
num.imp.dec2flt.parse.adjust_many_digit_count_loop
start 65517#isize 2#usize true = ok (-18)#isize := by
have hloop : num.imp.dec2flt.parse.adjust_many_digit_count_loop
start 65517#isize 2#usize true
⦃ adjusted => adjusted.val = -18 ⦄ := by
unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Std.Isize × Std.Usize × Bool =>
2 * (65537 - p.2.1.val) + if p.2.2 then 1 else 0)
(fun p =>
(p.2.2 = true /\ exists k : Nat,
k <= 65535 /\ p.2.1.val = 2 + k /\
p.1.val = 65517 - (k : Int)) \/
(p.2.2 = false /\ p.2.1.val = 65537 /\ p.1.val = -18))
(fun adjusted => adjusted.val = -18)
(fun p => num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start p.1 p.2.1 p.2.2)
(65517#isize, 2#usize, true)
· intro p hp
rcases p with ⟨count, index, scanning⟩
rcases hp with hscan | hdone
· rcases hscan with ⟨hscanning, k, hk, hindex, hcount⟩
simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
have hscanning' : scanning = true := hscanning
subst scanning
by_cases hmore : k < 65535
· have hinside : index < Slice.len start := by
change index.val < start.val.length
simp only [hs, List.length_append, List.length_cons,
List.length_nil, List.length_replicate]
omega
have hread := read_zero index k hindex hmore
have hsublo :
IScalar.min .Isize <= count.val - (1#isize).val := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalarTy.numBits, hbits] <;> omega
have hsubhi :
count.val - (1#isize).val <= IScalar.max .Isize := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.max, IScalarTy.numBits, hbits] <;> omega
obtain ⟨count1, hcount1, hcount1val⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec hsublo hsubhi)
have haddbound :
index.val + (1#usize).val <= UScalar.max .Usize := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [UScalar.max, hbits] <;> omega
obtain ⟨index1, hindex1, hindex1val⟩ :=
Aeneas.Std.WP.spec_imp_exists (UScalar.add_spec haddbound)
have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
apply IScalar.eq_of_val_eq
have h := UScalar.hcast_inBounds_spec .Isize (1#u8)
(by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
simpa [Aeneas.Std.lift, WP.spec_ok] using h
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside, hread, hindex1]
rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
change (do
let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
let digit' ← lift (UScalar.hcast .Isize digit)
let count2 ← count - digit'
ok (cont (count2, index1, true))) ⦃_⦄
rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
ok 1#u8 by rfl]
change (do
let digit' ← lift (UScalar.hcast .Isize 1#u8)
let count2 ← count - digit'
ok (cont (count2, index1, true))) ⦃_⦄
rw [hcast1]
change (do
let count2 ← count - 1#isize
ok (cont (count2, index1, true))) ⦃_⦄
rw [hcount1]
simp [WP.spec_ok]
have hcount1val' : count1.val = count.val - 1 := by
simpa using hcount1val
have hindex1val' : index1.val = index.val + 1 := by
simpa using hindex1val
clear hsublo hsubhi haddbound hcount1val hindex1val
constructor
· refine ⟨k + 1, by omega, ?_, ?_⟩ <;> omega
· omega
· have hindex' : index.val = 65537 := by omega
have hinside : index < Slice.len start := by
change index.val < start.val.length
simp only [hs, List.length_append, List.length_cons,
List.length_nil, List.length_replicate]
omega
have hread := read_one index hindex'
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside, hread, WP.spec_ok]
omega
· rcases hdone with ⟨hscanning, hindex, hcount⟩
simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
have hscanning' : scanning = false := hscanning
subst scanning
have hinside : index < Slice.len start := by
change index.val < start.val.length
simp only [hs, List.length_append, List.length_cons,
List.length_nil, List.length_replicate]
omega
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside, WP.spec_ok]
exact hcount
· simp
obtain ⟨adjusted, hadjusted, hval⟩ :=
Aeneas.Std.WP.spec_imp_exists hloop
have heq : adjusted = (-18)#isize := by
apply IScalar.eq_of_val_eq
simpa using hval
simpa [heq] using hadjusted
have hinside0 : (0#usize) < Slice.len start := by
change 0 < start.val.length
simp only [hs, List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
omega
have hinside1 : (1#usize) < Slice.len start := by
change 1 < start.val.length
simp only [hs, List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
omega
have hread0 : Slice.index_usize start 0#usize = ok 48#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq, hs]
rfl
have hread1 : Slice.index_usize start 1#usize = ok 46#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq, hs]
rfl
have addOne (x y : Usize) (hxy : x.val + 1 = y.val) :
x + 1#usize = ok y := by
have hmax : x.val + (1#usize).val <= UScalar.max .Usize := by
rw [show (1#usize).val = 1 by rfl, hxy]
have hy := UScalar.hrBounds y
simpa [UScalar.rMax_eq_max] using hy
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.add_spec hmax)
rw [hz]
congr 1
apply UScalar.eq_of_val_eq
simpa [hxy] using hzval
have subSmall (x y d : Isize) (hxy : x.val - d.val = y.val) :
x - d = ok y := by
have hy := IScalar.hBounds y
have hmin : IScalar.min .Isize <= x.val - d.val := by
rw [hxy]
simpa [IScalar.min] using hy.1
have hmax : x.val - d.val <= IScalar.max .Isize := by
rw [hxy]
simp only [IScalar.max]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec hmin hmax)
rw [hz]
congr 1
apply IScalar.eq_of_val_eq
simpa [hxy] using hzval
have hsub0 : 65518#isize - 1#isize = ok 65517#isize :=
subSmall _ _ _ (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
scalar_tac)
have hsubPoint : 65517#isize - 0#isize = ok 65517#isize :=
subSmall _ _ _ (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
scalar_tac)
have hidx0 : 0#usize + 1#usize = ok 1#usize := addOne _ _ (by rfl)
have hidx1 : 1#usize + 1#usize = ok 2#usize := addOne _ _ (by rfl)
have hbody0 :
num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start 65518#isize 0#usize true =
ok (cont (65517#isize, 1#usize, true)) := by
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside0, hread0, Aeneas.Std.lift]
rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
change (do
let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
let digit' ← lift (UScalar.hcast .Isize digit)
let count ← 65518#isize - digit'
let index ← 0#usize + 1#usize
ok (cont (count, index, true))) = _
rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
ok 1#u8 by rfl]
change (do
let digit' ← lift (UScalar.hcast .Isize 1#u8)
let count ← 65518#isize - digit'
let index ← 0#usize + 1#usize
ok (cont (count, index, true))) = _
have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
apply IScalar.eq_of_val_eq
have h := UScalar.hcast_inBounds_spec .Isize (1#u8) (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
simpa [Aeneas.Std.lift, WP.spec_ok] using h
rw [hcast1]
change (do
let count ← 65518#isize - 1#isize
let index ← 0#usize + 1#usize
ok (cont (count, index, true))) = _
rw [hsub0]
change (do
let index ← 0#usize + 1#usize
ok (cont (65517#isize, index, true))) = _
rw [hidx0]
rfl
have hbody1 :
num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start 65517#isize 1#usize true =
ok (cont (65517#isize, 2#usize, true)) := by
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside1, hread1, Aeneas.Std.lift]
rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
change (do
let digit ← lift (core.num.U8.saturating_sub 46#u8 47#u8)
let digit' ← lift (UScalar.hcast .Isize digit)
let count ← 65517#isize - digit'
let index ← 1#usize + 1#usize
ok (cont (count, index, true))) = _
rw [show lift (core.num.U8.saturating_sub 46#u8 47#u8) =
ok 0#u8 by rfl]
change (do
let digit' ← lift (UScalar.hcast .Isize 0#u8)
let count ← 65517#isize - digit'
let index ← 1#usize + 1#usize
ok (cont (count, index, true))) = _
have hcast0 : UScalar.hcast .Isize 0#u8 = 0#isize := by
apply IScalar.eq_of_val_eq
have h := UScalar.hcast_inBounds_spec .Isize (0#u8) (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
simpa [Aeneas.Std.lift, WP.spec_ok] using h
rw [hcast0]
change (do
let count ← 65517#isize - 0#isize
let index ← 1#usize + 1#usize
ok (cont (count, index, true))) = _
rw [hsubPoint]
change (do
let index ← 1#usize + 1#usize
ok (cont (65517#isize, index, true))) = _
rw [hidx1]
rfl
unfold num.imp.dec2flt.parse.adjust_many_digit_count
unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
rw [Aeneas.Std.loop.eq_1]
simp only [hbody0]
rw [Aeneas.Std.loop.eq_1]
simp only [hbody1]
simpa [num.imp.dec2flt.parse.adjust_many_digit_count_loop] using
adjust_loop_exact
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 1000000
namespace dec2flt_model
-- [TABLET NODE: ParserExactRoundingAdjustment]
theorem ParserExactRoundingAdjustment (start : Slice Std.U8)
(hs : start.val = [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
[49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]) :
num.imp.dec2flt.parse.adjust_many_digit_count start 65518#isize =
ok (-18)#isize := by
-- BODY
have read_zero (index : Std.Usize) (k : Nat)
(hi : index.val = 2 + k) (hk : k < 65535) :
Slice.index_usize start index = ok 48#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq]
rw [hs, hi]
rw [List.getElem?_append_left (by
simp only [List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
omega)]
rw [List.getElem?_append_right (by norm_num)]
simp only [List.length_cons, List.length_nil, Nat.add_sub_cancel_left]
rw [List.getElem?_replicate_of_lt hk]
have read_one (index : Std.Usize) (hi : index.val = 65537) :
Slice.index_usize start index = ok 49#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq]
rw [hs, hi]
rw [List.getElem?_append_right (by norm_num)]
simp only [List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
rfl
have adjust_loop_exact :
num.imp.dec2flt.parse.adjust_many_digit_count_loop
start 65517#isize 2#usize true = ok (-18)#isize := by
have hloop : num.imp.dec2flt.parse.adjust_many_digit_count_loop
start 65517#isize 2#usize true
⦃ adjusted => adjusted.val = -18 ⦄ := by
unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Std.Isize × Std.Usize × Bool =>
2 * (65537 - p.2.1.val) + if p.2.2 then 1 else 0)
(fun p =>
(p.2.2 = true /\ exists k : Nat,
k <= 65535 /\ p.2.1.val = 2 + k /\
p.1.val = 65517 - (k : Int)) \/
(p.2.2 = false /\ p.2.1.val = 65537 /\ p.1.val = -18))
(fun adjusted => adjusted.val = -18)
(fun p => num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start p.1 p.2.1 p.2.2)
(65517#isize, 2#usize, true)
· intro p hp
rcases p with ⟨count, index, scanning⟩
rcases hp with hscan | hdone
· rcases hscan with ⟨hscanning, k, hk, hindex, hcount⟩
simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
have hscanning' : scanning = true := hscanning
subst scanning
by_cases hmore : k < 65535
· have hinside : index < Slice.len start := by
change index.val < start.val.length
simp only [hs, List.length_append, List.length_cons,
List.length_nil, List.length_replicate]
omega
have hread := read_zero index k hindex hmore
have hsublo :
IScalar.min .Isize <= count.val - (1#isize).val := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalarTy.numBits, hbits] <;> omega
have hsubhi :
count.val - (1#isize).val <= IScalar.max .Isize := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.max, IScalarTy.numBits, hbits] <;> omega
obtain ⟨count1, hcount1, hcount1val⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec hsublo hsubhi)
have haddbound :
index.val + (1#usize).val <= UScalar.max .Usize := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [UScalar.max, hbits] <;> omega
obtain ⟨index1, hindex1, hindex1val⟩ :=
Aeneas.Std.WP.spec_imp_exists (UScalar.add_spec haddbound)
have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
apply IScalar.eq_of_val_eq
have h := UScalar.hcast_inBounds_spec .Isize (1#u8)
(by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
simpa [Aeneas.Std.lift, WP.spec_ok] using h
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside, hread, hindex1]
rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
change (do
let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
let digit' ← lift (UScalar.hcast .Isize digit)
let count2 ← count - digit'
ok (cont (count2, index1, true))) ⦃_⦄
rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
ok 1#u8 by rfl]
change (do
let digit' ← lift (UScalar.hcast .Isize 1#u8)
let count2 ← count - digit'
ok (cont (count2, index1, true))) ⦃_⦄
rw [hcast1]
change (do
let count2 ← count - 1#isize
ok (cont (count2, index1, true))) ⦃_⦄
rw [hcount1]
simp [WP.spec_ok]
have hcount1val' : count1.val = count.val - 1 := by
simpa using hcount1val
have hindex1val' : index1.val = index.val + 1 := by
simpa using hindex1val
clear hsublo hsubhi haddbound hcount1val hindex1val
constructor
· refine ⟨k + 1, by omega, ?_, ?_⟩ <;> omega
· omega
· have hindex' : index.val = 65537 := by omega
have hinside : index < Slice.len start := by
change index.val < start.val.length
simp only [hs, List.length_append, List.length_cons,
List.length_nil, List.length_replicate]
omega
have hread := read_one index hindex'
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside, hread, WP.spec_ok]
omega
· rcases hdone with ⟨hscanning, hindex, hcount⟩
simp only [Prod.fst, Prod.snd] at hscanning hindex hcount ⊢
have hscanning' : scanning = false := hscanning
subst scanning
have hinside : index < Slice.len start := by
change index.val < start.val.length
simp only [hs, List.length_append, List.length_cons,
List.length_nil, List.length_replicate]
omega
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside, WP.spec_ok]
exact hcount
· simp
obtain ⟨adjusted, hadjusted, hval⟩ :=
Aeneas.Std.WP.spec_imp_exists hloop
have heq : adjusted = (-18)#isize := by
apply IScalar.eq_of_val_eq
simpa using hval
simpa [heq] using hadjusted
have hinside0 : (0#usize) < Slice.len start := by
change 0 < start.val.length
simp only [hs, List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
omega
have hinside1 : (1#usize) < Slice.len start := by
change 1 < start.val.length
simp only [hs, List.length_append, List.length_cons, List.length_nil,
List.length_replicate]
omega
have hread0 : Slice.index_usize start 0#usize = ok 48#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq, hs]
rfl
have hread1 : Slice.index_usize start 1#usize = ok 46#u8 := by
unfold Slice.index_usize
rw [Slice.getElem?_Usize_eq, hs]
rfl
have addOne (x y : Usize) (hxy : x.val + 1 = y.val) :
x + 1#usize = ok y := by
have hmax : x.val + (1#usize).val <= UScalar.max .Usize := by
rw [show (1#usize).val = 1 by rfl, hxy]
have hy := UScalar.hrBounds y
simpa [UScalar.rMax_eq_max] using hy
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.add_spec hmax)
rw [hz]
congr 1
apply UScalar.eq_of_val_eq
simpa [hxy] using hzval
have subSmall (x y d : Isize) (hxy : x.val - d.val = y.val) :
x - d = ok y := by
have hy := IScalar.hBounds y
have hmin : IScalar.min .Isize <= x.val - d.val := by
rw [hxy]
simpa [IScalar.min] using hy.1
have hmax : x.val - d.val <= IScalar.max .Isize := by
rw [hxy]
simp only [IScalar.max]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec hmin hmax)
rw [hz]
congr 1
apply IScalar.eq_of_val_eq
simpa [hxy] using hzval
have hsub0 : 65518#isize - 1#isize = ok 65517#isize :=
subSmall _ _ _ (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
scalar_tac)
have hsubPoint : 65517#isize - 0#isize = ok 65517#isize :=
subSmall _ _ _ (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
scalar_tac)
have hidx0 : 0#usize + 1#usize = ok 1#usize := addOne _ _ (by rfl)
have hidx1 : 1#usize + 1#usize = ok 2#usize := addOne _ _ (by rfl)
have hbody0 :
num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start 65518#isize 0#usize true =
ok (cont (65517#isize, 1#usize, true)) := by
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside0, hread0, Aeneas.Std.lift]
rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
change (do
let digit ← lift (core.num.U8.saturating_sub 48#u8 47#u8)
let digit' ← lift (UScalar.hcast .Isize digit)
let count ← 65518#isize - digit'
let index ← 0#usize + 1#usize
ok (cont (count, index, true))) = _
rw [show lift (core.num.U8.saturating_sub 48#u8 47#u8) =
ok 1#u8 by rfl]
change (do
let digit' ← lift (UScalar.hcast .Isize 1#u8)
let count ← 65518#isize - digit'
let index ← 0#usize + 1#usize
ok (cont (count, index, true))) = _
have hcast1 : UScalar.hcast .Isize 1#u8 = 1#isize := by
apply IScalar.eq_of_val_eq
have h := UScalar.hcast_inBounds_spec .Isize (1#u8) (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
simpa [Aeneas.Std.lift, WP.spec_ok] using h
rw [hcast1]
change (do
let count ← 65518#isize - 1#isize
let index ← 0#usize + 1#usize
ok (cont (count, index, true))) = _
rw [hsub0]
change (do
let index ← 0#usize + 1#usize
ok (cont (65517#isize, index, true))) = _
rw [hidx0]
rfl
have hbody1 :
num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start 65517#isize 1#usize true =
ok (cont (65517#isize, 2#usize, true)) := by
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
hinside1, hread1, Aeneas.Std.lift]
rw [show (48#u8 - 1#u8) = ok 47#u8 by rfl]
change (do
let digit ← lift (core.num.U8.saturating_sub 46#u8 47#u8)
let digit' ← lift (UScalar.hcast .Isize digit)
let count ← 65517#isize - digit'
let index ← 1#usize + 1#usize
ok (cont (count, index, true))) = _
rw [show lift (core.num.U8.saturating_sub 46#u8 47#u8) =
ok 0#u8 by rfl]
change (do
let digit' ← lift (UScalar.hcast .Isize 0#u8)
let count ← 65517#isize - digit'
let index ← 1#usize + 1#usize
ok (cont (count, index, true))) = _
have hcast0 : UScalar.hcast .Isize 0#u8 = 0#isize := by
apply IScalar.eq_of_val_eq
have h := UScalar.hcast_inBounds_spec .Isize (0#u8) (by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [IScalar.min, IScalar.max, IScalarTy.numBits, hbits])
simpa [Aeneas.Std.lift, WP.spec_ok] using h
rw [hcast0]
change (do
let count ← 65517#isize - 0#isize
let index ← 1#usize + 1#usize
ok (cont (count, index, true))) = _
rw [hsubPoint]
change (do
let index ← 1#usize + 1#usize
ok (cont (65517#isize, index, true))) = _
rw [hidx1]
rfl
unfold num.imp.dec2flt.parse.adjust_many_digit_count
unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
rw [Aeneas.Std.loop.eq_1]
simp only [hbody0]
rw [Aeneas.Std.loop.eq_1]
simp only [hbody1]
simpa [num.imp.dec2flt.parse.adjust_many_digit_count_loop] using
adjust_loop_exact
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (47)
- adjust_many_digit_count · dec2flt/parse.rs:86 Program Rust
- adjust_many_digit_count_loop · dec2flt/parse.rs:89 Program Rust
- body · dec2flt/parse.rs:89 Program Rust
More program dependencies (14)
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (30)
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
Technical checking records
Local closure summary
{
"node": "ParserExactRoundingAdjustment",
"closure_version": "patch_c_v1",
"active_decl_hash": "9d09748f71c4609875c0c42f6e8a4ab90a244de2fc419348ed6cc81cc1deea09",
"active_statement_hash": "77a7e4d11728f051dbf0d640c901fce5bfd986f6e53236c40057072e4b14fb59",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-128",
"boundary_theorems": {},
"strict_theorem_deps": {
"num_imp_dec2flt_parse_adjust_many_digit_count": "faf0081b4c91301b"
},
"strict_definition_deps": {
"num_imp_dec2flt_parse_adjust_many_digit_count": "1bc88a1b016164f3"
}
}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:5f4720f11f16bbeb96e9c6e6b026d7b64751937bc969982bc51b52f119da83c1",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}