Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Helper · Exact many-digit adjustment
s begin with the bytes 0., then eleven ASCII zero
bytes, then an ASCII 1, followed by an arbitrary suffix. The
extracted adjust_many_digit_count operation, started with count
2{,}147{,}483{,}630, returns the exact count 2{,}147{,}483{,}618.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.NumberHelperAdjustManySourceLength
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 65536
namespace dec2flt_model
-- [TABLET NODE: ParserNumericAdjustmentCertificate]
theorem ParserNumericAdjustmentCertificate (s : Slice Std.U8)
(tail : List Std.U8)
(hs : s.val = [48#u8, 46#u8] ++
List.replicate 11 48#u8 ++ 49#u8 :: tail) :
num.imp.dec2flt.parse.adjust_many_digit_count s 2147483630#isize =
ok 2147483618#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 one from its byte value and then saturating at zero
produces one, so the checked signed count decreases from
2{,}147{,}483{,}630 to 2{,}147{,}483{,}629. On the point byte the same
calculation produces zero, so the count is unchanged. Each of the next
eleven zero bytes again produces one, giving the successive counts
2{,}147{,}483{,}628 through 2{,}147{,}483{,}618. The following byte is
1, so its adjusted byte value is two; the loop changes its scanning
flag to false without changing the count, and the following loop head returns.usize range, and all twelve subtractions by
one (as well as the subtraction by zero) remain within the 64-bit
isize range fixed by Assumptions. Thus every checked
operation follows the successful branch and the extracted loop returns the
claimed exact count.Lean proof
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 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 hbyteSub : (48#u8 - 1#u8) = ok 47#u8 := by rfl
have hsat0 : core.num.U8.saturating_sub 46#u8 47#u8 = 0#u8 := by rfl
have hsat1 : core.num.U8.saturating_sub 48#u8 47#u8 = 1#u8 := by 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
have ha := UScalar.add_spec hmax
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists ha
rw [hz]
congr 1
apply UScalar.eq_of_val_eq
simpa [hxy] using hzval
have subSmall (x y d : Isize) (hd : d = 0#isize ∨ d = 1#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]
simp only [IScalar.min]
simpa [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] using hy.1
have hmax : x.val - d.val ≤ IScalar.max .Isize := by
rw [hxy]
simp only [IScalar.max]
have := hy.2
simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] at this ⊢
omega
have hsub := IScalar.sub_spec (x := x) (y := d) hmin hmax
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists hsub
rw [hz]
congr 1
apply IScalar.eq_of_val_eq
simpa [hxy] using hzval
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 hidx2 : 2#usize + 1#usize = ok 3#usize := addOne _ _ (by rfl)
have hidx3 : 3#usize + 1#usize = ok 4#usize := addOne _ _ (by rfl)
have hidx4 : 4#usize + 1#usize = ok 5#usize := addOne _ _ (by rfl)
have hidx5 : 5#usize + 1#usize = ok 6#usize := addOne _ _ (by rfl)
have hidx6 : 6#usize + 1#usize = ok 7#usize := addOne _ _ (by rfl)
have hidx7 : 7#usize + 1#usize = ok 8#usize := addOne _ _ (by rfl)
have hidx8 : 8#usize + 1#usize = ok 9#usize := addOne _ _ (by rfl)
have hidx9 : 9#usize + 1#usize = ok 10#usize := addOne _ _ (by rfl)
have hidx10 : 10#usize + 1#usize = ok 11#usize := addOne _ _ (by rfl)
have hidx11 : 11#usize + 1#usize = ok 12#usize := addOne _ _ (by rfl)
have hidx12 : 12#usize + 1#usize = ok 13#usize := addOne _ _ (by rfl)
have hsub0 : 2147483630#isize - 1#isize = ok 2147483629#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsubPoint : 2147483629#isize - 0#isize = ok 2147483629#isize :=
subSmall _ _ _ (Or.inl rfl) (by scalar_tac)
have hsub1 : 2147483629#isize - 1#isize = ok 2147483628#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub2 : 2147483628#isize - 1#isize = ok 2147483627#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub3 : 2147483627#isize - 1#isize = ok 2147483626#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub4 : 2147483626#isize - 1#isize = ok 2147483625#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub5 : 2147483625#isize - 1#isize = ok 2147483624#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub6 : 2147483624#isize - 1#isize = ok 2147483623#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub7 : 2147483623#isize - 1#isize = ok 2147483622#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub8 : 2147483622#isize - 1#isize = ok 2147483621#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub9 : 2147483621#isize - 1#isize = ok 2147483620#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub10 : 2147483620#isize - 1#isize = ok 2147483619#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub11 : 2147483619#isize - 1#isize = ok 2147483618#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
unfold num.imp.dec2flt.parse.adjust_many_digit_count
unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
repeat'
(rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
Slice.index_usize, hs, List.replicate_succ,
hbyteSub, hsat0, hsat1, Aeneas.Std.lift, hcast0, hcast1,
hidx0, hidx1, hidx2, hidx3, hidx4, hidx5, hidx6, hidx7,
hidx8, hidx9, hidx10, hidx11, hidx12,
hsub0, hsubPoint, hsub1, hsub2, hsub3, hsub4, hsub5, hsub6,
hsub7, hsub8, hsub9, hsub10, hsub11,
UScalar.sub, UScalar.saturating_sub,
IScalar.sub, IScalar.tryMk, IScalar.tryMkOpt, IScalar.check_bounds,
IScalar.inBounds, IScalar.min, IScalar.max,
UScalar.add, Dec2Flt.configured_x86_64_numBits])
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.NumberHelperAdjustManySourceLength
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 65536
namespace dec2flt_model
-- [TABLET NODE: ParserNumericAdjustmentCertificate]
theorem ParserNumericAdjustmentCertificate (s : Slice Std.U8)
(tail : List Std.U8)
(hs : s.val = [48#u8, 46#u8] ++
List.replicate 11 48#u8 ++ 49#u8 :: tail) :
num.imp.dec2flt.parse.adjust_many_digit_count s 2147483630#isize =
ok 2147483618#isize := by
-- BODY
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 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 hbyteSub : (48#u8 - 1#u8) = ok 47#u8 := by rfl
have hsat0 : core.num.U8.saturating_sub 46#u8 47#u8 = 0#u8 := by rfl
have hsat1 : core.num.U8.saturating_sub 48#u8 47#u8 = 1#u8 := by 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
have ha := UScalar.add_spec hmax
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists ha
rw [hz]
congr 1
apply UScalar.eq_of_val_eq
simpa [hxy] using hzval
have subSmall (x y d : Isize) (hd : d = 0#isize ∨ d = 1#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]
simp only [IScalar.min]
simpa [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] using hy.1
have hmax : x.val - d.val ≤ IScalar.max .Isize := by
rw [hxy]
simp only [IScalar.max]
have := hy.2
simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits] at this ⊢
omega
have hsub := IScalar.sub_spec (x := x) (y := d) hmin hmax
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists hsub
rw [hz]
congr 1
apply IScalar.eq_of_val_eq
simpa [hxy] using hzval
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 hidx2 : 2#usize + 1#usize = ok 3#usize := addOne _ _ (by rfl)
have hidx3 : 3#usize + 1#usize = ok 4#usize := addOne _ _ (by rfl)
have hidx4 : 4#usize + 1#usize = ok 5#usize := addOne _ _ (by rfl)
have hidx5 : 5#usize + 1#usize = ok 6#usize := addOne _ _ (by rfl)
have hidx6 : 6#usize + 1#usize = ok 7#usize := addOne _ _ (by rfl)
have hidx7 : 7#usize + 1#usize = ok 8#usize := addOne _ _ (by rfl)
have hidx8 : 8#usize + 1#usize = ok 9#usize := addOne _ _ (by rfl)
have hidx9 : 9#usize + 1#usize = ok 10#usize := addOne _ _ (by rfl)
have hidx10 : 10#usize + 1#usize = ok 11#usize := addOne _ _ (by rfl)
have hidx11 : 11#usize + 1#usize = ok 12#usize := addOne _ _ (by rfl)
have hidx12 : 12#usize + 1#usize = ok 13#usize := addOne _ _ (by rfl)
have hsub0 : 2147483630#isize - 1#isize = ok 2147483629#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsubPoint : 2147483629#isize - 0#isize = ok 2147483629#isize :=
subSmall _ _ _ (Or.inl rfl) (by scalar_tac)
have hsub1 : 2147483629#isize - 1#isize = ok 2147483628#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub2 : 2147483628#isize - 1#isize = ok 2147483627#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub3 : 2147483627#isize - 1#isize = ok 2147483626#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub4 : 2147483626#isize - 1#isize = ok 2147483625#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub5 : 2147483625#isize - 1#isize = ok 2147483624#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub6 : 2147483624#isize - 1#isize = ok 2147483623#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub7 : 2147483623#isize - 1#isize = ok 2147483622#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub8 : 2147483622#isize - 1#isize = ok 2147483621#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub9 : 2147483621#isize - 1#isize = ok 2147483620#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub10 : 2147483620#isize - 1#isize = ok 2147483619#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
have hsub11 : 2147483619#isize - 1#isize = ok 2147483618#isize :=
subSmall _ _ _ (Or.inr rfl) (by scalar_tac)
unfold num.imp.dec2flt.parse.adjust_many_digit_count
unfold num.imp.dec2flt.parse.adjust_many_digit_count_loop
repeat'
(rw [Aeneas.Std.loop.eq_1]
simp [num.imp.dec2flt.parse.adjust_many_digit_count_loop.body,
Slice.index_usize, hs, List.replicate_succ,
hbyteSub, hsat0, hsat1, Aeneas.Std.lift, hcast0, hcast1,
hidx0, hidx1, hidx2, hidx3, hidx4, hidx5, hidx6, hidx7,
hidx8, hidx9, hidx10, hidx11, hidx12,
hsub0, hsubPoint, hsub1, hsub2, hsub3, hsub4, hsub5, hsub6,
hsub7, hsub8, hsub9, hsub10, hsub11,
UScalar.sub, UScalar.saturating_sub,
IScalar.sub, IScalar.tryMk, IScalar.tryMkOpt, IScalar.check_bounds,
IScalar.inBounds, IScalar.min, IScalar.max,
UScalar.add, Dec2Flt.configured_x86_64_numBits])
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": "ParserNumericAdjustmentCertificate",
"closure_version": "patch_c_v1",
"active_decl_hash": "88ba9abe6a38283fed6d456c3874d79ebd781acbf63eb7d687882a50d9de1a5b",
"active_statement_hash": "edbbf7b119191e2d95e612db0637624a1d5eed646fd9c648c80563517c6f9a7d",
"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-126",
"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:b6b7447bbf333b81e6b7bd00be4135f218bf4fc792ae0448c7ce23b1e65c5a49",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}