Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Exact exponent continuation at the significand end
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.P9_T1_ScientificVocabularyFold
import Tablet.NumberHelperScientificRenderedSuffixSafeLength
import Tablet.P435_T1_DigitDecoding
import Tablet.ModelSliceSplitFirst
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P789_T1_RenderedExponentContinuation]
theorem P789_T1_RenderedExponentContinuation
(x : DecimalLexeme) (sigEnd : Slice Std.U8) (digits : List Std.U8)
(hvalid : DecimalGoalVocabularyDefault.validNumeric x)
(hmap : digits.map (fun b => b.val) =
(match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d))
(hdigits : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57)
(hend : sigEnd.val = match x.exponent with
| none => []
| some (upper, sign, _) => (if upper then 69#u8 else 101#u8) ::
(match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ digits) :
exists explicit : Std.I64,
explicit.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x /\
-5764607523034234879 <= explicit.val /\ explicit.val <= 5764607523034234879 /\
((sigEnd.val = [] /\ explicit = 0#i64) \/
exists (marker : Std.U8) (next rest : Slice Std.U8),
core.slice.Slice.split_first sigEnd = ok (some (marker, next)) /\
(marker = 101#u8 \/ marker = 69#u8) /\
num.imp.dec2flt.parse.parse_scientific next = ok (some explicit, rest) /\
rest.val = []) := 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
cases hx : x.exponent with
| none =>
refine ⟨0#i64, ?_, by norm_num, by norm_num, Or.inl ⟨?_, rfl⟩⟩
· simp [DecimalGoalVocabularyDefault, hx]
· simpa [hx] using hend
| some tuple =>
rcases tuple with ⟨upper, sign, ds⟩
have hv : ds ≠ [] /\ forall d, d ∈ ds -> d < 10 := by
have hv := (show _ ∧ _ ∧ _ ∧ _ from hvalid).2.2.2
simpa [hx] using hv
have hm : digits.map (fun b => b.val) = ds.map (fun d => 48 + d) := by
simpa [hx] using hmap
obtain ⟨hdecode, hlength, _⟩ := (P435_T1_DigitDecoding digits).2 ds hm
have hne : digits != [] := by
simp only [bne_iff_ne]
intro he
have : ds.length = 0 := by simpa [he] using hlength.symm
exact hv.1 (List.eq_nil_of_length_eq_zero this)
let suffix := (match sign with
| none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ digits
have hs : sigEnd.val = (if upper then 69#u8 else 101#u8) :: suffix := by
cases sign <;> simpa [hx, suffix] using hend
have hlen : suffix.length <= Usize.max := by
have h := sigEnd.property
rw [hs] at h
simp only [List.length_cons] at h
omega
let next : Slice Std.U8 := ⟨suffix, hlen⟩
have hsplit : core.slice.Slice.split_first sigEnd =
ok (some ((if upper then 69#u8 else 101#u8), next)) := by
let shaped : Slice Std.U8 := ⟨(if upper then 69#u8 else 101#u8) :: suffix,
by rw [← hs]; exact sigEnd.property⟩
have hEq : sigEnd = shaped := (Slice.eq_iff _ _).2 hs
rw [hEq]
rfl
have hmapNext : next.val.map (fun b => b.val) =
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun d => 48 + d) := by
cases sign with
| none => simpa [next, suffix] using hm
| some neg => cases neg <;> simp [next, suffix, hm]
obtain ⟨explicit, rest, hparse, hrest, hlo, hhi, _, _⟩ :=
NumberHelperScientificRenderedSuffixSafeLength next sign ds
(by simpa only [bne_iff_ne] using hv.1) hv.2 hmapNext
obtain ⟨foldExponent, foldRest, hfoldParse, _, hfold⟩ :=
P9_T1_ScientificVocabularyFold next sign digits [] hne hdigits
(by simp) (by cases sign <;> simp [next, suffix])
have heq : (some foldExponent, foldRest) = (some explicit, rest) :=
Result.ok.inj (hfoldParse.symm.trans hparse)
have he : foldExponent = explicit := Option.some.inj (congrArg Prod.fst heq)
rw [he, hdecode] at hfold
refine ⟨explicit, ?_, hlo, hhi, Or.inr ⟨_, next, rest, hsplit, ?_, hparse, hrest⟩⟩
· cases sign with
| none => simpa [DecimalGoalVocabularyDefault, hx] using hfold
| some neg => cases neg <;> simpa [DecimalGoalVocabularyDefault, hx] using hfold
· cases upper <;> simp
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P9_T1_ScientificVocabularyFold
import Tablet.NumberHelperScientificRenderedSuffixSafeLength
import Tablet.P435_T1_DigitDecoding
import Tablet.ModelSliceSplitFirst
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P789_T1_RenderedExponentContinuation]
theorem P789_T1_RenderedExponentContinuation
(x : DecimalLexeme) (sigEnd : Slice Std.U8) (digits : List Std.U8)
(hvalid : DecimalGoalVocabularyDefault.validNumeric x)
(hmap : digits.map (fun b => b.val) =
(match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d))
(hdigits : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57)
(hend : sigEnd.val = match x.exponent with
| none => []
| some (upper, sign, _) => (if upper then 69#u8 else 101#u8) ::
(match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ digits) :
exists explicit : Std.I64,
explicit.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x /\
-5764607523034234879 <= explicit.val /\ explicit.val <= 5764607523034234879 /\
((sigEnd.val = [] /\ explicit = 0#i64) \/
exists (marker : Std.U8) (next rest : Slice Std.U8),
core.slice.Slice.split_first sigEnd = ok (some (marker, next)) /\
(marker = 101#u8 \/ marker = 69#u8) /\
num.imp.dec2flt.parse.parse_scientific next = ok (some explicit, rest) /\
rest.val = []) := by
-- BODY
cases hx : x.exponent with
| none =>
refine ⟨0#i64, ?_, by norm_num, by norm_num, Or.inl ⟨?_, rfl⟩⟩
· simp [DecimalGoalVocabularyDefault, hx]
· simpa [hx] using hend
| some tuple =>
rcases tuple with ⟨upper, sign, ds⟩
have hv : ds ≠ [] /\ forall d, d ∈ ds -> d < 10 := by
have hv := (show _ ∧ _ ∧ _ ∧ _ from hvalid).2.2.2
simpa [hx] using hv
have hm : digits.map (fun b => b.val) = ds.map (fun d => 48 + d) := by
simpa [hx] using hmap
obtain ⟨hdecode, hlength, _⟩ := (P435_T1_DigitDecoding digits).2 ds hm
have hne : digits != [] := by
simp only [bne_iff_ne]
intro he
have : ds.length = 0 := by simpa [he] using hlength.symm
exact hv.1 (List.eq_nil_of_length_eq_zero this)
let suffix := (match sign with
| none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ digits
have hs : sigEnd.val = (if upper then 69#u8 else 101#u8) :: suffix := by
cases sign <;> simpa [hx, suffix] using hend
have hlen : suffix.length <= Usize.max := by
have h := sigEnd.property
rw [hs] at h
simp only [List.length_cons] at h
omega
let next : Slice Std.U8 := ⟨suffix, hlen⟩
have hsplit : core.slice.Slice.split_first sigEnd =
ok (some ((if upper then 69#u8 else 101#u8), next)) := by
let shaped : Slice Std.U8 := ⟨(if upper then 69#u8 else 101#u8) :: suffix,
by rw [← hs]; exact sigEnd.property⟩
have hEq : sigEnd = shaped := (Slice.eq_iff _ _).2 hs
rw [hEq]
rfl
have hmapNext : next.val.map (fun b => b.val) =
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun d => 48 + d) := by
cases sign with
| none => simpa [next, suffix] using hm
| some neg => cases neg <;> simp [next, suffix, hm]
obtain ⟨explicit, rest, hparse, hrest, hlo, hhi, _, _⟩ :=
NumberHelperScientificRenderedSuffixSafeLength next sign ds
(by simpa only [bne_iff_ne] using hv.1) hv.2 hmapNext
obtain ⟨foldExponent, foldRest, hfoldParse, _, hfold⟩ :=
P9_T1_ScientificVocabularyFold next sign digits [] hne hdigits
(by simp) (by cases sign <;> simp [next, suffix])
have heq : (some foldExponent, foldRest) = (some explicit, rest) :=
Result.ok.inj (hfoldParse.symm.trans hparse)
have he : foldExponent = explicit := Option.some.inj (congrArg Prod.fst heq)
rw [he, hdecode] at hfold
refine ⟨explicit, ?_, hlo, hhi, Or.inr ⟨_, next, rest, hsplit, ?_, hparse, hrest⟩⟩
· cases sign with
| none => simpa [DecimalGoalVocabularyDefault, hx] using hfold
| some neg => cases neg <;> simpa [DecimalGoalVocabularyDefault, hx] using hfold
· cases upper <;> simp
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (47)
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
More program dependencies (14)
- 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
- parse_scientific · dec2flt/parse.rs:121 Program Rust
- parse_scientific_loop · dec2flt/parse.rs:145 Program Rust
- body · dec2flt/parse.rs:145 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 43 entries
- Binary64Model
- Binary64ModelDefault
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- 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
- NumberHelperScientificPrefixSafeLength
- NumberHelperScientificRenderedSuffixSafeLength
- NumberHelperSplitExponentSuffix
- DigitDecoding
- RenderedExponentContinuation
- ScientificLoopFold
- ScientificScannerFold
- ScientificVocabularyFold
- Preamble
- core num FpCategory
- num imp dec2flt common BiasedFp
- num imp dec2flt decimal Decimal
- num imp dec2flt parse parse scientific
Technical checking records
Local closure summary
{
"node": "P789_T1_RenderedExponentContinuation",
"closure_version": "patch_c_v1",
"active_decl_hash": "1d33485a4b41e31c7d485a97e131c1f8e1d8c06648cca57d3142184cba52546e",
"active_statement_hash": "29baa4a8ce4837d06acbf91ff05329f19e7cde08bc4df3a690946c969d7c199f",
"kernel_axioms": [
"Classical.choice",
"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-182",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
"NumberHelperScientificRenderedSuffixSafeLength": "e9bebcd7a1b030d2",
"P435_T1_DigitDecoding": "0b69e5fe3215de46",
"P9_T1_ScientificVocabularyFold": "b4e9d9d3618cb9a8"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "c08dd4b4aea4abb4",
"DecimalGoalVocabularyDefault": "b9386c8d0fd53e6e",
"DecimalLexeme": "8127b3eaeae00dd2",
"F64": "ec4e25fbaf4e11d4",
"P9_T1_ScientificVocabularyFold": "28ca0a8ac503ee01",
"Preamble": "965f15fc36f80938",
"num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
"num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
"num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5"
}
}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:520dded0002ded2ae546d8259aae0750ecd5cc7b7923058771ac12265a365bd5",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}