Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Exact decimal-sequence exponent loop
parse_decimal_exponent(s) returns normally with an I32
value whose mathematical value is \operatorname{foldl}(G,0,D).Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_exponent
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqExponentLoopExact]
theorem DecimalSeqExponentLoopExact :
forall (s : Slice Std.U8) (digits : List Nat),
SourceValidByteSlice s ->
DecimalGoalVocabularyDefault.bytes s =
digits.map (fun digit => 48 + digit) ->
(forall digit, digit ∈ digits -> digit < 10) ->
exists e : Std.I32,
num.imp.dec2flt.decimal_seq.parse_decimal_exponent s = ok e /\
e.val = (digits.foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) := 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
take j D.Lean proof
set_option maxHeartbeats 800000 in
intro s digits hsource hbytes hdigits
change s.val.map (fun b : Std.U8 => b.val) =
digits.map (fun digit => 48 + digit) at hbytes
have hlen : s.val.length = digits.length := by
have hm := congrArg List.length hbytes
simpa using hm
have hbyte : forall j (hj : j < digits.length),
(s.val[j]'(by rw [hlen]; exact hj)).val = 48 + digits[j]'hj := by
intro j hj
have hm := congrArg (fun xs : List Nat => xs[j]?) hbytes
simpa [List.getElem?_eq_getElem, hj, hlen] using hm
have hloop :
num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop s 0#i32 0#usize
⦃ p => p.val = (digits.foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) ⦄ := by
unfold num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Std.I32 × Std.Usize => digits.length - p.2.val)
(fun p => p.2.val <= digits.length /\
p.1.val = (((digits.take p.2.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) : Int))
(fun p => p.val = ((digits.foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) : Int))
(fun p => num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop.body
s p.1 p.2)
(0#i32, 0#usize)
· intro p hp
rcases p with ⟨acc, count⟩
rcases hp with ⟨hcount, hacc⟩
change count.val <= digits.length at hcount
change acc.val = (((digits.take count.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) : Int) at hacc
simp [num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop.body,
WP.spec_ok, Slice.length]
split
· rename_i hins
step
have hi := hbyte count.val (by omega)
have hiVal : i1.val = 48 + digits[count.val]'(by omega) := by
rw [i1_post]
exact hi
step
have hi2Val : i2.val = digits[count.val]'(by omega) := by
rw [i2_post, core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
rw [hiVal]
have hd := hdigits (digits[count.val]'(by omega))
(List.getElem_mem _)
rw [show 48 + digits[count.val] + 208 =
digits[count.val] + 256 by omega]
simp [Nat.add_mod, Nat.mod_eq_of_lt (by omega :
digits[count.val] < 256)]
have hi2Small : i2.val < 10 := by
rw [hi2Val]
exact hdigits _ (List.getElem_mem _)
simp [hi2Small]
step
have hdigitVal : digit.val = digits[count.val]'(by omega) := by
have heq : digit = i2 := by rw [digit_post, i2_post]
rw [heq, hi2Val]
have hcountLt : count.val < digits.length := by
rw [← hlen]
exact hins
by_cases hsmall : acc.val < 65536
· simp only [if_pos hsmall]
step
step
have hxcast : (UScalar.hcast .I32 digit).val = digit.val := by
have hh := UScalar.hcast_inBounds_spec .I32 digit (by scalar_tac)
simpa [WP.spec_ok] using hh
have hmax : (10 * acc.val + digit.val) <= I32.max := by
simp [I32.max_eq]
rw [hdigitVal]
have hd := hdigits (digits[count.val]'(by omega))
(List.getElem_mem _)
omega
step with IScalar.add_spec
step
have hcountMax : count.val + 1 <= UScalar.max .Usize := by
have hsprop := s.property
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, Usize.max, Usize.numBits, hbits] at hsprop ⊢
omega
have hcount1 : count1.val = count.val + 1 := by
simpa using count1_post
have hnext : exp_num1.val = 10 * acc.val + digit.val := by
rw [exp_num1_post, x_post, hxcast]
omega
have hcountLt : count.val < digits.length := by
rw [← hlen]
exact hins
constructor
· rw [hcount1]
omega
· constructor
· rw [hcount1, List.take_succ_eq_append_getElem hcountLt,
List.foldl_append, List.foldl_cons, List.foldl_nil]
have hfoldsmall :
(digits.take count.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 <
65536 := by
rw [hacc] at hsmall
exact_mod_cast hsmall
simp only [if_pos hfoldsmall]
rw [hnext, hacc, hdigitVal]
norm_num
· rw [hcount1]
omega
· simp only [if_neg hsmall]
have hcountMax : count.val + 1 <= UScalar.max .Usize := by
have hsprop := s.property
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, Usize.max, Usize.numBits, hbits] at hsprop ⊢
omega
obtain ⟨count1, hcount1, hcount1Val⟩ :=
Aeneas.Std.WP.spec_imp_exists
(UScalar.add_spec (x := count) (y := 1#usize) hcountMax)
rw [hcount1]
norm_num at hcount1Val
simp [WP.spec_ok]
constructor
· change count1.val <= digits.length
rw [hcount1Val]
omega
· constructor
· change acc.val = _
rw [hacc]
have hfoldge : Not
((digits.take count.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 <
65536) := by
intro hh
apply hsmall
rw [hacc]
exact_mod_cast hh
rw [hcount1Val, List.take_succ_eq_append_getElem hcountLt,
List.foldl_append, List.foldl_cons, List.foldl_nil]
simp [hfoldge]
· change digits.length - count1.val < digits.length - count.val
rw [hcount1Val]
omega
· simp [WP.spec_ok]
have hcountEq : count.val = digits.length := by
rw [← hlen]
omega
rw [hacc, (List.take_eq_self_iff digits).2 (by omega)]
· simp
obtain ⟨e, he⟩ := Aeneas.Std.WP.spec_imp_exists hloop
refine ⟨e, ?_, he.2⟩
unfold num.imp.dec2flt.decimal_seq.parse_decimal_exponent
exact he.1
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_exponent
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqExponentLoopExact]
theorem DecimalSeqExponentLoopExact :
forall (s : Slice Std.U8) (digits : List Nat),
SourceValidByteSlice s ->
DecimalGoalVocabularyDefault.bytes s =
digits.map (fun digit => 48 + digit) ->
(forall digit, digit ∈ digits -> digit < 10) ->
exists e : Std.I32,
num.imp.dec2flt.decimal_seq.parse_decimal_exponent s = ok e /\
e.val = (digits.foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) := by
-- BODY
set_option maxHeartbeats 800000 in
intro s digits hsource hbytes hdigits
change s.val.map (fun b : Std.U8 => b.val) =
digits.map (fun digit => 48 + digit) at hbytes
have hlen : s.val.length = digits.length := by
have hm := congrArg List.length hbytes
simpa using hm
have hbyte : forall j (hj : j < digits.length),
(s.val[j]'(by rw [hlen]; exact hj)).val = 48 + digits[j]'hj := by
intro j hj
have hm := congrArg (fun xs : List Nat => xs[j]?) hbytes
simpa [List.getElem?_eq_getElem, hj, hlen] using hm
have hloop :
num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop s 0#i32 0#usize
⦃ p => p.val = (digits.foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) ⦄ := by
unfold num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop
apply Aeneas.Std.loop.spec_decr_nat
(fun p : Std.I32 × Std.Usize => digits.length - p.2.val)
(fun p => p.2.val <= digits.length /\
p.1.val = (((digits.take p.2.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) : Int))
(fun p => p.val = ((digits.foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) : Int))
(fun p => num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop.body
s p.1 p.2)
(0#i32, 0#usize)
· intro p hp
rcases p with ⟨acc, count⟩
rcases hp with ⟨hcount, hacc⟩
change count.val <= digits.length at hcount
change acc.val = (((digits.take count.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 : Nat) : Int) at hacc
simp [num.imp.dec2flt.decimal_seq.parse_decimal_exponent_loop.body,
WP.spec_ok, Slice.length]
split
· rename_i hins
step
have hi := hbyte count.val (by omega)
have hiVal : i1.val = 48 + digits[count.val]'(by omega) := by
rw [i1_post]
exact hi
step
have hi2Val : i2.val = digits[count.val]'(by omega) := by
rw [i2_post, core.num.U8.wrapping_sub_val_eq]
simp only [UScalar.size_UScalarTyU8, U8.size_eq]
norm_num
rw [hiVal]
have hd := hdigits (digits[count.val]'(by omega))
(List.getElem_mem _)
rw [show 48 + digits[count.val] + 208 =
digits[count.val] + 256 by omega]
simp [Nat.add_mod, Nat.mod_eq_of_lt (by omega :
digits[count.val] < 256)]
have hi2Small : i2.val < 10 := by
rw [hi2Val]
exact hdigits _ (List.getElem_mem _)
simp [hi2Small]
step
have hdigitVal : digit.val = digits[count.val]'(by omega) := by
have heq : digit = i2 := by rw [digit_post, i2_post]
rw [heq, hi2Val]
have hcountLt : count.val < digits.length := by
rw [← hlen]
exact hins
by_cases hsmall : acc.val < 65536
· simp only [if_pos hsmall]
step
step
have hxcast : (UScalar.hcast .I32 digit).val = digit.val := by
have hh := UScalar.hcast_inBounds_spec .I32 digit (by scalar_tac)
simpa [WP.spec_ok] using hh
have hmax : (10 * acc.val + digit.val) <= I32.max := by
simp [I32.max_eq]
rw [hdigitVal]
have hd := hdigits (digits[count.val]'(by omega))
(List.getElem_mem _)
omega
step with IScalar.add_spec
step
have hcountMax : count.val + 1 <= UScalar.max .Usize := by
have hsprop := s.property
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, Usize.max, Usize.numBits, hbits] at hsprop ⊢
omega
have hcount1 : count1.val = count.val + 1 := by
simpa using count1_post
have hnext : exp_num1.val = 10 * acc.val + digit.val := by
rw [exp_num1_post, x_post, hxcast]
omega
have hcountLt : count.val < digits.length := by
rw [← hlen]
exact hins
constructor
· rw [hcount1]
omega
· constructor
· rw [hcount1, List.take_succ_eq_append_getElem hcountLt,
List.foldl_append, List.foldl_cons, List.foldl_nil]
have hfoldsmall :
(digits.take count.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 <
65536 := by
rw [hacc] at hsmall
exact_mod_cast hsmall
simp only [if_pos hfoldsmall]
rw [hnext, hacc, hdigitVal]
norm_num
· rw [hcount1]
omega
· simp only [if_neg hsmall]
have hcountMax : count.val + 1 <= UScalar.max .Usize := by
have hsprop := s.property
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, Usize.max, Usize.numBits, hbits] at hsprop ⊢
omega
obtain ⟨count1, hcount1, hcount1Val⟩ :=
Aeneas.Std.WP.spec_imp_exists
(UScalar.add_spec (x := count) (y := 1#usize) hcountMax)
rw [hcount1]
norm_num at hcount1Val
simp [WP.spec_ok]
constructor
· change count1.val <= digits.length
rw [hcount1Val]
omega
· constructor
· change acc.val = _
rw [hacc]
have hfoldge : Not
((digits.take count.val).foldl
(fun n digit => if n < 65536 then 10 * n + digit else n) 0 <
65536) := by
intro hh
apply hsmall
rw [hacc]
exact_mod_cast hh
rw [hcount1Val, List.take_succ_eq_append_getElem hcountLt,
List.foldl_append, List.foldl_cons, List.foldl_nil]
simp [hfoldge]
· change digits.length - count1.val < digits.length - count.val
rw [hcount1Val]
omega
· simp [WP.spec_ok]
have hcountEq : count.val = digits.length := by
rw [← hlen]
omega
rw [hacc, (List.take_eq_self_iff digits).2 (by omega)]
· simp
obtain ⟨e, he⟩ := Aeneas.Std.WP.spec_imp_exists hloop
refine ⟨e, ?_, he.2⟩
unfold num.imp.dec2flt.decimal_seq.parse_decimal_exponent
exact he.1
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (47)
- 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
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
- 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
Technical checking records
Local closure summary
{
"node": "DecimalSeqExponentLoopExact",
"closure_version": "patch_c_v1",
"active_decl_hash": "c72deb7bb21f4f058c2e0b952a25f3c1d6ad84c04f2c78918762498652d35ce3",
"active_statement_hash": "ae89ed0f3ad04fbc10b802b73cc7e4465434226ba5c25c920e040e9c0ab6f67b",
"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": "revalidate-cycle-163",
"boundary_theorems": {},
"strict_theorem_deps": {
"num_imp_dec2flt_decimal_seq_parse_decimal_exponent": "faf0081b4c91301b"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "65227461bf3cac06",
"DecimalGoalVocabularyDefault": "512f8d0aea894250",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_decimal_seq_parse_decimal_exponent": "498406f251d28850"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:daa8a632b7ca9e58947455017bcd855a6ccbebf64f068dab773e999b1bf139ed",
"current_fingerprint": "sound-v2:daa8a632b7ca9e58947455017bcd855a6ccbebf64f068dab773e999b1bf139ed",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}