Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Actual optional exponent operand
parse_scientific, and return the option's value or I64 zero;
return I64 zero for other heads. This is the monadic expression in the
paired statement. It returns normally with e satisfying
e.\mathit{val}=\texttt{accumulatedExplicitExponent}(x).
There is no source-length, A/B, or nonzero-significand hypothesis.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.NumberHelperSplitExponentSuffix
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P495_T1_ExponentSuffix]
theorem P495_T1_ExponentSuffix (s : Slice Std.U8) (x : DecimalLexeme)
(hvalid : DecimalGoalVocabularyDefault.validNumeric x)
(hs : s.val.map (fun b => b.val) = match x.exponent with
| none => []
| some (upper, sign, ds) =>
(if upper then 69 else 101) ::
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun z => 48 + z)) :
let explicitCall : Result Std.I64 := do
let empty <- core.slice.Slice.is_empty s
if empty then ok 0#i64 else
let ch <- Slice.index_usize s 0#usize
if ch = 101#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else if ch = 69#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else ok 0#i64
exists e : Std.I64, explicitCall = ok e /\
e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x := 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
let explicitCall : Result Std.I64 := do
let empty <- core.slice.Slice.is_empty s
if empty then ok 0#i64 else
let ch <- Slice.index_usize s 0#usize
if ch = 101#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else if ch = 69#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else ok 0#i64
change ∃ e : Std.I64, explicitCall = ok e ∧
e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
cases hx : x.exponent with
| none =>
have hs0 : s.val.map (fun b => b.val) = [] := by simpa [hx] using hs
cases hsv : s.val with
| nil =>
have hlen : s.val.length = 0 := by simp [hsv]
have hempty : core.slice.Slice.is_empty s = ok true := by
simp [core.slice.Slice.is_empty, hlen]
refine ⟨0#i64, ?_, ?_⟩
· simp [explicitCall, hempty, hsv]
· simp [DecimalGoalVocabularyDefault, hx]
| cons b bs => simp [hsv] at hs0
| some ex =>
rcases ex with ⟨upper, sign, ds⟩
simp [DecimalGoalVocabularyDefault, hx] at hvalid
rcases hvalid with ⟨_, _, _, hne, hd⟩
have hmap : s.val.map (fun b => b.val) =
(if upper then 69 else 101) ::
((match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun z => 48 + z)) := by
simpa [hx] using hs
cases hsv : s.val with
| nil => simp [hsv] at hmap
| cons b bs =>
obtain ⟨b', bs', hcons, hbmap, hbsmap⟩ :=
List.map_eq_cons_iff.mp hmap
have hbb : b = b' := by
rw [hsv] at hcons
injection hcons
have hbs' : bs = bs' := by
rw [hsv] at hcons
injection hcons with hhead htail
have hb : b = (if upper then 69#u8 else 101#u8) := by
apply UScalar.eq_of_val_eq
have hnum : (if upper then 69#u8 else 101#u8).val =
(if upper then 69 else 101) := by cases upper <;> rfl
rw [hbb, hnum]
exact hbmap
have hbsmap' : bs'.map (fun c => c.val) =
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun z => 48 + z) := by simpa using hbsmap
obtain ⟨dbs, hsplit, hdbmap⟩ :=
NumberHelperSplitExponentSuffix sign bs' ds hbsmap'
have hdsne : dbs ≠ [] := by
intro he
subst dbs
simp at hdbmap
exact hne (by simpa using hdbmap)
have hdbytes : ∀ c, c ∈ dbs → 48 ≤ c.val ∧ c.val ≤ 57 := by
intro c hc
have hmemb : c.val ∈ (ds.map (fun z => 48 + z)) := by
rw [← hdbmap]
exact List.mem_map.mpr ⟨c, hc, rfl⟩
rcases List.mem_map.mp hmemb with ⟨d, hdmem, hcv⟩
have := hd d hdmem
omega
have hbound : (b' :: bs').length ≤ Usize.max := by
rw [← hcons]
exact s.property
let s' : Slice Std.U8 := ⟨b' :: bs', hbound⟩
have hs' : s = s' := (Slice.eq_iff _ _).2 (by simp [s', hcons])
subst s
let u : Slice Std.U8 := ⟨bs', by
have := hbound
simp only [List.length_cons] at this
omega⟩
have hsplit' : bs' =
(match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ dbs := by
cases sign <;> simp_all [hsplit]
have huval : u.val =
(match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ dbs := by
simpa [u] using hsplit'
have hnonempty : core.slice.Slice.is_empty s' = ok false := by
simp [core.slice.Slice.is_empty, s']
have hread : Slice.index_usize s' 0#usize = ok (if upper then 69#u8 else 101#u8) := by
have hb' : b' = (if upper then 69#u8 else 101#u8) := hbb.symm.trans hb
simp [Slice.index_usize, s', hb']
have hdrop : core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s'
{ start := 1#usize } = ok u := by
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, s', u]
obtain ⟨e, rest, hparse, hrest, hval⟩ :=
P9_T1_ScientificVocabularyFold u sign dbs []
(by simpa only [bne_iff_ne] using hdsne)
hdbytes (by intro c cs heq; simp at heq)
(by simpa using huval)
have hdigit : (dbs.map (fun c => c.val - 48)) = ds := by
calc
_ = (dbs.map (fun c => c.val)).map (fun n => n - 48) := by
simp [List.map_map, Function.comp_def]
_ = (ds.map (fun z => 48 + z)).map (fun n => n - 48) :=
congrArg (List.map (fun n => n - 48)) hdbmap
_ = ds := by simp [List.map_map, Function.comp_def]
have hexponent : e.val =
DecimalGoalVocabularyDefault.accumulatedExplicitExponent x := by
rw [hval, hdigit]
cases sign with
| none => simp [DecimalGoalVocabularyDefault, hx]
| some neg => cases neg <;> simp [DecimalGoalVocabularyDefault, hx]
have hresult : explicitCall = ok e := by
unfold explicitCall
cases upper <;>
simp [hnonempty, hread, hdrop, hparse, hb]
exact ⟨e, hresult, hexponent⟩
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P9_T1_ScientificVocabularyFold
import Tablet.NumberHelperSplitExponentSuffix
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P495_T1_ExponentSuffix]
theorem P495_T1_ExponentSuffix (s : Slice Std.U8) (x : DecimalLexeme)
(hvalid : DecimalGoalVocabularyDefault.validNumeric x)
(hs : s.val.map (fun b => b.val) = match x.exponent with
| none => []
| some (upper, sign, ds) =>
(if upper then 69 else 101) ::
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun z => 48 + z)) :
let explicitCall : Result Std.I64 := do
let empty <- core.slice.Slice.is_empty s
if empty then ok 0#i64 else
let ch <- Slice.index_usize s 0#usize
if ch = 101#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else if ch = 69#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else ok 0#i64
exists e : Std.I64, explicitCall = ok e /\
e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x := by
-- BODY
let explicitCall : Result Std.I64 := do
let empty <- core.slice.Slice.is_empty s
if empty then ok 0#i64 else
let ch <- Slice.index_usize s 0#usize
if ch = 101#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else if ch = 69#u8 then do
let suffix <- core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize }
let (o, _) <- num.imp.dec2flt.parse.parse_scientific suffix
ok (core.option.Option.unwrap_or o 0#i64)
else ok 0#i64
change ∃ e : Std.I64, explicitCall = ok e ∧
e.val = DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
cases hx : x.exponent with
| none =>
have hs0 : s.val.map (fun b => b.val) = [] := by simpa [hx] using hs
cases hsv : s.val with
| nil =>
have hlen : s.val.length = 0 := by simp [hsv]
have hempty : core.slice.Slice.is_empty s = ok true := by
simp [core.slice.Slice.is_empty, hlen]
refine ⟨0#i64, ?_, ?_⟩
· simp [explicitCall, hempty, hsv]
· simp [DecimalGoalVocabularyDefault, hx]
| cons b bs => simp [hsv] at hs0
| some ex =>
rcases ex with ⟨upper, sign, ds⟩
simp [DecimalGoalVocabularyDefault, hx] at hvalid
rcases hvalid with ⟨_, _, _, hne, hd⟩
have hmap : s.val.map (fun b => b.val) =
(if upper then 69 else 101) ::
((match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun z => 48 + z)) := by
simpa [hx] using hs
cases hsv : s.val with
| nil => simp [hsv] at hmap
| cons b bs =>
obtain ⟨b', bs', hcons, hbmap, hbsmap⟩ :=
List.map_eq_cons_iff.mp hmap
have hbb : b = b' := by
rw [hsv] at hcons
injection hcons
have hbs' : bs = bs' := by
rw [hsv] at hcons
injection hcons with hhead htail
have hb : b = (if upper then 69#u8 else 101#u8) := by
apply UScalar.eq_of_val_eq
have hnum : (if upper then 69#u8 else 101#u8).val =
(if upper then 69 else 101) := by cases upper <;> rfl
rw [hbb, hnum]
exact hbmap
have hbsmap' : bs'.map (fun c => c.val) =
(match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
ds.map (fun z => 48 + z) := by simpa using hbsmap
obtain ⟨dbs, hsplit, hdbmap⟩ :=
NumberHelperSplitExponentSuffix sign bs' ds hbsmap'
have hdsne : dbs ≠ [] := by
intro he
subst dbs
simp at hdbmap
exact hne (by simpa using hdbmap)
have hdbytes : ∀ c, c ∈ dbs → 48 ≤ c.val ∧ c.val ≤ 57 := by
intro c hc
have hmemb : c.val ∈ (ds.map (fun z => 48 + z)) := by
rw [← hdbmap]
exact List.mem_map.mpr ⟨c, hc, rfl⟩
rcases List.mem_map.mp hmemb with ⟨d, hdmem, hcv⟩
have := hd d hdmem
omega
have hbound : (b' :: bs').length ≤ Usize.max := by
rw [← hcons]
exact s.property
let s' : Slice Std.U8 := ⟨b' :: bs', hbound⟩
have hs' : s = s' := (Slice.eq_iff _ _).2 (by simp [s', hcons])
subst s
let u : Slice Std.U8 := ⟨bs', by
have := hbound
simp only [List.length_cons] at this
omega⟩
have hsplit' : bs' =
(match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ dbs := by
cases sign <;> simp_all [hsplit]
have huval : u.val =
(match sign with | none => [] | some neg => [if neg then 45#u8 else 43#u8]) ++ dbs := by
simpa [u] using hsplit'
have hnonempty : core.slice.Slice.is_empty s' = ok false := by
simp [core.slice.Slice.is_empty, s']
have hread : Slice.index_usize s' 0#usize = ok (if upper then 69#u8 else 101#u8) := by
have hb' : b' = (if upper then 69#u8 else 101#u8) := hbb.symm.trans hb
simp [Slice.index_usize, s', hb']
have hdrop : core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s'
{ start := 1#usize } = ok u := by
simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
Slice.drop, s', u]
obtain ⟨e, rest, hparse, hrest, hval⟩ :=
P9_T1_ScientificVocabularyFold u sign dbs []
(by simpa only [bne_iff_ne] using hdsne)
hdbytes (by intro c cs heq; simp at heq)
(by simpa using huval)
have hdigit : (dbs.map (fun c => c.val - 48)) = ds := by
calc
_ = (dbs.map (fun c => c.val)).map (fun n => n - 48) := by
simp [List.map_map, Function.comp_def]
_ = (ds.map (fun z => 48 + z)).map (fun n => n - 48) :=
congrArg (List.map (fun n => n - 48)) hdbmap
_ = ds := by simp [List.map_map, Function.comp_def]
have hexponent : e.val =
DecimalGoalVocabularyDefault.accumulatedExplicitExponent x := by
rw [hval, hdigit]
cases sign with
| none => simp [DecimalGoalVocabularyDefault, hx]
| some neg => cases neg <;> simp [DecimalGoalVocabularyDefault, hx]
have hresult : explicitCall = ok e := by
unfold explicitCall
cases upper <;>
simp [hnonempty, hread, hdrop, hparse, hb]
exact ⟨e, hresult, hexponent⟩
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (47)
- BiasedFp · dec2flt/common.rs:56 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- parse_scientific · dec2flt/parse.rs:121 Program Rust
More program dependencies (14)
- parse_scientific_loop · dec2flt/parse.rs:145 Program Rust
- body · dec2flt/parse.rs:145 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
- ByteSlice · dec2flt/common.rs:4 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)
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- 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
- 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 40 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
- NumberHelperSplitExponentSuffix
- ExponentSuffix
- 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": "P495_T1_ExponentSuffix",
"closure_version": "patch_c_v1",
"active_decl_hash": "a66e14ddbde18270ea7c8171155b6c5f165d26edd4b6ab1183d5214da493b80d",
"active_statement_hash": "907c42bbf16fbe429c2d2f2cc9f4d66cfa6cad1b84bf8e25c4fcf0e845f345e9",
"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-181",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
"NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766",
"P9_T1_ScientificVocabularyFold": "b4e9d9d3618cb9a8"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "c08dd4b4aea4abb4",
"DecimalGoalVocabularyDefault": "b9386c8d0fd53e6e",
"DecimalLexeme": "303e59678842cea4",
"F64": "ec4e25fbaf4e11d4",
"NumberHelperSplitExponentSuffix": "3a789d080d66f335",
"P9_T1_ScientificVocabularyFold": "28ca0a8ac503ee01",
"num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
"num_imp_dec2flt_decimal_Decimal": "63fd2f021dd0ef41",
"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:083ab7b1947b668b972c2c43b61a7011a569a5e89d9c16d197a5a2731245df88",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}