Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Normal fractional retry with exact accounting
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.P367_T1_NumberHelperIntegralRetryA
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P367_T1_NumberHelperFractionalRetryA]
theorem P367_T1_NumberHelperFractionalRetryA
(start intEnd : Slice Std.U8) (explicit : Std.I64)
(integer fraction tail : List Std.U8)
(hstart : start.val = integer ++ 46#u8 :: (fraction ++ tail))
(hend : intEnd.val = 46#u8 :: (fraction ++ tail))
(hinteger : forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57)
(hfraction : forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57)
(htail : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
(hlen : start.val.length <= 3458764513820540928)
(hexpLo : -5764607523034234879 <= explicit.val)
(hexpHi : explicit.val <= 5764607523034234879) :
exists (mantissa : Std.U64) (exponent : Std.I64)
(consumed remaining : List Std.U8),
num.imp.dec2flt.parse.parse_many_digits start intEnd explicit =
ok (mantissa, exponent) /\
integer ++ fraction = consumed ++ remaining /\
mantissa.val = consumed.foldl (fun a b => 10 * a + (b.val - 48)) 0 /\
mantissa.val <= 9999999999999999999 /\
exponent.val = explicit.val - (fraction.length : Int) +
(remaining.length : Int) := 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
have hfracBound : fraction.length <= 3458764513820540928 := by
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega
have hpointTail : forall b rest,
46#u8 :: (fraction ++ tail) = b :: rest ->
¬ (48 <= b.val /\ b.val <= 57) := by
intro b rest h
cases h
norm_num
obtain ⟨rest1, value1, rem1, used1, hscan1, hpart1, hrest1,
hvalue1, hremDigits1, hremLen1, hbound1, hlow1, hsharp1⟩ :=
NumberHelperTryParse19SafeLength start 0#u64 integer
(46#u8 :: (fraction ++ tail)) hstart hinteger hpointTail (by norm_num)
by_cases hhigh : 1000000000000000000 <= value1.val
· have fold_ge_start : forall (ds : List Std.U8) (a : Nat),
a <= ds.foldl (fun x b => 10 * x + (b.val - 48)) a := by
intro ds
induction ds with
| nil => intro a; rfl
| cons b bs ih =>
intro a
have h := ih (10 * a + (b.val - 48))
simpa only [List.foldl_cons] using (show
a <= bs.foldl (fun x b => 10 * x + (b.val - 48))
(10 * a + (b.val - 48)) by omega)
have hfull : 1000000000000000000 <=
integer.foldl (fun a b => 10 * a + (b.val - 48)) 0 := by
rw [hpart1, List.foldl_append]
have hg := fold_ge_start rem1 value1.val
simpa [hvalue1] using (le_trans hhigh hg)
obtain ⟨mantissa, exponent, consumed, remaining, hparse, hpart,
hvalue, hmantissaLo, hmantissaHi, hexponent⟩ :=
P367_T1_NumberHelperIntegralRetryA start intEnd explicit integer
(46#u8 :: (fraction ++ tail)) hstart hend hinteger hpointTail
hlen hfull hexpLo hexpHi
refine ⟨mantissa, exponent, consumed, remaining ++ fraction,
hparse, ?_, hvalue, hmantissaHi, ?_⟩
· rw [hpart, List.append_assoc]
· simp only [List.length_append, Nat.cast_add]
omega
· have hrem1nil : rem1 = [] := hlow1 (by omega)
have hused1 : used1 = integer := by simpa [hrem1nil] using hpart1.symm
have hrest1val : rest1.val = 46#u8 :: (fraction ++ tail) := by
simpa [hrem1nil] using hrest1
have hfracLen : (fraction ++ tail).length <= start.val.length := by
rw [hstart]
simp only [List.length_append, List.length_cons]
omega
let fractional : Slice Std.U8 :=
⟨fraction ++ tail, le_trans hfracLen start.property⟩
have hdrop : core.slice.index.SliceIndexRangeFromUsizeSlice.index
(T := Std.U8) { start := 1#usize } rest1 = ok fractional := by
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, hrest1val, fractional]
obtain ⟨rest2, value2, rem2, used2, hscan2, hpart2, hrest2,
hvalue2, hremDigits2, hremLen2, hbound2, hlow2, hsharp2⟩ :=
NumberHelperTryParse19SafeLength fractional value1 fraction tail
rfl hfraction htail hbound1
have hrest2Len : rest2.val.length <= fractional.val.length := by
have hp := congrArg List.length hpart2
simp only [List.length_append] at hp
simp only [hrest2, fractional, List.length_append]
omega
obtain ⟨offset, hoffset, hoffsetVal⟩ :=
P364_T1_NumberHelperOffsetSourceLength fractional rest2
(by dsimp [fractional]; omega) hrest2Len
have hoffsetExact : offset.val =
(fraction.length : Int) - (rem2.length : Int) := by
simp only [fractional, hrest2, List.length_append, Nat.cast_add]
at hoffsetVal
omega
have hnotmin : offset.val ≠ IScalar.min .Isize := by
rw [hoffsetExact, IScalar.min]
norm_num [IScalarTy.numBits, Dec2Flt.P340_T1_selected_target_numBits]
omega
obtain ⟨negOffset, hneg, hnegVal⟩ := Aeneas.Std.WP.spec_imp_exists
(HNeg.hNeg.step offset hnotmin)
have hcastBounds : IScalar.min .I64 <= negOffset.val /\
negOffset.val <= IScalar.max .I64 := by
simp only [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
rw [hnegVal, hoffsetExact]
omega
obtain ⟨base, hcast, hbase⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.cast_inBounds_spec .I64 negOffset hcastBounds)
obtain ⟨exponent, hadd, hexponent⟩ :=
P367_T1_NumberHelperExponentAddA base explicit
(by rw [hbase, hnegVal, hoffsetExact]; omega)
(by rw [hbase, hnegVal, hoffsetExact]; omega) hexpLo hexpHi
refine ⟨value2, exponent, integer ++ used2, rem2, ?_, ?_, ?_,
hbound2, ?_⟩
· simp [num.imp.dec2flt.parse.parse_many_digits, hscan1,
num.imp.dec2flt.parse.MIN_19DIGIT_INT, hhigh, hdrop, hscan2,
hoffset, hneg, hcast, hadd]
· rw [hpart2, List.append_assoc]
· simp only [List.foldl_append]
simpa [hused1, hvalue1] using hvalue2
· rw [hexponent, hbase, hnegVal, hoffsetExact]
omega
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P367_T1_NumberHelperIntegralRetryA
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P367_T1_NumberHelperFractionalRetryA]
theorem P367_T1_NumberHelperFractionalRetryA
(start intEnd : Slice Std.U8) (explicit : Std.I64)
(integer fraction tail : List Std.U8)
(hstart : start.val = integer ++ 46#u8 :: (fraction ++ tail))
(hend : intEnd.val = 46#u8 :: (fraction ++ tail))
(hinteger : forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57)
(hfraction : forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57)
(htail : forall b rest, tail = b :: rest -> ¬ (48 <= b.val /\ b.val <= 57))
(hlen : start.val.length <= 3458764513820540928)
(hexpLo : -5764607523034234879 <= explicit.val)
(hexpHi : explicit.val <= 5764607523034234879) :
exists (mantissa : Std.U64) (exponent : Std.I64)
(consumed remaining : List Std.U8),
num.imp.dec2flt.parse.parse_many_digits start intEnd explicit =
ok (mantissa, exponent) /\
integer ++ fraction = consumed ++ remaining /\
mantissa.val = consumed.foldl (fun a b => 10 * a + (b.val - 48)) 0 /\
mantissa.val <= 9999999999999999999 /\
exponent.val = explicit.val - (fraction.length : Int) +
(remaining.length : Int) := by
-- BODY
have hfracBound : fraction.length <= 3458764513820540928 := by
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega
have hpointTail : forall b rest,
46#u8 :: (fraction ++ tail) = b :: rest ->
¬ (48 <= b.val /\ b.val <= 57) := by
intro b rest h
cases h
norm_num
obtain ⟨rest1, value1, rem1, used1, hscan1, hpart1, hrest1,
hvalue1, hremDigits1, hremLen1, hbound1, hlow1, hsharp1⟩ :=
NumberHelperTryParse19SafeLength start 0#u64 integer
(46#u8 :: (fraction ++ tail)) hstart hinteger hpointTail (by norm_num)
by_cases hhigh : 1000000000000000000 <= value1.val
· have fold_ge_start : forall (ds : List Std.U8) (a : Nat),
a <= ds.foldl (fun x b => 10 * x + (b.val - 48)) a := by
intro ds
induction ds with
| nil => intro a; rfl
| cons b bs ih =>
intro a
have h := ih (10 * a + (b.val - 48))
simpa only [List.foldl_cons] using (show
a <= bs.foldl (fun x b => 10 * x + (b.val - 48))
(10 * a + (b.val - 48)) by omega)
have hfull : 1000000000000000000 <=
integer.foldl (fun a b => 10 * a + (b.val - 48)) 0 := by
rw [hpart1, List.foldl_append]
have hg := fold_ge_start rem1 value1.val
simpa [hvalue1] using (le_trans hhigh hg)
obtain ⟨mantissa, exponent, consumed, remaining, hparse, hpart,
hvalue, hmantissaLo, hmantissaHi, hexponent⟩ :=
P367_T1_NumberHelperIntegralRetryA start intEnd explicit integer
(46#u8 :: (fraction ++ tail)) hstart hend hinteger hpointTail
hlen hfull hexpLo hexpHi
refine ⟨mantissa, exponent, consumed, remaining ++ fraction,
hparse, ?_, hvalue, hmantissaHi, ?_⟩
· rw [hpart, List.append_assoc]
· simp only [List.length_append, Nat.cast_add]
omega
· have hrem1nil : rem1 = [] := hlow1 (by omega)
have hused1 : used1 = integer := by simpa [hrem1nil] using hpart1.symm
have hrest1val : rest1.val = 46#u8 :: (fraction ++ tail) := by
simpa [hrem1nil] using hrest1
have hfracLen : (fraction ++ tail).length <= start.val.length := by
rw [hstart]
simp only [List.length_append, List.length_cons]
omega
let fractional : Slice Std.U8 :=
⟨fraction ++ tail, le_trans hfracLen start.property⟩
have hdrop : core.slice.index.SliceIndexRangeFromUsizeSlice.index
(T := Std.U8) { start := 1#usize } rest1 = ok fractional := by
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, hrest1val, fractional]
obtain ⟨rest2, value2, rem2, used2, hscan2, hpart2, hrest2,
hvalue2, hremDigits2, hremLen2, hbound2, hlow2, hsharp2⟩ :=
NumberHelperTryParse19SafeLength fractional value1 fraction tail
rfl hfraction htail hbound1
have hrest2Len : rest2.val.length <= fractional.val.length := by
have hp := congrArg List.length hpart2
simp only [List.length_append] at hp
simp only [hrest2, fractional, List.length_append]
omega
obtain ⟨offset, hoffset, hoffsetVal⟩ :=
P364_T1_NumberHelperOffsetSourceLength fractional rest2
(by dsimp [fractional]; omega) hrest2Len
have hoffsetExact : offset.val =
(fraction.length : Int) - (rem2.length : Int) := by
simp only [fractional, hrest2, List.length_append, Nat.cast_add]
at hoffsetVal
omega
have hnotmin : offset.val ≠ IScalar.min .Isize := by
rw [hoffsetExact, IScalar.min]
norm_num [IScalarTy.numBits, Dec2Flt.P340_T1_selected_target_numBits]
omega
obtain ⟨negOffset, hneg, hnegVal⟩ := Aeneas.Std.WP.spec_imp_exists
(HNeg.hNeg.step offset hnotmin)
have hcastBounds : IScalar.min .I64 <= negOffset.val /\
negOffset.val <= IScalar.max .I64 := by
simp only [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
rw [hnegVal, hoffsetExact]
omega
obtain ⟨base, hcast, hbase⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.cast_inBounds_spec .I64 negOffset hcastBounds)
obtain ⟨exponent, hadd, hexponent⟩ :=
P367_T1_NumberHelperExponentAddA base explicit
(by rw [hbase, hnegVal, hoffsetExact]; omega)
(by rw [hbase, hnegVal, hoffsetExact]; omega) hexpLo hexpHi
refine ⟨value2, exponent, integer ++ used2, rem2, ?_, ?_, ?_,
hbound2, ?_⟩
· simp [num.imp.dec2flt.parse.parse_many_digits, hscan1,
num.imp.dec2flt.parse.MIN_19DIGIT_INT, hhigh, hdrop, hscan2,
hoffset, hneg, hcast, hadd]
· rw [hpart2, List.append_assoc]
· simp only [List.foldl_append]
simpa [hused1, hvalue1] using hvalue2
· rw [hexponent, hbase, hnegVal, hoffsetExact]
omega
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (50)
- parse_many_digits · dec2flt/parse.rs:104 Program Rust
- offset_from · dec2flt/common.rs:34 Program Rust
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
More program dependencies (17)
- try_parse_19digits · dec2flt/parse.rs:61 Program Rust
- try_parse_19digits_loop · dec2flt/parse.rs:64 Program Rust
- body · dec2flt/parse.rs:64 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:56 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 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)
- split_first · core/src/slice/mod.rs:198 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
- 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
- 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.P340_T1_selected_target_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
All 38 entries
- Binary64Model
- Binary64ModelDefault
- F64
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- NumberHelperTryParse19SafeLength
- NumberHelperOffsetSourceLength
- NumberHelperExponentAddA
- NumberHelperFractionalRetryA
- NumberHelperIntegralRetryA
- Preamble
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- core num FpCategory
- num imp dec2flt parse MIN 19DIGIT INT
- num imp dec2flt parse parse many digits
- num imp dec2flt parse try parse 19digits
Technical checking records
Local closure summary
{
"node": "P367_T1_NumberHelperFractionalRetryA",
"closure_version": "patch_c_v1",
"active_decl_hash": "586023820c11f25e444cd95d62cdb2f986000c4f361d3b6ea59a58eabb3f745c",
"active_statement_hash": "e5234d0b210573df8f18daa82af1c805f8e0cfe3f05e4e0ec36ecb96d9e87c84",
"kernel_axioms": [
"Classical.choice",
"Dec2Flt.P340_T1_selected_target_numBits",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-181",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperTryParse19SafeLength": "dd334c60b1e032a8",
"P364_T1_NumberHelperOffsetSourceLength": "de0168dfeba3b802",
"P367_T1_NumberHelperExponentAddA": "cd7f7391f1891168",
"P367_T1_NumberHelperIntegralRetryA": "d66d59fc5c9acf83",
"num_imp_dec2flt_parse_MIN_19DIGIT_INT": "de62bc3f1baba809",
"num_imp_dec2flt_parse_parse_many_digits": "0f3e5cc6a65d812e"
},
"strict_definition_deps": {
"SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
"num_imp_dec2flt_parse_MIN_19DIGIT_INT": "476edc5502ff7bfb",
"num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
"num_imp_dec2flt_parse_try_parse_19digits": "c9c74554a359a9c4"
}
}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:6404b5f6f988f2ee504742d55ab0830dd9d9a361979b7cc3b50763b51cbf3a18",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}