Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Helper · Exact nineteen-digit retry
first consist of eleven ASCII zeros, the 19-byte word
1000000000000000080, and 2{,}147{,}483{,}618 further ASCII zeros.
Then the extracted try_parse_19digits call from accumulator zero
returns mantissa 1{,}000{,}000{,}000{,}000{,}000{,}080 and a residual slice
consisting exactly of the final replicated zeros.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.NumberHelperTryParse19SafeLength
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 65536
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: ParserNumericTry19Certificate]
theorem ParserNumericTry19Certificate (first : Slice Std.U8)
(hfirst : first.val = List.replicate 11 48#u8 ++
[49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
List.replicate 2147483618 48#u8) :
exists rest : Slice Std.U8,
rest.val = List.replicate 2147483618 48#u8 /\
num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
ok (rest, 1000000000000000080#u64) := 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 hdigits : forall b, List.Mem b first.val ->
48 <= b.val /\ b.val <= 57 := by
as_aux_lemma =>
intro b hb
rw [hfirst] at hb
rcases List.mem_append.mp hb with hb | hb
· rcases List.mem_append.mp hb with hb | hb
· rw [List.mem_replicate] at hb
rcases hb with ⟨_, rfl⟩
norm_num
· simp only [List.mem_cons, List.not_mem_nil, or_false] at hb
rcases hb with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl |
rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
norm_num
· rw [List.mem_replicate] at hb
rcases hb with ⟨_, rfl⟩
norm_num
have htail : forall b rest, ([] : List Std.U8) = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest h
simp at h
obtain ⟨rest, mantissa, remaining, consumed, hparse, hpartition,
hrest, hvalue, hremaining, hremainingLen, hmantissa, hlow, hsharp⟩ :=
NumberHelperTryParse19SafeLength first 0#u64 first.val [] (by simp)
hdigits htail (by norm_num)
let digitStep : Nat -> Std.U8 -> Nat :=
fun a b => 10 * a + (b.val - 48)
change mantissa.val = consumed.foldl digitStep 0 at hvalue
have fold_ge_start : forall (l : List Std.U8) (a : Nat),
a <= l.foldl digitStep a := by
as_aux_lemma =>
intro l
induction l with
| nil => intro a; simp
| cons b bs ih =>
intro a
simp only [List.foldl_cons]
exact le_trans (by simp [digitStep]; omega) (ih _)
have fold_prefix_mono : forall (l1 l2 : List Std.U8),
l1 <+: l2 -> l1.foldl digitStep 0 <= l2.foldl digitStep 0 := by
as_aux_lemma =>
intro l1 l2 hp
rcases hp with ⟨suffix, hsuffix⟩
rw [← hsuffix, List.foldl_append]
exact fold_ge_start suffix _
have hconsumedTake : consumed = first.val.take consumed.length := by
calc
consumed = (consumed ++ remaining).take consumed.length := by
rw [List.take_left]
_ = first.val.take consumed.length := by rw [hpartition]
have hdigitsLen : first.val.length = 2147483648 := by
rw [hfirst]
simp only [List.length_append, List.length_replicate, List.length_cons,
List.length_nil]
have hfold29 : (first.val.take 29).foldl digitStep 0 =
100000000000000008 := by
as_aux_lemma =>
rw [hfirst]
have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
norm_num [digitStep, List.replicate_succ]
norm_num [digitStep, List.take_append, hz]
have hfold30 : (first.val.take 30).foldl digitStep 0 =
1000000000000000080 := by
as_aux_lemma =>
rw [hfirst]
have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
norm_num [digitStep, List.replicate_succ]
norm_num [digitStep, List.take_append, hz]
have hfold31 : (first.val.take 31).foldl digitStep 0 =
10000000000000000800 := by
as_aux_lemma =>
rw [hfirst]
have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
norm_num [digitStep, List.replicate_succ]
norm_num [digitStep, List.take_append, hz]
have hconsumedLower : 30 <= consumed.length := by
by_contra hn
have hlen29 : consumed.length <= 29 := by omega
have hp : consumed <+: first.val.take 29 := by
rw [hconsumedTake]
exact List.take_prefix_take_left hlen29
have hmle := fold_prefix_mono consumed (first.val.take 29) hp
rw [hfold29] at hmle
have hmlow : mantissa.val < 1000000000000000000 := by
rw [hvalue]
omega
have hremnil := hlow hmlow
have hlenEq := congrArg List.length hpartition
rw [hremnil] at hlenEq
simp only [List.length_append, List.length_nil, Nat.add_zero] at hlenEq
rw [hdigitsLen] at hlenEq
omega
have hconsumedUpper : consumed.length <= 30 := by
by_contra hn
have hlen31 : 31 <= consumed.length := by omega
have hp : first.val.take 31 <+: consumed := by
rw [hconsumedTake]
exact List.take_prefix_take_left hlen31
have hmge := fold_prefix_mono (first.val.take 31) consumed hp
rw [hfold31, ← hvalue] at hmge
omega
have hconsumedLen : consumed.length = 30 := by omega
have hprefix : first.val.take 30 = List.replicate 11 48#u8 ++
[49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
rw [hfirst]
norm_num [List.take_append]
have hconsumed : consumed = List.replicate 11 48#u8 ++
[49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
rw [hconsumedTake, hconsumedLen, hprefix]
have hremainingEq : remaining = List.replicate 2147483618 48#u8 := by
rw [hfirst, hconsumed] at hpartition
exact (List.append_cancel_left hpartition).symm
have hmantissaEq : mantissa = 1000000000000000080#u64 := by
apply UScalar.eq_of_val_eq
rw [hvalue, hconsumedTake, hconsumedLen, hfold30]
norm_num
have hrestEq : rest.val = List.replicate 2147483618 48#u8 := by
calc
rest.val = remaining ++ [] := hrest
_ = remaining := List.append_nil _
_ = List.replicate 2147483618 48#u8 := hremainingEq
have hparseEq :
num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
ok (rest, 1000000000000000080#u64) := by
calc
num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
ok (rest, mantissa) := hparse
_ = ok (rest, 1000000000000000080#u64) := by rw [hmantissaEq]
exact ⟨rest, hrestEq, hparseEq⟩
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.NumberHelperTryParse19SafeLength
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 65536
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: ParserNumericTry19Certificate]
theorem ParserNumericTry19Certificate (first : Slice Std.U8)
(hfirst : first.val = List.replicate 11 48#u8 ++
[49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
List.replicate 2147483618 48#u8) :
exists rest : Slice Std.U8,
rest.val = List.replicate 2147483618 48#u8 /\
num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
ok (rest, 1000000000000000080#u64) := by
-- BODY
have hdigits : forall b, List.Mem b first.val ->
48 <= b.val /\ b.val <= 57 := by
as_aux_lemma =>
intro b hb
rw [hfirst] at hb
rcases List.mem_append.mp hb with hb | hb
· rcases List.mem_append.mp hb with hb | hb
· rw [List.mem_replicate] at hb
rcases hb with ⟨_, rfl⟩
norm_num
· simp only [List.mem_cons, List.not_mem_nil, or_false] at hb
rcases hb with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl |
rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
norm_num
· rw [List.mem_replicate] at hb
rcases hb with ⟨_, rfl⟩
norm_num
have htail : forall b rest, ([] : List Std.U8) = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest h
simp at h
obtain ⟨rest, mantissa, remaining, consumed, hparse, hpartition,
hrest, hvalue, hremaining, hremainingLen, hmantissa, hlow, hsharp⟩ :=
NumberHelperTryParse19SafeLength first 0#u64 first.val [] (by simp)
hdigits htail (by norm_num)
let digitStep : Nat -> Std.U8 -> Nat :=
fun a b => 10 * a + (b.val - 48)
change mantissa.val = consumed.foldl digitStep 0 at hvalue
have fold_ge_start : forall (l : List Std.U8) (a : Nat),
a <= l.foldl digitStep a := by
as_aux_lemma =>
intro l
induction l with
| nil => intro a; simp
| cons b bs ih =>
intro a
simp only [List.foldl_cons]
exact le_trans (by simp [digitStep]; omega) (ih _)
have fold_prefix_mono : forall (l1 l2 : List Std.U8),
l1 <+: l2 -> l1.foldl digitStep 0 <= l2.foldl digitStep 0 := by
as_aux_lemma =>
intro l1 l2 hp
rcases hp with ⟨suffix, hsuffix⟩
rw [← hsuffix, List.foldl_append]
exact fold_ge_start suffix _
have hconsumedTake : consumed = first.val.take consumed.length := by
calc
consumed = (consumed ++ remaining).take consumed.length := by
rw [List.take_left]
_ = first.val.take consumed.length := by rw [hpartition]
have hdigitsLen : first.val.length = 2147483648 := by
rw [hfirst]
simp only [List.length_append, List.length_replicate, List.length_cons,
List.length_nil]
have hfold29 : (first.val.take 29).foldl digitStep 0 =
100000000000000008 := by
as_aux_lemma =>
rw [hfirst]
have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
norm_num [digitStep, List.replicate_succ]
norm_num [digitStep, List.take_append, hz]
have hfold30 : (first.val.take 30).foldl digitStep 0 =
1000000000000000080 := by
as_aux_lemma =>
rw [hfirst]
have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
norm_num [digitStep, List.replicate_succ]
norm_num [digitStep, List.take_append, hz]
have hfold31 : (first.val.take 31).foldl digitStep 0 =
10000000000000000800 := by
as_aux_lemma =>
rw [hfirst]
have hz : (List.replicate 11 48#u8).foldl digitStep 0 = 0 := by
norm_num [digitStep, List.replicate_succ]
norm_num [digitStep, List.take_append, hz]
have hconsumedLower : 30 <= consumed.length := by
by_contra hn
have hlen29 : consumed.length <= 29 := by omega
have hp : consumed <+: first.val.take 29 := by
rw [hconsumedTake]
exact List.take_prefix_take_left hlen29
have hmle := fold_prefix_mono consumed (first.val.take 29) hp
rw [hfold29] at hmle
have hmlow : mantissa.val < 1000000000000000000 := by
rw [hvalue]
omega
have hremnil := hlow hmlow
have hlenEq := congrArg List.length hpartition
rw [hremnil] at hlenEq
simp only [List.length_append, List.length_nil, Nat.add_zero] at hlenEq
rw [hdigitsLen] at hlenEq
omega
have hconsumedUpper : consumed.length <= 30 := by
by_contra hn
have hlen31 : 31 <= consumed.length := by omega
have hp : first.val.take 31 <+: consumed := by
rw [hconsumedTake]
exact List.take_prefix_take_left hlen31
have hmge := fold_prefix_mono (first.val.take 31) consumed hp
rw [hfold31, ← hvalue] at hmge
omega
have hconsumedLen : consumed.length = 30 := by omega
have hprefix : first.val.take 30 = List.replicate 11 48#u8 ++
[49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
rw [hfirst]
norm_num [List.take_append]
have hconsumed : consumed = List.replicate 11 48#u8 ++
[49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
48#u8, 48#u8, 48#u8, 56#u8, 48#u8] := by
rw [hconsumedTake, hconsumedLen, hprefix]
have hremainingEq : remaining = List.replicate 2147483618 48#u8 := by
rw [hfirst, hconsumed] at hpartition
exact (List.append_cancel_left hpartition).symm
have hmantissaEq : mantissa = 1000000000000000080#u64 := by
apply UScalar.eq_of_val_eq
rw [hvalue, hconsumedTake, hconsumedLen, hfold30]
norm_num
have hrestEq : rest.val = List.replicate 2147483618 48#u8 := by
calc
rest.val = remaining ++ [] := hrest
_ = remaining := List.append_nil _
_ = List.replicate 2147483618 48#u8 := hremainingEq
have hparseEq :
num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
ok (rest, 1000000000000000080#u64) := by
calc
num.imp.dec2flt.parse.try_parse_19digits first 0#u64 =
ok (rest, mantissa) := hparse
_ = ok (rest, 1000000000000000080#u64) := by rw [hmantissaEq]
exact ⟨rest, hrestEq, hparseEq⟩
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (48)
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- try_parse_19digits · dec2flt/parse.rs:61 Program Rust
- try_parse_19digits_loop · dec2flt/parse.rs:64 Program Rust
More program dependencies (15)
- 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: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)
- 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
- 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 33 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
- ParserNumericTry19Certificate
- Preamble
- core num FpCategory
- num imp dec2flt parse MIN 19DIGIT INT
- num imp dec2flt parse try parse 19digits
Technical checking records
Local closure summary
{
"node": "ParserNumericTry19Certificate",
"closure_version": "patch_c_v1",
"active_decl_hash": "334435a85620a7dfe3ef510e91e7dc1477eff532655032923272735ca790b28b",
"active_statement_hash": "be14fde324d21382a879b2b6ac66de7b10ad45b3cff862bacef210f554f3aa5a",
"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-126",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperTryParse19SafeLength": "dd334c60b1e032a8"
},
"strict_definition_deps": {
"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:d8451c078a1fd8cee6d8876a2e6ee509303109c494714bf272b0b37da8d89b81",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}