Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Rendered numeric prefixes as actual byte blocks
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.P435_T1_ByteValueBlocks
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.DecimalGoalVocabularyDefault
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P435_T1_RenderedDigitBlocks]
theorem P435_T1_RenderedDigitBlocks
(bytes remainder : List Std.U8) (x : DecimalLexeme)
(hsign : x.leadingSign = none)
(hvalid : DecimalGoalVocabularyDefault.validNumeric x)
(hrender : bytes.map (fun b => b.val) =
DecimalGoalVocabularyDefault.renderNumeric x ++ remainder.map (fun b => b.val)) :
exists integer fraction exponent : List Std.U8,
bytes = integer ++
(match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) ++
(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]) ++
exponent) ++ remainder /\
integer.map (fun b => b.val) = x.integerDigits.map (fun d => 48 + d) /\
fraction.map (fun b => b.val) =
(match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) /\
exponent.map (fun b => b.val) =
(match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) /\
(forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57) /\
(forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57) /\
(forall b, b ∈ exponent -> 48 <= b.val /\ b.val <= 57) := 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 fv : List Nat := match x.fractionDigits with
| none => [] | some ds => 46 :: ds.map (fun d => 48 + d)
let ev : List Nat := 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 d => 48 + d)
have hmap : bytes.map (fun b => b.val) =
x.integerDigits.map (fun d => 48 + d) ++
(fv ++ (ev ++ remainder.map (fun b => b.val))) := by
dsimp [DecimalGoalVocabularyDefault] at hrender
simpa [hsign, fv, ev, List.append_assoc] using hrender
obtain ⟨p, hp, hi, ht, _⟩ := P435_T1_ByteValueBlocks bytes
(x.integerDigits.map (fun d => 48 + d))
(fv ++ (ev ++ remainder.map (fun b => b.val))) hmap
obtain ⟨q, hq, hf, he, _⟩ := P435_T1_ByteValueBlocks p.2 fv
(ev ++ remainder.map (fun b => b.val)) ht
obtain ⟨r, hr, hev, hrem, hunique⟩ :=
P435_T1_ByteValueBlocks q.2 ev (remainder.map (fun b => b.val)) he
have hremEq : remainder = r.2 := (hunique r.1 remainder hev rfl).2
obtain ⟨fraction, hfraction, hfm⟩ : exists fraction : List Std.U8,
q.1 = (match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) /\
fraction.map (fun b => b.val) =
(match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) := by
cases hx : x.fractionDigits with
| none =>
have hnil : q.1 = [] := by simpa [fv, hx] using hf
exact ⟨[], by simp [hx, hnil]⟩
| some ds =>
have hf' : q.1.map (fun b => b.val) = 46 :: ds.map (fun d => 48 + d) := by
simpa [fv, hx] using hf
obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp hf'
have hb' : b = 46#u8 := UScalar.eq_of_val_eq (by simpa using hb)
exact ⟨bs, by simpa [hx, hb'] using hs, by simpa [hx] using hbs⟩
obtain ⟨exponent, hexponent, hem⟩ : exists exponent : List Std.U8,
r.1 = (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]) ++ exponent) /\
exponent.map (fun b => b.val) =
(match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) := by
cases hx : x.exponent with
| none =>
have hnil : r.1 = [] := by simpa [ev, hx] using hev
exact ⟨[], by simp [hx, hnil]⟩
| some tuple =>
rcases tuple with ⟨upper, sign, ds⟩
have he' : r.1.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 d => 48 + d)) := by
simpa [ev, hx] using hev
obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp he'
have hb' : b = (if upper then 69#u8 else 101#u8) := by
apply UScalar.eq_of_val_eq
cases upper <;> simpa using hb
obtain ⟨es, hbs', hm⟩ := NumberHelperSplitExponentSuffix sign bs ds hbs
refine ⟨es, ?_, by simpa [hx] using hm⟩
cases sign with
| none => simpa [hx, hb', hbs'] using hs
| some negative => cases negative <;> simpa [hx, hb', hbs'] using hs
have ranges : forall (bs : List Std.U8) (ds : List Nat),
bs.map (fun b => b.val) = ds.map (fun d => 48 + d) ->
(forall d, d ∈ ds -> d < 10) ->
forall b, b ∈ bs -> 48 <= b.val /\ b.val <= 57 := by
intro bs ds hm hd b hb
have hbmap : b.val ∈ bs.map (fun c => c.val) := List.mem_map_of_mem hb
rw [hm] at hbmap
obtain ⟨d, hdm, heq⟩ := List.mem_map.mp hbmap
have := hd d hdm
omega
have hv := hvalid
dsimp [DecimalGoalVocabularyDefault] at hv
rcases hv with ⟨hints, hfracs, hnonempty, hexps⟩
refine ⟨p.1, fraction, exponent, ?_, hi, hfm, hem,
ranges p.1 x.integerDigits hi hints, ?_, ?_⟩
· rw [hp, hq, hr, hfraction, hexponent, ← hremEq]
simp only [List.append_assoc]
· apply ranges fraction _ hfm
cases hx : x.fractionDigits <;> simpa [hx] using hfracs
· apply ranges exponent _ hem
cases hx : x.exponent with
| none => simp [hx]
| some tuple =>
rcases tuple with ⟨upper, sign, ds⟩
have hexps' : ds ≠ [] /\ (forall d, d ∈ ds -> d < 10) := by
simpa [hx] using hexps
exact hexps'.2
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P435_T1_ByteValueBlocks
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.DecimalGoalVocabularyDefault
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P435_T1_RenderedDigitBlocks]
theorem P435_T1_RenderedDigitBlocks
(bytes remainder : List Std.U8) (x : DecimalLexeme)
(hsign : x.leadingSign = none)
(hvalid : DecimalGoalVocabularyDefault.validNumeric x)
(hrender : bytes.map (fun b => b.val) =
DecimalGoalVocabularyDefault.renderNumeric x ++ remainder.map (fun b => b.val)) :
exists integer fraction exponent : List Std.U8,
bytes = integer ++
(match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) ++
(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]) ++
exponent) ++ remainder /\
integer.map (fun b => b.val) = x.integerDigits.map (fun d => 48 + d) /\
fraction.map (fun b => b.val) =
(match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) /\
exponent.map (fun b => b.val) =
(match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) /\
(forall b, b ∈ integer -> 48 <= b.val /\ b.val <= 57) /\
(forall b, b ∈ fraction -> 48 <= b.val /\ b.val <= 57) /\
(forall b, b ∈ exponent -> 48 <= b.val /\ b.val <= 57) := by
-- BODY
let fv : List Nat := match x.fractionDigits with
| none => [] | some ds => 46 :: ds.map (fun d => 48 + d)
let ev : List Nat := 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 d => 48 + d)
have hmap : bytes.map (fun b => b.val) =
x.integerDigits.map (fun d => 48 + d) ++
(fv ++ (ev ++ remainder.map (fun b => b.val))) := by
dsimp [DecimalGoalVocabularyDefault] at hrender
simpa [hsign, fv, ev, List.append_assoc] using hrender
obtain ⟨p, hp, hi, ht, _⟩ := P435_T1_ByteValueBlocks bytes
(x.integerDigits.map (fun d => 48 + d))
(fv ++ (ev ++ remainder.map (fun b => b.val))) hmap
obtain ⟨q, hq, hf, he, _⟩ := P435_T1_ByteValueBlocks p.2 fv
(ev ++ remainder.map (fun b => b.val)) ht
obtain ⟨r, hr, hev, hrem, hunique⟩ :=
P435_T1_ByteValueBlocks q.2 ev (remainder.map (fun b => b.val)) he
have hremEq : remainder = r.2 := (hunique r.1 remainder hev rfl).2
obtain ⟨fraction, hfraction, hfm⟩ : exists fraction : List Std.U8,
q.1 = (match x.fractionDigits with | none => [] | some _ => 46#u8 :: fraction) /\
fraction.map (fun b => b.val) =
(match x.fractionDigits with | none => [] | some ds => ds).map (fun d => 48 + d) := by
cases hx : x.fractionDigits with
| none =>
have hnil : q.1 = [] := by simpa [fv, hx] using hf
exact ⟨[], by simp [hx, hnil]⟩
| some ds =>
have hf' : q.1.map (fun b => b.val) = 46 :: ds.map (fun d => 48 + d) := by
simpa [fv, hx] using hf
obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp hf'
have hb' : b = 46#u8 := UScalar.eq_of_val_eq (by simpa using hb)
exact ⟨bs, by simpa [hx, hb'] using hs, by simpa [hx] using hbs⟩
obtain ⟨exponent, hexponent, hem⟩ : exists exponent : List Std.U8,
r.1 = (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]) ++ exponent) /\
exponent.map (fun b => b.val) =
(match x.exponent with | none => [] | some (_, _, ds) => ds).map (fun d => 48 + d) := by
cases hx : x.exponent with
| none =>
have hnil : r.1 = [] := by simpa [ev, hx] using hev
exact ⟨[], by simp [hx, hnil]⟩
| some tuple =>
rcases tuple with ⟨upper, sign, ds⟩
have he' : r.1.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 d => 48 + d)) := by
simpa [ev, hx] using hev
obtain ⟨b, bs, hs, hb, hbs⟩ := List.map_eq_cons_iff.mp he'
have hb' : b = (if upper then 69#u8 else 101#u8) := by
apply UScalar.eq_of_val_eq
cases upper <;> simpa using hb
obtain ⟨es, hbs', hm⟩ := NumberHelperSplitExponentSuffix sign bs ds hbs
refine ⟨es, ?_, by simpa [hx] using hm⟩
cases sign with
| none => simpa [hx, hb', hbs'] using hs
| some negative => cases negative <;> simpa [hx, hb', hbs'] using hs
have ranges : forall (bs : List Std.U8) (ds : List Nat),
bs.map (fun b => b.val) = ds.map (fun d => 48 + d) ->
(forall d, d ∈ ds -> d < 10) ->
forall b, b ∈ bs -> 48 <= b.val /\ b.val <= 57 := by
intro bs ds hm hd b hb
have hbmap : b.val ∈ bs.map (fun c => c.val) := List.mem_map_of_mem hb
rw [hm] at hbmap
obtain ⟨d, hdm, heq⟩ := List.mem_map.mp hbmap
have := hd d hdm
omega
have hv := hvalid
dsimp [DecimalGoalVocabularyDefault] at hv
rcases hv with ⟨hints, hfracs, hnonempty, hexps⟩
refine ⟨p.1, fraction, exponent, ?_, hi, hfm, hem,
ranges p.1 x.integerDigits hi hints, ?_, ?_⟩
· rw [hp, hq, hr, hfraction, hexponent, ← hremEq]
simp only [List.append_assoc]
· apply ranges fraction _ hfm
cases hx : x.fractionDigits <;> simpa [hx] using hfracs
· apply ranges exponent _ hem
cases hx : x.exponent with
| none => simp [hx]
| some tuple =>
rcases tuple with ⟨upper, sign, ds⟩
have hexps' : ds ≠ [] /\ (forall d, d ∈ ds -> d < 10) := by
simpa [hx] using hexps
exact hexps'.2
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (44)
- 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 (11)
- 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)
- 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
- 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": "P435_T1_RenderedDigitBlocks",
"closure_version": "patch_c_v1",
"active_decl_hash": "13f30a550283ada9a738c134682007d5cda3a5cc521ebff3ac91e3622ebeb4a8",
"active_statement_hash": "935689ba9ea6cdec45dc773fe324bee899b4a2df4b951143214ad6ecc5d095c8",
"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-92",
"boundary_theorems": {},
"strict_theorem_deps": {
"NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766",
"P435_T1_ByteValueBlocks": "c7b99f7987408046"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "4da7f295a9b85b50",
"DecimalGoalVocabularyDefault": "28ca0a8ac503ee01",
"DecimalLexeme": "250be645520aec86",
"NumberHelperSplitExponentSuffix": "3a789d080d66f335"
}
}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:c5afd44401c99af666699df74c087bef39a94da838a30f98d30b005f8514e3af",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}