Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Safe bounded many-digit adjustment
isize whose value is at most |s|. The extracted
adjust_many_digit_count operation returns normally.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
namespace dec2flt_model
-- [TABLET NODE: NumberHelperAdjustManySourceLength]
theorem NumberHelperAdjustManySourceLength
(start : Slice Std.U8) (n : Std.Isize)
(hlen : start.val.length <= 9223372036854775807)
(hnonneg : 0 <= n.val) (hnle : n.val <= start.val.length) :
exists adjusted,
num.imp.dec2flt.parse.adjust_many_digit_count start n = ok adjusted := 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
isize. In the first branch the new count remains above
n-(j+1); in the second it is exactly one less and again remains above
that lower bound. A different byte changes the scanning flag from true to
false without changing the index, which decreases the parity part of the
measure; the next iteration returns. Reaching the end also returns.isize and usize
widths are 64 bits, and the assumed length is at most 2^{63}-1.
Consequently both possible signed subtractions and every guarded index
increment succeed. The measure decreases on every continuing branch, so
the loop terminates normally and supplies the claimed result.Lean proof
have hloop : num.imp.dec2flt.parse.adjust_many_digit_count_loop
start n 0#usize true ⦃ _ => True ⦄ := 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 * (start.val.length - p.2.1.val) + if p.2.2 then 1 else 0)
(fun p => p.2.1.val <= start.val.length /\
n.val - p.2.1.val <= p.1.val /\ p.1.val <= n.val)
(fun _ => True)
(fun p => num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start p.1 p.2.1 p.2.2)
(n, 0#usize, true)
· intro p hp
rcases p with ⟨count, index, scanning⟩
rcases hp with ⟨hindex, hcountlo, hcounthi⟩
simp only [Prod.fst, Prod.snd] at hindex hcountlo hcounthi
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
WP.spec_ok, Slice.len_val]
split
· rename_i hinside
split
· rename_i hscanning
have hget : exists c, Slice.index_usize start index = ok c := by
simp [Slice.index_usize, hinside]
obtain ⟨c, hc⟩ := hget
rw [hc]
by_cases hpoint : c = 46#u8
· subst c
simp
have hi1 : (48#u8 - 1#u8) = ok 47#u8 := by rfl
rw [hi1]
simp
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 scalar_tac)
simpa [Aeneas.Std.lift, WP.spec_ok] using h
have hsaturate0 :
core.num.U8.saturating_sub 46#u8 47#u8 = 0#u8 := by
rfl
rw [hsaturate0]
simp [Aeneas.Std.lift]
rw [hcast0]
have hsublo : IScalar.min .Isize <= count.val - (0#isize).val := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.min, IScalarTy.numBits, hbits]
omega
have hsubhi : count.val - (0#isize).val <= IScalar.max .Isize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.max, IScalarTy.numBits, hbits]
omega
have hsub := IScalar.sub_spec hsublo hsubhi
obtain ⟨count1, hcount1, hcount1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hsub
rw [hcount1]
have haddbound :
index.val + (1#usize).val <= UScalar.max .Usize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, hbits]
omega
have hadd := UScalar.add_spec haddbound
obtain ⟨index1, hindex1, hindex1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hadd
rw [hindex1]
simp [WP.spec_ok, Slice.length]
simp at hcount1val hindex1val
omega
· simp [hpoint]
by_cases hzero : c = 48#u8
· subst c
simp
have hi1 : (48#u8 - 1#u8) = ok 47#u8 := by rfl
rw [hi1]
simp
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 scalar_tac)
simpa [Aeneas.Std.lift, WP.spec_ok] using h
have hsaturate1 :
core.num.U8.saturating_sub 48#u8 47#u8 = 1#u8 := by
rfl
rw [hsaturate1]
simp [Aeneas.Std.lift]
rw [hcast1]
have hsublo :
IScalar.min .Isize <= count.val - (1#isize).val := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.min, IScalarTy.numBits, hbits]
omega
have hsubhi :
count.val - (1#isize).val <= IScalar.max .Isize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.max, IScalarTy.numBits, hbits]
omega
have hsub := IScalar.sub_spec hsublo hsubhi
obtain ⟨count1, hcount1, hcount1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hsub
rw [hcount1]
have haddbound :
index.val + (1#usize).val <= UScalar.max .Usize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, hbits]
omega
have hadd := UScalar.add_spec haddbound
obtain ⟨index1, hindex1, hindex1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hadd
rw [hindex1]
simp [WP.spec_ok, Slice.length]
simp at hcount1val hindex1val
omega
· simp [hzero, WP.spec_ok]
omega
· simp [WP.spec_ok]
· simp [WP.spec_ok]
· simp [hnonneg, hnle]
obtain ⟨adjusted, hadjusted, _⟩ := Aeneas.Std.WP.spec_imp_exists hloop
exact ⟨adjusted, hadjusted⟩
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
namespace dec2flt_model
-- [TABLET NODE: NumberHelperAdjustManySourceLength]
theorem NumberHelperAdjustManySourceLength
(start : Slice Std.U8) (n : Std.Isize)
(hlen : start.val.length <= 9223372036854775807)
(hnonneg : 0 <= n.val) (hnle : n.val <= start.val.length) :
exists adjusted,
num.imp.dec2flt.parse.adjust_many_digit_count start n = ok adjusted := by
-- BODY
have hloop : num.imp.dec2flt.parse.adjust_many_digit_count_loop
start n 0#usize true ⦃ _ => True ⦄ := 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 * (start.val.length - p.2.1.val) + if p.2.2 then 1 else 0)
(fun p => p.2.1.val <= start.val.length /\
n.val - p.2.1.val <= p.1.val /\ p.1.val <= n.val)
(fun _ => True)
(fun p => num.imp.dec2flt.parse.adjust_many_digit_count_loop.body
start p.1 p.2.1 p.2.2)
(n, 0#usize, true)
· intro p hp
rcases p with ⟨count, index, scanning⟩
rcases hp with ⟨hindex, hcountlo, hcounthi⟩
simp only [Prod.fst, Prod.snd] at hindex hcountlo hcounthi
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
WP.spec_ok, Slice.len_val]
split
· rename_i hinside
split
· rename_i hscanning
have hget : exists c, Slice.index_usize start index = ok c := by
simp [Slice.index_usize, hinside]
obtain ⟨c, hc⟩ := hget
rw [hc]
by_cases hpoint : c = 46#u8
· subst c
simp
have hi1 : (48#u8 - 1#u8) = ok 47#u8 := by rfl
rw [hi1]
simp
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 scalar_tac)
simpa [Aeneas.Std.lift, WP.spec_ok] using h
have hsaturate0 :
core.num.U8.saturating_sub 46#u8 47#u8 = 0#u8 := by
rfl
rw [hsaturate0]
simp [Aeneas.Std.lift]
rw [hcast0]
have hsublo : IScalar.min .Isize <= count.val - (0#isize).val := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.min, IScalarTy.numBits, hbits]
omega
have hsubhi : count.val - (0#isize).val <= IScalar.max .Isize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.max, IScalarTy.numBits, hbits]
omega
have hsub := IScalar.sub_spec hsublo hsubhi
obtain ⟨count1, hcount1, hcount1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hsub
rw [hcount1]
have haddbound :
index.val + (1#usize).val <= UScalar.max .Usize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, hbits]
omega
have hadd := UScalar.add_spec haddbound
obtain ⟨index1, hindex1, hindex1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hadd
rw [hindex1]
simp [WP.spec_ok, Slice.length]
simp at hcount1val hindex1val
omega
· simp [hpoint]
by_cases hzero : c = 48#u8
· subst c
simp
have hi1 : (48#u8 - 1#u8) = ok 47#u8 := by rfl
rw [hi1]
simp
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 scalar_tac)
simpa [Aeneas.Std.lift, WP.spec_ok] using h
have hsaturate1 :
core.num.U8.saturating_sub 48#u8 47#u8 = 1#u8 := by
rfl
rw [hsaturate1]
simp [Aeneas.Std.lift]
rw [hcast1]
have hsublo :
IScalar.min .Isize <= count.val - (1#isize).val := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.min, IScalarTy.numBits, hbits]
omega
have hsubhi :
count.val - (1#isize).val <= IScalar.max .Isize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [IScalar.max, IScalarTy.numBits, hbits]
omega
have hsub := IScalar.sub_spec hsublo hsubhi
obtain ⟨count1, hcount1, hcount1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hsub
rw [hcount1]
have haddbound :
index.val + (1#usize).val <= UScalar.max .Usize := by
have hbits := Dec2Flt.configured_x86_64_numBits
simp [UScalar.max, hbits]
omega
have hadd := UScalar.add_spec haddbound
obtain ⟨index1, hindex1, hindex1val⟩ :=
Aeneas.Std.WP.spec_imp_exists hadd
rw [hindex1]
simp [WP.spec_ok, Slice.length]
simp at hcount1val hindex1val
omega
· simp [hzero, WP.spec_ok]
omega
· simp [WP.spec_ok]
· simp [WP.spec_ok]
· simp [hnonneg, hnle]
obtain ⟨adjusted, hadjusted, _⟩ := Aeneas.Std.WP.spec_imp_exists hloop
exact ⟨adjusted, hadjusted⟩
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
- 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": "NumberHelperAdjustManySourceLength",
"closure_version": "patch_c_v1",
"active_decl_hash": "18d6142ef36a8214253a601c843b0b3b9a250b99e64a222c1d5696655c967400",
"active_statement_hash": "5b69ae9e44571f54cc556c64ad7af6781f93b499372b3280899525adf457b012",
"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-116",
"boundary_theorems": {},
"strict_theorem_deps": {
"num_imp_dec2flt_parse_adjust_many_digit_count": "7a20708611001f01"
},
"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:08296c86ad91345b6199aac17ff5fac40da4d14b621c41c32d3e593b0dbddf88",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}