Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Exact whole-input sign removal
- or +, and its unchanged bytes otherwise. Put
\nu=\texttt{true} exactly when the initial byte is -.
Then b is source-valid and |b|\leq|s|.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_SignStrippedClassification]
theorem P616_T1_SignStrippedClassification (s : Str) (body : Slice Std.U8)
(hs : DecimalGoalVocabularyDefault.sourceString s)
(hbody : body.val =
if s.val.head? = some (45#u8) ∨ s.val.head? = some (43#u8)
then s.val.drop 1 else s.val) :
let negative : Bool := decide (s.val.head? = some (45#u8))
SourceValidByteSlice body ∧ body.val.length <= s.val.length ∧
(forall x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inl x)) ->
let y : DecimalLexeme := { x with leadingSign := none }
DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude y =
DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
DecimalGoalVocabularyDefault.exactMagnitude y = DecimalGoalVocabularyDefault.exactMagnitude x ∧
DecimalGoalVocabularyDefault.lexicalNegative x = negative) ∧
(forall sign nan,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inr (sign, nan))) ->
DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes body) none nan ∧
decide (sign = some true) = negative) ∧
((exists x : DecimalLexeme, x.leadingSign = none ∧
DecimalGoalVocabularyDefault.validNumeric x ∧
DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body) ->
exists x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inl x))) ∧
((exists nan, DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body) none nan) ->
exists sign nan, DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan)))) := 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
inf, infinity,
or nan. These four first bytes also exclude both signs.Lean proof
rcases s with ⟨sv, hsbound⟩
rcases body with ⟨bv, hbv⟩
change sv.length ≤ 9223372036854775807 ∧
∃ t : String, sv.map (fun z => z.val) = t.toUTF8.toList.map UInt8.toNat at hs
have hlen : bv.length ≤ sv.length := by
change bv = (if sv.head? = some (45#u8) ∨ sv.head? = some (43#u8)
then sv.drop 1 else sv) at hbody
cases sv with
| nil => simp at hbody; simp [hbody]
| cons a t =>
by_cases hm : a = 45#u8
· simp [hm] at hbody
subst bv
simp
· by_cases hp : a = 43#u8
· simp [hm, hp] at hbody
subst bv
simp
· simp [hm, hp] at hbody
subst bv
simp
have hvalidbody : SourceValidByteSlice (⟨bv, hbv⟩ : Slice Std.U8) := by
unfold SourceValidByteSlice
exact Nat.le_trans hlen hs.1
have hmapinj : ∀ (u v : List Std.U8),
u.map (fun z => z.val) = v.map (fun z => z.val) → u = v := by
intro u v h
induction u generalizing v with
| nil => cases v <;> simp_all
| cons a t iht =>
cases v with
| nil => simp at h
| cons b r =>
simp only [List.map_cons, List.cons.injEq] at h
have hab : a = b := UScalar.eq_of_val_eq h.1
have htr : t = r := iht r h.2
simp [hab, htr]
let signBytes : Option Bool → List Nat := fun sign =>
match sign with | none => [] | some n => [if n then 45 else 43]
have hsourceSplit : ∃ sg : Option Bool,
sv.map (fun z => z.val) = signBytes sg ++ bv.map (fun z => z.val) ∧
decide (sg = some true) = decide (sv.head? = some (45#u8)) := by
cases sv with
| nil =>
have hb : bv = [] := by
change bv = (if ([] : List Std.U8).head? = some (45#u8) ∨
([] : List Std.U8).head? = some (43#u8) then ([] : List Std.U8).drop 1 else []) at hbody
simpa using hbody
subst bv
refine ⟨none, ?_, ?_⟩ <;> simp [signBytes]
| cons a t =>
change bv = (if (a :: t).head? = some (45#u8) ∨
(a :: t).head? = some (43#u8) then (a :: t).drop 1 else a :: t) at hbody
by_cases hm : a = 45#u8
· have hb : bv = t := by simpa [hm] using hbody
subst bv
refine ⟨some true, ?_, ?_⟩ <;> simp [signBytes, hm]
· by_cases hp : a = 43#u8
· have hb : bv = t := by simpa [hm, hp] using hbody
subst bv
refine ⟨some false, ?_, ?_⟩ <;> simp [signBytes, hm, hp]
· have hb : bv = a :: t := by simpa [hm, hp] using hbody
subst bv
refine ⟨none, ?_, ?_⟩ <;> simp [signBytes, hm, hp]
refine ⟨hvalidbody, ?_, ?_, ?_, ?_, ?_⟩
· omega
· intro x hx
change DecimalGoalVocabularyDefault.validNumeric x ∧
DecimalGoalVocabularyDefault.renderNumeric x = sv.map (fun z => z.val) at hx
rcases hx with ⟨hv, hr⟩
let unsigned : DecimalLexeme := { x with leadingSign := none }
let r : List Nat := x.integerDigits.map (fun d => 48 + d) ++
(match x.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)) ++
(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 hr' : (match x.leadingSign with
| none => [] | some n => [if n then 45 else 43]) ++ r = sv.map (fun z => z.val) := by
change (match x.leadingSign with
| none => [] | some n => [if n then 45 else 43]) ++
x.integerDigits.map (fun d => 48 + d) ++
(match x.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)) ++
(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)) = sv.map (fun z => z.val) at hr
simpa [r, List.append_assoc] using hr
have hrUnsigned : DecimalGoalVocabularyDefault.renderNumeric unsigned = r := by
change (match unsigned.leadingSign with
| none => [] | some n => [if n then 45 else 43]) ++
unsigned.integerDigits.map (fun d => 48 + d) ++
(match unsigned.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)) ++
(match unsigned.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)) = r
simp [unsigned, r, List.append_assoc]
have hRne : r ≠ [] := by
dsimp [r]
rcases hv with ⟨hints, hfrac, hhas, hexp⟩
cases hi : x.integerDigits with
| nil =>
cases hf : x.fractionDigits with
| none => simp [hi, hf] at hhas
| some ds =>
have hds : ds ≠ [] := by simpa [hi, hf] using hhas
cases ds <;> simp_all [hi, hf]
| cons d ds => simp [hi]
have hRhead : ∀ a t, r = a :: t → a ≠ 43 ∧ a ≠ 45 := by
intro a t har
dsimp [r] at har
rcases hv with ⟨hints, hfrac, hhas, hexp⟩
cases hi : x.integerDigits with
| nil =>
cases hf : x.fractionDigits with
| none => simp [hi, hf] at hhas
| some ds =>
have hds : ds ≠ [] := by simpa [hi, hf] using hhas
cases ds with
| nil => contradiction
| cons d ds => simp [hi, hf] at har; omega
| cons d ds =>
have hd : d < 10 := hints d (by simp [hi])
simp [hi] at har
omega
refine ⟨?_, ?_, ?_, ?_, ?_⟩
· change DecimalGoalVocabularyDefault.validNumeric x
exact hv
· rw [hrUnsigned]
change r = bv.map (fun z => z.val)
have hrbody : r = bv.map (fun z => z.val) := by
cases sv with
| nil =>
cases x.leadingSign <;> simp at hr' <;> exact (hRne hr'.2).elim
| cons a t =>
have hb : bv = (if a = 45#u8 ∨ a = 43#u8 then t else a :: t) := by
change bv = (if (a :: t).head? = some (45#u8) ∨
(a :: t).head? = some (43#u8) then (a :: t).drop 1 else a :: t) at hbody
simpa using hbody
by_cases hm : a = 45#u8
· simp [hm] at hb
subst bv
subst a
cases hsx : x.leadingSign with
| none =>
simp [hsx] at hr'
have hnot := hRhead 45 (List.map (fun z => z.val) t) hr'
norm_num at hnot
| some neg =>
cases neg with
| false => simp [hsx] at hr'
| true =>
simp [hsx] at hr'
exact hr'
· by_cases hp : a = 43#u8
· simp [hm, hp] at hb
subst bv
subst a
cases hsx : x.leadingSign with
| none =>
simp [hsx] at hr'
have hnot := hRhead 43 (List.map (fun z => z.val) t) hr'
norm_num at hnot
| some neg =>
cases neg with
| false => simpa [hsx] using hr'
| true => simp [hsx] at hr'
· simp [hm, hp] at hb
subst bv
cases hsx : x.leadingSign with
| none => simpa [hsx] using hr'
| some neg =>
cases neg <;> simp [hsx] at hr'
· exact (hp (UScalar.eq_of_val_eq hr'.1)).elim
· exact (hm (UScalar.eq_of_val_eq hr'.1)).elim
exact hrbody
· rfl
· rfl
· change decide (x.leadingSign = some true) = decide (sv.head? = some (45#u8))
cases sv with
| nil =>
cases x.leadingSign <;> simp at hr' <;> exact (hRne hr'.2).elim
| cons a t =>
by_cases hm : a = 45#u8
· subst a
cases hxsign : x.leadingSign with
| none =>
simp [hxsign] at hr'
have hnot := hRhead 45 (List.map (fun z => z.val) t) hr'
norm_num at hnot
| some n =>
cases n with
| false => simp [hxsign] at hr'
| true => simp [hxsign]
· by_cases hp : a = 43#u8
· subst a
cases hxsign : x.leadingSign with
| none => simp [hxsign]
| some n =>
cases n with
| false => simp [hxsign]
| true => simp [hxsign] at hr'
· cases hxsign : x.leadingSign with
| none => simp [hxsign, hm]
| some n =>
cases n with
| false =>
simp [hxsign] at hr'
exact (hp (UScalar.eq_of_val_eq hr'.1)).elim
| true =>
simp [hxsign] at hr'
exact (hm (UScalar.eq_of_val_eq hr'.1)).elim
· intro sign nan hx
change DecimalGoalVocabularyDefault.specialLiteral
(sv.map (fun z => z.val)) sign nan at hx
dsimp [DecimalGoalVocabularyDefault] at hx
rcases hx with ⟨word, hword, hcase⟩
have hfirstWord : ∃ a rest, word = a :: rest ∧ a ≠ 43 ∧ a ≠ 45 := by
have hpos : 0 < word.length := by
cases nan with
| false =>
rcases hcase with hcase | hcase
· have hlen' := List.Forall₂.length_eq hcase
simp at hlen'
omega
· have hlen' := List.Forall₂.length_eq hcase
simp at hlen'
omega
| true =>
have hlen' := List.Forall₂.length_eq hcase
simp at hlen'
omega
obtain ⟨a, rest, hcons⟩ := List.exists_cons_of_length_pos hpos
rw [hcons] at hcase
refine ⟨a, rest, hcons, ?_, ?_⟩
· cases nan with
| false =>
rcases hcase with hcase | hcase
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
| true =>
cases hcase with
| cons ha _ => change a = 110 ∨ a + 32 = 110 at ha; omega
· cases nan with
| false =>
rcases hcase with hcase | hcase
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
| true =>
cases hcase with
| cons ha _ => change a = 110 ∨ a + 32 = 110 at ha; omega
obtain ⟨a, rest, hwordcons, haPlus, haMinus⟩ := hfirstWord
have hsrc : signBytes sign ++ word = sv.map (fun z => z.val) := hword.symm
refine ⟨?_, ?_⟩
· change DecimalGoalVocabularyDefault.specialLiteral
(bv.map (fun z => z.val)) none nan
dsimp [DecimalGoalVocabularyDefault]
refine ⟨word, ?_, hcase⟩
have ⟨sg, hsplit, _⟩ := hsourceSplit
cases sv with
| nil =>
cases sign <;> simp [signBytes, hwordcons] at hsrc
| cons z t =>
by_cases hm : z = 45#u8
· subst z
have hb : bv = t := by
change bv = (if (45#u8 :: t).head? = some (45#u8) ∨
(45#u8 :: t).head? = some (43#u8) then (45#u8 :: t).drop 1 else 45#u8 :: t) at hbody
simpa using hbody
subst bv
cases sign with
| none =>
simp [signBytes] at hsrc
have hh := congrArg List.head? hsrc
simp [hwordcons] at hh
exact (haMinus hh).elim
| some neg =>
cases neg with
| false => simp [signBytes] at hsrc
| true =>
simp [signBytes] at hsrc
exact hsrc.symm
· by_cases hp : z = 43#u8
· subst z
have hb : bv = t := by
change bv = (if (43#u8 :: t).head? = some (45#u8) ∨
(43#u8 :: t).head? = some (43#u8) then (43#u8 :: t).drop 1 else 43#u8 :: t) at hbody
simpa using hbody
subst bv
cases sign with
| none =>
simp [signBytes] at hsrc
have hh := congrArg List.head? hsrc
simp [hwordcons] at hh
exact (haPlus hh).elim
| some neg =>
cases neg with
| false =>
simp [signBytes] at hsrc
exact hsrc.symm
| true => simp [signBytes] at hsrc
· have hb : bv = z :: t := by
change bv = (if (z :: t).head? = some (45#u8) ∨
(z :: t).head? = some (43#u8) then (z :: t).drop 1 else z :: t) at hbody
simpa [hm, hp] using hbody
subst bv
cases sign with
| none => simpa [signBytes] using hsrc.symm
| some neg =>
cases neg <;> simp [signBytes] at hsrc
· rcases hsrc with ⟨hfirst, _⟩
exact (hp (UScalar.eq_of_val_eq hfirst)).elim
· rcases hsrc with ⟨hfirst, _⟩
exact (hm (UScalar.eq_of_val_eq hfirst)).elim
· change decide (sign = some true) = decide (sv.head? = some (45#u8))
cases sv with
| nil =>
cases sign <;> simp [signBytes, hwordcons] at hsrc
| cons z t =>
by_cases hm : z = 45#u8
· subst z
cases sign with
| none =>
simp [signBytes] at hsrc
have hh := congrArg List.head? hsrc
simp [hwordcons] at hh
exact (haMinus hh).elim
| some neg =>
cases neg with
| false => simp [signBytes] at hsrc
| true => simp [signBytes]
· by_cases hp : z = 43#u8
· subst z
cases sign with
| none => simp [signBytes]
| some neg =>
cases neg with
| false => simp [signBytes]
| true => simp [signBytes] at hsrc
· cases sign with
| none => simp [signBytes, hm]
| some neg =>
cases neg <;> simp [signBytes] at hsrc
· rcases hsrc with ⟨hfirst, _⟩
exact (hp (UScalar.eq_of_val_eq hfirst)).elim
· rcases hsrc with ⟨hfirst, _⟩
exact (hm (UScalar.eq_of_val_eq hfirst)).elim
· intro h
rcases h with ⟨x, hnone, hv, hr⟩
change DecimalGoalVocabularyDefault.renderNumeric x = bv.map (fun z => z.val) at hr
obtain ⟨sg, hsplit, _⟩ := hsourceSplit
let y : DecimalLexeme := { x with leadingSign := sg }
refine ⟨y, ?_⟩
change DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = sv.map (fun z => z.val)
constructor
· change DecimalGoalVocabularyDefault.validNumeric x
exact hv
· calc
DecimalGoalVocabularyDefault.renderNumeric y =
signBytes sg ++ DecimalGoalVocabularyDefault.renderNumeric x := by
simp [y, signBytes, hnone, DecimalGoalVocabularyDefault, List.append_assoc]
rfl
_ = signBytes sg ++ bv.map (fun z => z.val) := by rw [hr]
_ = sv.map (fun z => z.val) := hsplit.symm
· intro h
rcases h with ⟨nan, hsp⟩
change DecimalGoalVocabularyDefault.specialLiteral
(bv.map (fun z => z.val)) none nan at hsp
dsimp [DecimalGoalVocabularyDefault] at hsp
rcases hsp with ⟨word, hword, hcase⟩
obtain ⟨sg, hsplit, _⟩ := hsourceSplit
refine ⟨sg, nan, ?_⟩
change DecimalGoalVocabularyDefault.specialLiteral
(sv.map (fun z => z.val)) sg nan
dsimp [DecimalGoalVocabularyDefault]
refine ⟨word, ?_, hcase⟩
calc
sv.map (fun z => z.val) = signBytes sg ++ bv.map (fun z => z.val) := hsplit
_ = signBytes sg ++ word := by rw [hword]
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_SignStrippedClassification]
theorem P616_T1_SignStrippedClassification (s : Str) (body : Slice Std.U8)
(hs : DecimalGoalVocabularyDefault.sourceString s)
(hbody : body.val =
if s.val.head? = some (45#u8) ∨ s.val.head? = some (43#u8)
then s.val.drop 1 else s.val) :
let negative : Bool := decide (s.val.head? = some (45#u8))
SourceValidByteSlice body ∧ body.val.length <= s.val.length ∧
(forall x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inl x)) ->
let y : DecimalLexeme := { x with leadingSign := none }
DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude y =
DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
DecimalGoalVocabularyDefault.exactMagnitude y = DecimalGoalVocabularyDefault.exactMagnitude x ∧
DecimalGoalVocabularyDefault.lexicalNegative x = negative) ∧
(forall sign nan,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inr (sign, nan))) ->
DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes body) none nan ∧
decide (sign = some true) = negative) ∧
((exists x : DecimalLexeme, x.leadingSign = none ∧
DecimalGoalVocabularyDefault.validNumeric x ∧
DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body) ->
exists x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inl x))) ∧
((exists nan, DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body) none nan) ->
exists sign nan, DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan)))) := by
-- BODY
rcases s with ⟨sv, hsbound⟩
rcases body with ⟨bv, hbv⟩
change sv.length ≤ 9223372036854775807 ∧
∃ t : String, sv.map (fun z => z.val) = t.toUTF8.toList.map UInt8.toNat at hs
have hlen : bv.length ≤ sv.length := by
change bv = (if sv.head? = some (45#u8) ∨ sv.head? = some (43#u8)
then sv.drop 1 else sv) at hbody
cases sv with
| nil => simp at hbody; simp [hbody]
| cons a t =>
by_cases hm : a = 45#u8
· simp [hm] at hbody
subst bv
simp
· by_cases hp : a = 43#u8
· simp [hm, hp] at hbody
subst bv
simp
· simp [hm, hp] at hbody
subst bv
simp
have hvalidbody : SourceValidByteSlice (⟨bv, hbv⟩ : Slice Std.U8) := by
unfold SourceValidByteSlice
exact Nat.le_trans hlen hs.1
have hmapinj : ∀ (u v : List Std.U8),
u.map (fun z => z.val) = v.map (fun z => z.val) → u = v := by
intro u v h
induction u generalizing v with
| nil => cases v <;> simp_all
| cons a t iht =>
cases v with
| nil => simp at h
| cons b r =>
simp only [List.map_cons, List.cons.injEq] at h
have hab : a = b := UScalar.eq_of_val_eq h.1
have htr : t = r := iht r h.2
simp [hab, htr]
let signBytes : Option Bool → List Nat := fun sign =>
match sign with | none => [] | some n => [if n then 45 else 43]
have hsourceSplit : ∃ sg : Option Bool,
sv.map (fun z => z.val) = signBytes sg ++ bv.map (fun z => z.val) ∧
decide (sg = some true) = decide (sv.head? = some (45#u8)) := by
cases sv with
| nil =>
have hb : bv = [] := by
change bv = (if ([] : List Std.U8).head? = some (45#u8) ∨
([] : List Std.U8).head? = some (43#u8) then ([] : List Std.U8).drop 1 else []) at hbody
simpa using hbody
subst bv
refine ⟨none, ?_, ?_⟩ <;> simp [signBytes]
| cons a t =>
change bv = (if (a :: t).head? = some (45#u8) ∨
(a :: t).head? = some (43#u8) then (a :: t).drop 1 else a :: t) at hbody
by_cases hm : a = 45#u8
· have hb : bv = t := by simpa [hm] using hbody
subst bv
refine ⟨some true, ?_, ?_⟩ <;> simp [signBytes, hm]
· by_cases hp : a = 43#u8
· have hb : bv = t := by simpa [hm, hp] using hbody
subst bv
refine ⟨some false, ?_, ?_⟩ <;> simp [signBytes, hm, hp]
· have hb : bv = a :: t := by simpa [hm, hp] using hbody
subst bv
refine ⟨none, ?_, ?_⟩ <;> simp [signBytes, hm, hp]
refine ⟨hvalidbody, ?_, ?_, ?_, ?_, ?_⟩
· omega
· intro x hx
change DecimalGoalVocabularyDefault.validNumeric x ∧
DecimalGoalVocabularyDefault.renderNumeric x = sv.map (fun z => z.val) at hx
rcases hx with ⟨hv, hr⟩
let unsigned : DecimalLexeme := { x with leadingSign := none }
let r : List Nat := x.integerDigits.map (fun d => 48 + d) ++
(match x.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)) ++
(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 hr' : (match x.leadingSign with
| none => [] | some n => [if n then 45 else 43]) ++ r = sv.map (fun z => z.val) := by
change (match x.leadingSign with
| none => [] | some n => [if n then 45 else 43]) ++
x.integerDigits.map (fun d => 48 + d) ++
(match x.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)) ++
(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)) = sv.map (fun z => z.val) at hr
simpa [r, List.append_assoc] using hr
have hrUnsigned : DecimalGoalVocabularyDefault.renderNumeric unsigned = r := by
change (match unsigned.leadingSign with
| none => [] | some n => [if n then 45 else 43]) ++
unsigned.integerDigits.map (fun d => 48 + d) ++
(match unsigned.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)) ++
(match unsigned.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)) = r
simp [unsigned, r, List.append_assoc]
have hRne : r ≠ [] := by
dsimp [r]
rcases hv with ⟨hints, hfrac, hhas, hexp⟩
cases hi : x.integerDigits with
| nil =>
cases hf : x.fractionDigits with
| none => simp [hi, hf] at hhas
| some ds =>
have hds : ds ≠ [] := by simpa [hi, hf] using hhas
cases ds <;> simp_all [hi, hf]
| cons d ds => simp [hi]
have hRhead : ∀ a t, r = a :: t → a ≠ 43 ∧ a ≠ 45 := by
intro a t har
dsimp [r] at har
rcases hv with ⟨hints, hfrac, hhas, hexp⟩
cases hi : x.integerDigits with
| nil =>
cases hf : x.fractionDigits with
| none => simp [hi, hf] at hhas
| some ds =>
have hds : ds ≠ [] := by simpa [hi, hf] using hhas
cases ds with
| nil => contradiction
| cons d ds => simp [hi, hf] at har; omega
| cons d ds =>
have hd : d < 10 := hints d (by simp [hi])
simp [hi] at har
omega
refine ⟨?_, ?_, ?_, ?_, ?_⟩
· change DecimalGoalVocabularyDefault.validNumeric x
exact hv
· rw [hrUnsigned]
change r = bv.map (fun z => z.val)
have hrbody : r = bv.map (fun z => z.val) := by
cases sv with
| nil =>
cases x.leadingSign <;> simp at hr' <;> exact (hRne hr'.2).elim
| cons a t =>
have hb : bv = (if a = 45#u8 ∨ a = 43#u8 then t else a :: t) := by
change bv = (if (a :: t).head? = some (45#u8) ∨
(a :: t).head? = some (43#u8) then (a :: t).drop 1 else a :: t) at hbody
simpa using hbody
by_cases hm : a = 45#u8
· simp [hm] at hb
subst bv
subst a
cases hsx : x.leadingSign with
| none =>
simp [hsx] at hr'
have hnot := hRhead 45 (List.map (fun z => z.val) t) hr'
norm_num at hnot
| some neg =>
cases neg with
| false => simp [hsx] at hr'
| true =>
simp [hsx] at hr'
exact hr'
· by_cases hp : a = 43#u8
· simp [hm, hp] at hb
subst bv
subst a
cases hsx : x.leadingSign with
| none =>
simp [hsx] at hr'
have hnot := hRhead 43 (List.map (fun z => z.val) t) hr'
norm_num at hnot
| some neg =>
cases neg with
| false => simpa [hsx] using hr'
| true => simp [hsx] at hr'
· simp [hm, hp] at hb
subst bv
cases hsx : x.leadingSign with
| none => simpa [hsx] using hr'
| some neg =>
cases neg <;> simp [hsx] at hr'
· exact (hp (UScalar.eq_of_val_eq hr'.1)).elim
· exact (hm (UScalar.eq_of_val_eq hr'.1)).elim
exact hrbody
· rfl
· rfl
· change decide (x.leadingSign = some true) = decide (sv.head? = some (45#u8))
cases sv with
| nil =>
cases x.leadingSign <;> simp at hr' <;> exact (hRne hr'.2).elim
| cons a t =>
by_cases hm : a = 45#u8
· subst a
cases hxsign : x.leadingSign with
| none =>
simp [hxsign] at hr'
have hnot := hRhead 45 (List.map (fun z => z.val) t) hr'
norm_num at hnot
| some n =>
cases n with
| false => simp [hxsign] at hr'
| true => simp [hxsign]
· by_cases hp : a = 43#u8
· subst a
cases hxsign : x.leadingSign with
| none => simp [hxsign]
| some n =>
cases n with
| false => simp [hxsign]
| true => simp [hxsign] at hr'
· cases hxsign : x.leadingSign with
| none => simp [hxsign, hm]
| some n =>
cases n with
| false =>
simp [hxsign] at hr'
exact (hp (UScalar.eq_of_val_eq hr'.1)).elim
| true =>
simp [hxsign] at hr'
exact (hm (UScalar.eq_of_val_eq hr'.1)).elim
· intro sign nan hx
change DecimalGoalVocabularyDefault.specialLiteral
(sv.map (fun z => z.val)) sign nan at hx
dsimp [DecimalGoalVocabularyDefault] at hx
rcases hx with ⟨word, hword, hcase⟩
have hfirstWord : ∃ a rest, word = a :: rest ∧ a ≠ 43 ∧ a ≠ 45 := by
have hpos : 0 < word.length := by
cases nan with
| false =>
rcases hcase with hcase | hcase
· have hlen' := List.Forall₂.length_eq hcase
simp at hlen'
omega
· have hlen' := List.Forall₂.length_eq hcase
simp at hlen'
omega
| true =>
have hlen' := List.Forall₂.length_eq hcase
simp at hlen'
omega
obtain ⟨a, rest, hcons⟩ := List.exists_cons_of_length_pos hpos
rw [hcons] at hcase
refine ⟨a, rest, hcons, ?_, ?_⟩
· cases nan with
| false =>
rcases hcase with hcase | hcase
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
| true =>
cases hcase with
| cons ha _ => change a = 110 ∨ a + 32 = 110 at ha; omega
· cases nan with
| false =>
rcases hcase with hcase | hcase
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
· cases hcase with
| cons ha _ => change a = 105 ∨ a + 32 = 105 at ha; omega
| true =>
cases hcase with
| cons ha _ => change a = 110 ∨ a + 32 = 110 at ha; omega
obtain ⟨a, rest, hwordcons, haPlus, haMinus⟩ := hfirstWord
have hsrc : signBytes sign ++ word = sv.map (fun z => z.val) := hword.symm
refine ⟨?_, ?_⟩
· change DecimalGoalVocabularyDefault.specialLiteral
(bv.map (fun z => z.val)) none nan
dsimp [DecimalGoalVocabularyDefault]
refine ⟨word, ?_, hcase⟩
have ⟨sg, hsplit, _⟩ := hsourceSplit
cases sv with
| nil =>
cases sign <;> simp [signBytes, hwordcons] at hsrc
| cons z t =>
by_cases hm : z = 45#u8
· subst z
have hb : bv = t := by
change bv = (if (45#u8 :: t).head? = some (45#u8) ∨
(45#u8 :: t).head? = some (43#u8) then (45#u8 :: t).drop 1 else 45#u8 :: t) at hbody
simpa using hbody
subst bv
cases sign with
| none =>
simp [signBytes] at hsrc
have hh := congrArg List.head? hsrc
simp [hwordcons] at hh
exact (haMinus hh).elim
| some neg =>
cases neg with
| false => simp [signBytes] at hsrc
| true =>
simp [signBytes] at hsrc
exact hsrc.symm
· by_cases hp : z = 43#u8
· subst z
have hb : bv = t := by
change bv = (if (43#u8 :: t).head? = some (45#u8) ∨
(43#u8 :: t).head? = some (43#u8) then (43#u8 :: t).drop 1 else 43#u8 :: t) at hbody
simpa using hbody
subst bv
cases sign with
| none =>
simp [signBytes] at hsrc
have hh := congrArg List.head? hsrc
simp [hwordcons] at hh
exact (haPlus hh).elim
| some neg =>
cases neg with
| false =>
simp [signBytes] at hsrc
exact hsrc.symm
| true => simp [signBytes] at hsrc
· have hb : bv = z :: t := by
change bv = (if (z :: t).head? = some (45#u8) ∨
(z :: t).head? = some (43#u8) then (z :: t).drop 1 else z :: t) at hbody
simpa [hm, hp] using hbody
subst bv
cases sign with
| none => simpa [signBytes] using hsrc.symm
| some neg =>
cases neg <;> simp [signBytes] at hsrc
· rcases hsrc with ⟨hfirst, _⟩
exact (hp (UScalar.eq_of_val_eq hfirst)).elim
· rcases hsrc with ⟨hfirst, _⟩
exact (hm (UScalar.eq_of_val_eq hfirst)).elim
· change decide (sign = some true) = decide (sv.head? = some (45#u8))
cases sv with
| nil =>
cases sign <;> simp [signBytes, hwordcons] at hsrc
| cons z t =>
by_cases hm : z = 45#u8
· subst z
cases sign with
| none =>
simp [signBytes] at hsrc
have hh := congrArg List.head? hsrc
simp [hwordcons] at hh
exact (haMinus hh).elim
| some neg =>
cases neg with
| false => simp [signBytes] at hsrc
| true => simp [signBytes]
· by_cases hp : z = 43#u8
· subst z
cases sign with
| none => simp [signBytes]
| some neg =>
cases neg with
| false => simp [signBytes]
| true => simp [signBytes] at hsrc
· cases sign with
| none => simp [signBytes, hm]
| some neg =>
cases neg <;> simp [signBytes] at hsrc
· rcases hsrc with ⟨hfirst, _⟩
exact (hp (UScalar.eq_of_val_eq hfirst)).elim
· rcases hsrc with ⟨hfirst, _⟩
exact (hm (UScalar.eq_of_val_eq hfirst)).elim
· intro h
rcases h with ⟨x, hnone, hv, hr⟩
change DecimalGoalVocabularyDefault.renderNumeric x = bv.map (fun z => z.val) at hr
obtain ⟨sg, hsplit, _⟩ := hsourceSplit
let y : DecimalLexeme := { x with leadingSign := sg }
refine ⟨y, ?_⟩
change DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = sv.map (fun z => z.val)
constructor
· change DecimalGoalVocabularyDefault.validNumeric x
exact hv
· calc
DecimalGoalVocabularyDefault.renderNumeric y =
signBytes sg ++ DecimalGoalVocabularyDefault.renderNumeric x := by
simp [y, signBytes, hnone, DecimalGoalVocabularyDefault, List.append_assoc]
rfl
_ = signBytes sg ++ bv.map (fun z => z.val) := by rw [hr]
_ = sv.map (fun z => z.val) := hsplit.symm
· intro h
rcases h with ⟨nan, hsp⟩
change DecimalGoalVocabularyDefault.specialLiteral
(bv.map (fun z => z.val)) none nan at hsp
dsimp [DecimalGoalVocabularyDefault] at hsp
rcases hsp with ⟨word, hword, hcase⟩
obtain ⟨sg, hsplit, _⟩ := hsourceSplit
refine ⟨sg, nan, ?_⟩
change DecimalGoalVocabularyDefault.specialLiteral
(sv.map (fun z => z.val)) sg nan
dsimp [DecimalGoalVocabularyDefault]
refine ⟨word, ?_, hcase⟩
calc
sv.map (fun z => z.val) = signBytes sg ++ bv.map (fun z => z.val) := hsplit
_ = signBytes sg ++ word := by rw [hword]
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": "P616_T1_SignStrippedClassification",
"closure_version": "patch_c_v1",
"active_decl_hash": "3c135dd8b969d3e26eb81bddff591d333c86d57fa76bc1dc7e919677b915038e",
"active_statement_hash": "1130fe50dfc9caf730a2a84a7f9a6f0a61d762900306108adb9c7d84f1f78e7d",
"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-156",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalGoalVocabularyDefault": "94cb4c406f8efb78"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "c08dd4b4aea4abb4",
"DecimalGoalVocabularyDefault": "28ca0a8ac503ee01",
"DecimalLexeme": "250be645520aec86",
"F64": "ec4e25fbaf4e11d4",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
"num_imp_dec2flt_decimal_Decimal": "63fd2f021dd0ef41"
}
}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:7d894d723001471fcfaa67aea4a41c41bdf966f525852809b7442d5dd225c6b4",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}