Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Generic fixed-frame classification, rounding and sign
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.DispatchContracts
import Tablet.P9_T1_DispatchFrame
import Tablet.P9_T1_EmbedComponents
import Tablet.P616_T1_SignStrippedClassification
import Tablet.P616_T1_RoundingCellConvexity
import Tablet.ClassificationDeterminism
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.ModelF64MantissaDigits
import Tablet.ModelU64Shl
import Tablet.ModelU64BitOr
import Tablet.num_imp_dec2flt_pfe_empty
import Tablet.num_imp_dec2flt_pfe_invalid
import Tablet.num_imp_traits_Float_SIG_BITS_default
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_FrameCorrectness]
theorem P616_T1_FrameCorrectness :
forall C : P9_T1_AbstractComponents, DispatchContracts C ->
forall (s : Str) r trace, DecimalGoalVocabularyDefault.sourceString s ->
s.val.length <= 3458764513820540928 ->
P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s = ok (r, trace) ->
((DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s) none ->
exists error, r = core.result.Result.Err error) ∧
(forall sign nan,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inr (sign, nan))) ->
exists f, r = core.result.Result.Ok f ∧
(if nan then DecimalGoalVocabularyDefault.isNan f
else DecimalGoalVocabularyDefault.isInfinity (decide (sign = some true)) f)) ∧
(forall x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inl x)) ->
exists f magnitude, r = core.result.Result.Ok f ∧
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.accumulatedMagnitude x) magnitude ∧
DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude f)) := 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
number_reject, using nonemptiness and the A-bound, forces
C.\mathrm{parseNumber}(b)=\mathrm{None}. In that branch the full-domain
special_reject law forces C.\mathrm{parseSpecial}(b,\nu)=\mathrm{None}.
The frame returns Rust Err of the normal Invalid error and the Invalid
trace with these two None observations. The earlier empty and sign-only
branches already returned Rust Err, so the invalid assertion holds in
all cases.number_reject forces None before any special call. Depending on
the NaN Boolean, special_nan or special_infinity supplies Some f with
exactly the claimed word predicate at sign \nu. The frame's Special
branch returns that same f and records the numeric None and special
Some. It executes neither numeric conversion nor a second negation;
the separate special sign has already been applied by its law.
This proves the special assertion and respects numeric-before-special
ordering rather than replacing the two calls by a free classifier.number_accept
gives C.\mathrm{parseNumber}(b)=\mathrm{Some}(d) for some record.
Record_bounds gives d.\mathit{negative}=\mathrm{false} and
w:=d.\mathit{mantissa}.\mathit{val}<10^{19}.
Put q=d.\mathit{exponent}.\mathit{val},
L=w10^q, U=(w+1)10^q, and
V=\mathrm{accumulatedMagnitude}(y)=\mathrm{accumulatedMagnitude}(x).
Record_accumulated gives V=L when many_digits is false and
L\leq V<U otherwise. Since 10^q>0, L\geq0 and L<U.many_digits flag is unchanged. If C.\mathrm{native}(d') is
Some f, native_normal supplies a magnitude m rounding L, the
signedMagnitude(\nu,m,f) predicate, and many_digits false.
The latter makes V=L by representation. Substituting this equality
gives rounding of V and thus of x's accumulated magnitude.
The FastPath branch returns exactly f and records the signed input;
there is no further sign operation on this branch. Its supplied sign
predicate and the equality of lexical sign prove the numeric assertion.Integer_normal says either f_1.p_{\rm biased}<0, or
C.\mathrm{assemble}(f_1) is a clear-sign rounding of L.
The scalar guard f_1.p_{\rm biased}\geq0 is exactly the opposite
integer inequality. There are the following exhaustive selections.many_digits is false and the first exponent is nonnegative, no second
call is executed and f_1 is selected without slow fallback. Its
assembled magnitude rounds L=V by the nondeferral alternative.
If the first exponent is negative, regardless of many_digits, the second
guard is false and the unchanged negative pair reaches slow fallback.
Slow_normal applies on the source-valid unsigned numeric b, with no
A restriction needed, and says that the assembled slow replacement is
a clear-sign rounding of V.many_digits true and first exponent nonnegative,
so the guarded second call is executed. The checked successor is normal
and exactly w+1: w<10^{19} implies w+1\leq10^{19}<2^{64}.
Thus its endpoint value is precisely U, not a wrapping successor.
Let f_2 be the second abstract integer result. The pair comparison
num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq
returns true precisely when both fields agree. Pair extensionality then
gives f_2=f_1. In this equality case f_2 too has nonnegative
exponent, so both integer_normal laws take their nondeferral alternative.
The same word m=C.\mathrm{assemble}(f_1)=C.\mathrm{assemble}(f_2)
rounds both L and U. Apply
RoundingCellConvexity with L\leq V and V<U
(hence V\leq U). It gives that m rounds V, including odd/even
ties and zero or infinity endpoints. The post-comparison pair remains
f_1, forced_deferral is false and there is no slow call.
If the comparison is false, the frame overwrites the first exponent
with -1. The post-comparison negative test is therefore true,
forced_deferral is true and the slow call uses the same b, not a
truncated record or a sign-bearing string. Slow_normal again supplies
the clear-sign rounding of V for the selected replacement. No value
law is required of the unequal endpoint pair itself.SIG_BITS computation num imp traits Float SIG BITS default
uses ModelF64MantissaDigits's 53 and checked subtraction of
one to give 52. This count is below 64, so the shift underlying
ModelU64Shl is the 64-bit modular shift. The OR underlying
ModelU64BitOr is total. Consequently the resulting trace
raw word has exactly the natural value in assembledWord(f_*,\cdot).
Contract assembly_all gives that same formula for m; word
extensionality identifies them. The embedded assembly call returns ok
of m, as recorded in assembly_result.negate_all together with
m.\mathit{val}<2^{63} gives
f.\mathit{val}=m.\mathit{val}+2^{63}. These are exactly both clauses
of signedMagnitude(\nu,m,f), including zero and infinity. The
sum is below 2^{64}, so this is the full natural word equation.
Replace \nu by the lexical-negative flag of x to obtain the stated
predicate.many_digits
record updates retain the original flag, its native input has the
overwritten sign, its first and guarded second operands and pairs are
the ones used above, and its comparison, forced-deferral and slow fields
are the selected branch's actual Booleans and options. Its raw and
assembly words are equal as proved; its lexical_sign_applied flag is
\nu, and its result is the final word just signed. Substitution in
the given normal equation and injectivity of ok identify its Rust
result r with Ok of this f. Native and special traces likewise
retain their direct-return values and select no assembly pair.
Thus every possible normal frame output has the three asserted
classification, accumulated-rounding and sign properties. No public
parser theorem or dispatch-composition theorem was used.Lean proof
classical
intro C hc s r trace hs hA hrun
have hbytes : ∀ b ∈ DecimalGoalVocabularyDefault.bytes s, b < 256 := by
intro b hb
dsimp [DecimalGoalVocabularyDefault] at hb ⊢
rcases List.mem_map.mp hb with ⟨u, hu, rfl⟩
exact u.bv.isLt
have bind_ok_inv : forall {alpha beta : Type} (x : Result alpha)
(g : alpha -> Result beta) y,
Bind.bind x g = ok y -> exists z, x = ok z /\ g z = ok y := by
intro alpha beta x g y hx
cases x with
| fail err => simp [Bind.bind, Aeneas.Std.bind] at hx
| div => simp [Bind.bind, Aeneas.Std.bind] at hx
| ok z => exact ⟨z, rfl, hx⟩
have noUnsignedNumericEmpty : forall x : DecimalLexeme,
DecimalGoalVocabularyDefault.validNumeric x -> x.leadingSign = none ->
DecimalGoalVocabularyDefault.renderNumeric x = [] -> False := by
intro x hv hs hr
dsimp only [DecimalGoalVocabularyDefault] at hv hs hr
rcases hv with ⟨_, _, hne, _⟩
cases hi : x.integerDigits with
| nil =>
cases hf : x.fractionDigits with
| none => simp_all [hi, hf]
| some ds => cases ds <;> simp_all [hi, hf]
| cons d ds => simp [hi] at hr
unfold P9_T1_DispatchFrame at hrun
obtain ⟨body, hbody, hrun⟩ := bind_ok_inv _ _ _ hrun
have hbody_eq : body = s := by
simpa only [core.str.Str.as_bytes, ModelStrAsBytes, Result.ok.injEq] using hbody.symm
subst body
obtain ⟨head, hhead, hrun⟩ := bind_ok_inv _ _ _ hrun
have hhead_eq : head = s.val.head? := by
simpa only [core.slice.Slice.first, ModelSliceFirst, Result.ok.injEq] using hhead.symm
subst head
cases hlist : s.val with
| nil =>
simp only [hlist, List.head?_nil] at hrun
obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro _
exact ⟨_, rfl⟩
constructor
· intro sign nan hclass
dsimp only [DecimalGoalVocabularyDefault] at hclass
simp [hlist] at hclass
· intro x hclass
dsimp only [DecimalGoalVocabularyDefault] at hclass
simp [hlist] at hclass
rcases hclass with ⟨_, _, hnonempty, _, _, hi, hf, _⟩
cases hfrac : x.fractionDigits <;> simp_all [hfrac]
| cons c tail =>
simp only [hlist, List.head?_cons] at hrun
obtain ⟨body1, hbody1, hrun⟩ := bind_ok_inv _ _ _ hrun
have hindex : core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize } = ok (s.drop 1#usize) := by
simp [Slice.index_SliceIndexRangeFromUsizeSliceInst,
core.slice.index.SliceIndexRangeFromUsizeSlice.index, hlist]
have hbodyval : body1.val = if c = 45#u8 ∨ c = 43#u8 then tail else s.val := by
by_cases hm : c = 45#u8
· simp [hm, hindex] at hbody1
subst body1
simp [Slice.drop, hlist, hm]
· by_cases hp : c = 43#u8
· simp [hp, hindex] at hbody1
subst body1
simp [Slice.drop, hlist, hp]
· simp only [hm, hp, ite_false, Result.ok.injEq] at hbody1
subst body1
simp [hm, hp]
have hbodyval' : body1.val =
if s.val.head? = some (45#u8) ∨ s.val.head? = some (43#u8)
then s.val.drop 1 else s.val := by
simpa [hlist, Slice.drop] using hbodyval
have hstrip := P616_T1_SignStrippedClassification s body1 hs hbodyval'
have hbodySource : SourceValidByteSlice body1 := hstrip.1
have hbodyLength : body1.val.length <= s.val.length := hstrip.2.1
obtain ⟨empty, hempty, hrun⟩ := bind_ok_inv _ _ _ hrun
have hempty_eq : empty = decide (body1.val = []) := by
simpa only [core.slice.Slice.is_empty, Slice.length,
List.length_eq_zero_iff, Result.ok.injEq] using hempty.symm
by_cases hbodyempty : body1.val = []
· simp only [hempty_eq, hbodyempty, decide_true, if_true] at hrun
obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro _
exact ⟨_, rfl⟩
constructor
· intro sign nan hclass
have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
dsimp only [DecimalGoalVocabularyDefault] at hsbody
simp [hbodyempty] at hsbody
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hrender : DecimalGoalVocabularyDefault.renderNumeric y = [] := by
dsimp only [DecimalGoalVocabularyDefault]
dsimp only [DecimalGoalVocabularyDefault] at hnum
simpa [y, hbodyempty] using hnum.2.1
exact (noUnsignedNumericEmpty y hnum.1 rfl hrender).elim
· have hempty_false : empty = false := by
simp [hempty_eq, hbodyempty]
rw [hempty_false] at hrun
obtain ⟨parsed, hparsed, hrun⟩ := bind_ok_inv _ _ _ hrun
cases parsed with
| none =>
obtain ⟨special, hspecial, hrun⟩ := bind_ok_inv _ _ _ hrun
cases special with
| none =>
obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro _
exact ⟨_, rfl⟩
constructor
· intro sign nan hclass
have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
cases nan with
| false =>
obtain ⟨f, hparse, _⟩ := hc.special_infinity body1 (decide (c = 45#u8))
hbodySource hsbody
have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
simpa [P9_T1_EmbedComponents] using hspecial
rw [hnone] at hparse
cases hparse
| true =>
obtain ⟨f, hparse, _⟩ := hc.special_nan body1 (decide (c = 45#u8))
hbodySource hsbody
have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
simpa [P9_T1_EmbedComponents] using hspecial
rw [hnone] at hparse
cases hparse
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
have hnone : C.parseNumber body1 = none := by
simpa [P9_T1_EmbedComponents] using hparsed
rw [hnone] at hparse
cases hparse
| some value =>
have hspecialC : C.parseSpecial body1 (decide (c = 45#u8)) = some value := by
simpa [P9_T1_EmbedComponents] using hspecial
cases hrun
constructor
· intro hclass
have hnoSpecial : ¬ exists nan,
DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body1) none nan := by
intro hx
obtain ⟨sign, nan, hclass'⟩ := hstrip.2.2.2.2.2 hx
exact hclass.2 ⟨sign, nan, hclass'⟩
have hnone := hc.special_reject body1 (decide (c = 45#u8))
hbodySource hnoSpecial
rw [hnone] at hspecialC
cases hspecialC
constructor
· intro sign nan hclass
have hsdata := hstrip.2.2.2.1 sign nan hclass
have hnegative : decide (sign = some true) = decide (c = 45#u8) := by
simpa [hlist] using hsdata.2
cases nan with
| false =>
obtain ⟨f, hparse, hinf⟩ := hc.special_infinity body1
(decide (c = 45#u8)) hbodySource hsdata.1
rw [hspecialC] at hparse
cases hparse
refine ⟨value, rfl, ?_⟩
simpa [hnegative] using hinf
| true =>
obtain ⟨f, hparse, hnan⟩ := hc.special_nan body1
(decide (c = 45#u8)) hbodySource hsdata.1
rw [hspecialC] at hparse
cases hparse
exact ⟨value, rfl, hnan⟩
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
have hnone : C.parseNumber body1 = none := by
simpa [P9_T1_EmbedComponents] using hparsed
rw [hnone] at hparse
cases hparse
| some d =>
have hparse : C.parseNumber body1 = some d := by
simpa [P9_T1_EmbedComponents] using hparsed
have hnotInvalid :
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) none -> False := by
intro hclass
have hnoBodyNum : ¬ exists y : DecimalLexeme,
y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
intro hx
obtain ⟨x', hx'⟩ := hstrip.2.2.2.2.1 hx
exact hclass.1 ⟨x', hx'⟩
have hn := hc.number_reject body1 hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) hnoBodyNum
simp [hn] at hparse
have hnotSpecial : ∀ sign nan,
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan))) -> False := by
intro sign nan hclass
have hnoFullNum : ¬ exists x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inl x)) := by
intro hx
obtain ⟨x, hx⟩ := hx
have heq := ClassificationDeterminism.1
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan)))
(some (Sum.inl x)) hbytes hclass hx
cases heq
have hnoBodyNum : ¬ exists y : DecimalLexeme,
y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
intro hx
obtain ⟨x, hx⟩ := hstrip.2.2.2.2.1 hx
exact hnoFullNum ⟨x, hx⟩
have hn := hc.number_reject body1 hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) hnoBodyNum
simp [hn] at hparse
obtain ⟨fast, hfast, hrun⟩ := bind_ok_inv _ _ _ hrun
cases fast with
| none =>
have hnativeNone : C.native
{ d with negative := decide (c = 45#u8), many_digits := d.many_digits } = none := by
change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
ok none at hfast
injection hfast with hnativeNone
obtain ⟨first, hfirst, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨phase1, hphase1, hrun⟩ := bind_ok_inv _ _ _ hrun
rcases phase1 with ⟨many1, many2, first1, fp, secondGuard⟩
obtain ⟨phase2, hphase2, hrun⟩ := bind_ok_inv _ _ _ hrun
rcases phase2 with ⟨post, secondExp, secondMant, secondResult,
secondEqual, forced⟩
obtain ⟨phase3, hphase3, hrun⟩ := bind_ok_inv _ _ _ hrun
rcases phase3 with ⟨selected, slowGuard, slowResult⟩
have hfirstC : C.integer d.exponent d.mantissa = first := by
change ok (C.integer d.exponent d.mantissa) = ok first at hfirst
injection hfirst with hfirstC
by_cases hmany : d.many_digits
· simp only [hmany, if_pos] at hphase1
cases hphase1
by_cases hfirstNegative : first.p_biased < 0#i32
· have hltVal : first.p_biased.val < 0 := by simpa using hfirstNegative
have hfirstBelow : ¬ 0 ≤ first.p_biased.val := by omega
simp [hfirstBelow] at hphase2
rcases hphase2 with ⟨hpost, hphase2⟩
subst post
simp only [hfirstNegative, if_pos] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate magnitude := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate magnitude := by rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true magnitude (C.negate magnitude) := by
change magnitude.val < 2 ^ 63 ∧
(C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all magnitude]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
(C.negate magnitude) := by rw [hlex]; exact hsign
exact ⟨C.negate magnitude, magnitude,
congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false magnitude magnitude := by
change magnitude.val < 2 ^ 63 ∧
magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
· have hnotLtVal : ¬ first.p_biased.val < 0 := by simpa using hfirstNegative
have hfirstNonneg : 0 ≤ first.p_biased.val := by omega
simp [hfirstNonneg] at hphase2
obtain ⟨next, hnext, hphase2⟩ := bind_ok_inv _ _ _ hphase2
obtain ⟨second, hsecond, hphase2⟩ := bind_ok_inv _ _ _ hphase2
obtain ⟨equal, hequal, hphase2⟩ := bind_ok_inv _ _ _ hphase2
cases equal
· simp at hphase2
rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
have hpostNegative : post.p_biased < 0#i32 := by
rw [← hpost]
simp
simp only [hpostNegative, if_pos] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate magnitude := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate magnitude := by rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true magnitude (C.negate magnitude) := by
change magnitude.val < 2 ^ 63 ∧
(C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all magnitude]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
(C.negate magnitude) := by rw [hlex]; exact hsign
exact ⟨C.negate magnitude, magnitude,
congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false magnitude magnitude := by
change magnitude.val < 2 ^ 63 ∧
magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
· simp at hphase2
rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
subst post
simp [hfirstNegative] at hphase3
have hselected : selected = first := by
exact hphase3.1.symm
subst selected
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
have hassemblyC : C.assemble first = assembly := by
change ok (C.assemble first) = ok assembly at hassembly
injection hassembly with hassemblyC
have hsecondC : C.integer d.exponent next = second := by
change ok (C.integer d.exponent next) = ok second at hsecond
injection hsecond with hsecondC
have hpair : first = second := by
have hm : first.m = second.m := by
by_contra h
simp [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, h] at hequal
have hp : first.p_biased = second.p_biased := by
have hh : decide (first.p_biased = second.p_biased) = true := by
simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, hm] using hequal
simpa using hh
have hf := And.intro hm hp
rcases hf with ⟨hm, hp⟩
cases first
cases second
cases hm
cases hp
rfl
have hnextval : next.val = d.mantissa.val + 1 := by
have hadd := UScalar.add_equiv d.mantissa (1#u64)
rw [hnext] at hadd
simpa using hadd.2.1
have hbounds := hc.record_bounds body1 d hbodySource hbodyempty hparse
have hfirstNormal := hc.integer_normal d.exponent d.mantissa
have hfirstRound : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
rw [hfirstC]
exact hnotLtVal
rcases hfirstNormal with hneg | ⟨hr, hclear⟩
· exact (hnot hneg).elim
· simpa only [DecimalGoalVocabularyDefault, hfirstC] using hr
have hfirstClear : (C.assemble first).val < 2 ^ 63 := by
have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
rw [hfirstC]
exact hnotLtVal
rcases hfirstNormal with hneg | ⟨hr, hclear⟩
· exact (hnot hneg).elim
· simpa [hfirstC] using hclear
have hsecondNormal := hc.integer_normal d.exponent next
have hsecondRound : DecimalGoalVocabularyDefault.roundsMagnitude
((next.val : Real) * (10 : Real) ^ d.exponent.val)
(C.assemble second) := by
have hnot : ¬ (C.integer d.exponent next).p_biased.val < 0 := by
rw [hsecondC, ← hpair]
exact hnotLtVal
rcases hsecondNormal with hneg | ⟨hr, hclear⟩
· exact (hnot hneg).elim
· simpa [hsecondC] using hr
have hsecondRound' : DecimalGoalVocabularyDefault.roundsMagnitude
((((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val))
(C.assemble first) := by
rw [← hpair] at hsecondRound
rw [hnextval] at hsecondRound
exact hsecondRound
have hupperRewrite :
((next.val : Real) * (10 : Real) ^ d.exponent.val) =
(((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
rw [hnextval]
have hsecondRound'' := hsecondRound
rw [hupperRewrite] at hsecondRound''
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hinterval :
DecimalGoalVocabularyDefault.decimalMagnitude d ≤
DecimalGoalVocabularyDefault.accumulatedMagnitude y ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude y <
(((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
simpa [hmany] using hacc
have hroundMag := P616_T1_RoundingCellConvexity
(DecimalGoalVocabularyDefault.decimalMagnitude d)
(((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val)
(DecimalGoalVocabularyDefault.accumulatedMagnitude y) (C.assemble first)
hfirstRound hsecondRound' hinterval.1 (le_of_lt hinterval.2)
have hround := hroundMag
rw [hnum.2.2.1] at hround
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate (C.assemble first) := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate (C.assemble first) := by rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true (C.assemble first) (C.negate (C.assemble first)) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.negate (C.assemble first)).val =
(C.assemble first).val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all]
constructor
· exact hfirstClear
· rw [if_pos hfirstClear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) (C.negate (C.assemble first)) := by
rw [hlex]
exact hsign
exact ⟨C.negate (C.assemble first), C.assemble first,
congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false (C.assemble first) (C.assemble first) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.assemble first).val =
(C.assemble first).val + (if false then 2 ^ 63 else 0)
constructor
· exact hfirstClear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) assembly := by
rw [hlex, ← hassemblyC]
exact hsign
exact ⟨assembly, C.assemble first, rfl, hround, hsignLex⟩
· simp only [hmany, Bool.false_eq_true, if_false] at hphase1
cases hphase1
simp only [Bool.false_eq_true, if_false] at hphase2
cases hphase2
by_cases hfirstNegative : first.p_biased < 0#i32
· simp only [hfirstNegative, if_pos] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate magnitude := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate magnitude := by
rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true magnitude (C.negate magnitude) := by
change magnitude.val < 2 ^ 63 ∧
(C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all magnitude]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
(C.negate magnitude) := by
rw [hlex]
exact hsign
exact ⟨C.negate magnitude, magnitude, congrArg
(fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false magnitude magnitude := by
change magnitude.val < 2 ^ 63 ∧
magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
· simp only [hfirstNegative, if_neg] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
have hassemblyC : C.assemble first = assembly := by
change ok (C.assemble first) = ok assembly at hassembly
injection hassembly with hassemblyC
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
simpa [hmany] using hacc
have hinteger := hc.integer_normal d.exponent d.mantissa
have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hr
have hround := hroundD
rw [hdecimal, hnum.2.2.1] at hround
have hclear : (C.assemble first).val < 2 ^ 63 := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hclear
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true (C.assemble first) (C.negate (C.assemble first)) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.negate (C.assemble first)).val =
(C.assemble first).val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) (C.negate (C.assemble first)) := by
rw [hlex]
exact hsign
have hresult : result = C.negate (C.assemble first) := by
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
simpa [hassemblyC] using hnegateC.symm
exact ⟨C.negate (C.assemble first), C.assemble first,
congrArg (fun z => core.result.Result.Ok z) hresult,
hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
simpa [hmany] using hacc
have hinteger := hc.integer_normal d.exponent d.mantissa
have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hr
have hround := hroundD
rw [hdecimal, hnum.2.2.1] at hround
have hclear : (C.assemble first).val < 2 ^ 63 := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hclear
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false (C.assemble first) (C.assemble first) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.assemble first).val =
(C.assemble first).val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) (C.assemble first) := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, C.assemble first, rfl, hround, hsignLexAssembly⟩
| some value =>
have hnative : C.native
{ d with negative := decide (c = 45#u8), many_digits := d.many_digits } = some value := by
change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
ok (some value) at hfast
injection hfast with hnative
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let nativeRecord : num.imp.dec2flt.decimal.Decimal :=
{ d with negative := decide (c = 45#u8), many_digits := d.many_digits }
have hnum := hstrip.2.2.1 x hclass
have hnativeNormal := hc.native_normal nativeRecord value hnative
rcases hnativeNormal with ⟨hmd, hrest⟩
rcases hrest with ⟨magnitude, hround, hsigned⟩
have hmany : d.many_digits = false := by
change nativeRecord.many_digits = false at hmd
simpa [nativeRecord] using hmd
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
simpa [hmany] using hacc
have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) magnitude := by
simpa only [DecimalGoalVocabularyDefault] using hround
rw [hdecimal, hnum.2.2.1] at hroundD
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = decide (c = 45#u8) := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = decide (c = 45#u8) := by simp [hlist]
have hsigned' : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude value := by
rw [hlex]
simpa only [DecimalGoalVocabularyDefault, nativeRecord] using hsigned
exact ⟨value, magnitude, rfl, hroundD, hsigned'⟩
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.DispatchContracts
import Tablet.P9_T1_DispatchFrame
import Tablet.P9_T1_EmbedComponents
import Tablet.P616_T1_SignStrippedClassification
import Tablet.P616_T1_RoundingCellConvexity
import Tablet.ClassificationDeterminism
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.ModelF64MantissaDigits
import Tablet.ModelU64Shl
import Tablet.ModelU64BitOr
import Tablet.num_imp_dec2flt_pfe_empty
import Tablet.num_imp_dec2flt_pfe_invalid
import Tablet.num_imp_traits_Float_SIG_BITS_default
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_FrameCorrectness]
theorem P616_T1_FrameCorrectness :
forall C : P9_T1_AbstractComponents, DispatchContracts C ->
forall (s : Str) r trace, DecimalGoalVocabularyDefault.sourceString s ->
s.val.length <= 3458764513820540928 ->
P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s = ok (r, trace) ->
((DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s) none ->
exists error, r = core.result.Result.Err error) ∧
(forall sign nan,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inr (sign, nan))) ->
exists f, r = core.result.Result.Ok f ∧
(if nan then DecimalGoalVocabularyDefault.isNan f
else DecimalGoalVocabularyDefault.isInfinity (decide (sign = some true)) f)) ∧
(forall x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
(some (Sum.inl x)) ->
exists f magnitude, r = core.result.Result.Ok f ∧
DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.accumulatedMagnitude x) magnitude ∧
DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude f)) := by
-- BODY
classical
intro C hc s r trace hs hA hrun
have hbytes : ∀ b ∈ DecimalGoalVocabularyDefault.bytes s, b < 256 := by
intro b hb
dsimp [DecimalGoalVocabularyDefault] at hb ⊢
rcases List.mem_map.mp hb with ⟨u, hu, rfl⟩
exact u.bv.isLt
have bind_ok_inv : forall {alpha beta : Type} (x : Result alpha)
(g : alpha -> Result beta) y,
Bind.bind x g = ok y -> exists z, x = ok z /\ g z = ok y := by
intro alpha beta x g y hx
cases x with
| fail err => simp [Bind.bind, Aeneas.Std.bind] at hx
| div => simp [Bind.bind, Aeneas.Std.bind] at hx
| ok z => exact ⟨z, rfl, hx⟩
have noUnsignedNumericEmpty : forall x : DecimalLexeme,
DecimalGoalVocabularyDefault.validNumeric x -> x.leadingSign = none ->
DecimalGoalVocabularyDefault.renderNumeric x = [] -> False := by
intro x hv hs hr
dsimp only [DecimalGoalVocabularyDefault] at hv hs hr
rcases hv with ⟨_, _, hne, _⟩
cases hi : x.integerDigits with
| nil =>
cases hf : x.fractionDigits with
| none => simp_all [hi, hf]
| some ds => cases ds <;> simp_all [hi, hf]
| cons d ds => simp [hi] at hr
unfold P9_T1_DispatchFrame at hrun
obtain ⟨body, hbody, hrun⟩ := bind_ok_inv _ _ _ hrun
have hbody_eq : body = s := by
simpa only [core.str.Str.as_bytes, ModelStrAsBytes, Result.ok.injEq] using hbody.symm
subst body
obtain ⟨head, hhead, hrun⟩ := bind_ok_inv _ _ _ hrun
have hhead_eq : head = s.val.head? := by
simpa only [core.slice.Slice.first, ModelSliceFirst, Result.ok.injEq] using hhead.symm
subst head
cases hlist : s.val with
| nil =>
simp only [hlist, List.head?_nil] at hrun
obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro _
exact ⟨_, rfl⟩
constructor
· intro sign nan hclass
dsimp only [DecimalGoalVocabularyDefault] at hclass
simp [hlist] at hclass
· intro x hclass
dsimp only [DecimalGoalVocabularyDefault] at hclass
simp [hlist] at hclass
rcases hclass with ⟨_, _, hnonempty, _, _, hi, hf, _⟩
cases hfrac : x.fractionDigits <;> simp_all [hfrac]
| cons c tail =>
simp only [hlist, List.head?_cons] at hrun
obtain ⟨body1, hbody1, hrun⟩ := bind_ok_inv _ _ _ hrun
have hindex : core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := 1#usize } = ok (s.drop 1#usize) := by
simp [Slice.index_SliceIndexRangeFromUsizeSliceInst,
core.slice.index.SliceIndexRangeFromUsizeSlice.index, hlist]
have hbodyval : body1.val = if c = 45#u8 ∨ c = 43#u8 then tail else s.val := by
by_cases hm : c = 45#u8
· simp [hm, hindex] at hbody1
subst body1
simp [Slice.drop, hlist, hm]
· by_cases hp : c = 43#u8
· simp [hp, hindex] at hbody1
subst body1
simp [Slice.drop, hlist, hp]
· simp only [hm, hp, ite_false, Result.ok.injEq] at hbody1
subst body1
simp [hm, hp]
have hbodyval' : body1.val =
if s.val.head? = some (45#u8) ∨ s.val.head? = some (43#u8)
then s.val.drop 1 else s.val := by
simpa [hlist, Slice.drop] using hbodyval
have hstrip := P616_T1_SignStrippedClassification s body1 hs hbodyval'
have hbodySource : SourceValidByteSlice body1 := hstrip.1
have hbodyLength : body1.val.length <= s.val.length := hstrip.2.1
obtain ⟨empty, hempty, hrun⟩ := bind_ok_inv _ _ _ hrun
have hempty_eq : empty = decide (body1.val = []) := by
simpa only [core.slice.Slice.is_empty, Slice.length,
List.length_eq_zero_iff, Result.ok.injEq] using hempty.symm
by_cases hbodyempty : body1.val = []
· simp only [hempty_eq, hbodyempty, decide_true, if_true] at hrun
obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro _
exact ⟨_, rfl⟩
constructor
· intro sign nan hclass
have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
dsimp only [DecimalGoalVocabularyDefault] at hsbody
simp [hbodyempty] at hsbody
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hrender : DecimalGoalVocabularyDefault.renderNumeric y = [] := by
dsimp only [DecimalGoalVocabularyDefault]
dsimp only [DecimalGoalVocabularyDefault] at hnum
simpa [y, hbodyempty] using hnum.2.1
exact (noUnsignedNumericEmpty y hnum.1 rfl hrender).elim
· have hempty_false : empty = false := by
simp [hempty_eq, hbodyempty]
rw [hempty_false] at hrun
obtain ⟨parsed, hparsed, hrun⟩ := bind_ok_inv _ _ _ hrun
cases parsed with
| none =>
obtain ⟨special, hspecial, hrun⟩ := bind_ok_inv _ _ _ hrun
cases special with
| none =>
obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro _
exact ⟨_, rfl⟩
constructor
· intro sign nan hclass
have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
cases nan with
| false =>
obtain ⟨f, hparse, _⟩ := hc.special_infinity body1 (decide (c = 45#u8))
hbodySource hsbody
have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
simpa [P9_T1_EmbedComponents] using hspecial
rw [hnone] at hparse
cases hparse
| true =>
obtain ⟨f, hparse, _⟩ := hc.special_nan body1 (decide (c = 45#u8))
hbodySource hsbody
have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
simpa [P9_T1_EmbedComponents] using hspecial
rw [hnone] at hparse
cases hparse
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
have hnone : C.parseNumber body1 = none := by
simpa [P9_T1_EmbedComponents] using hparsed
rw [hnone] at hparse
cases hparse
| some value =>
have hspecialC : C.parseSpecial body1 (decide (c = 45#u8)) = some value := by
simpa [P9_T1_EmbedComponents] using hspecial
cases hrun
constructor
· intro hclass
have hnoSpecial : ¬ exists nan,
DecimalGoalVocabularyDefault.specialLiteral
(DecimalGoalVocabularyDefault.bytes body1) none nan := by
intro hx
obtain ⟨sign, nan, hclass'⟩ := hstrip.2.2.2.2.2 hx
exact hclass.2 ⟨sign, nan, hclass'⟩
have hnone := hc.special_reject body1 (decide (c = 45#u8))
hbodySource hnoSpecial
rw [hnone] at hspecialC
cases hspecialC
constructor
· intro sign nan hclass
have hsdata := hstrip.2.2.2.1 sign nan hclass
have hnegative : decide (sign = some true) = decide (c = 45#u8) := by
simpa [hlist] using hsdata.2
cases nan with
| false =>
obtain ⟨f, hparse, hinf⟩ := hc.special_infinity body1
(decide (c = 45#u8)) hbodySource hsdata.1
rw [hspecialC] at hparse
cases hparse
refine ⟨value, rfl, ?_⟩
simpa [hnegative] using hinf
| true =>
obtain ⟨f, hparse, hnan⟩ := hc.special_nan body1
(decide (c = 45#u8)) hbodySource hsdata.1
rw [hspecialC] at hparse
cases hparse
exact ⟨value, rfl, hnan⟩
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
have hnone : C.parseNumber body1 = none := by
simpa [P9_T1_EmbedComponents] using hparsed
rw [hnone] at hparse
cases hparse
| some d =>
have hparse : C.parseNumber body1 = some d := by
simpa [P9_T1_EmbedComponents] using hparsed
have hnotInvalid :
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) none -> False := by
intro hclass
have hnoBodyNum : ¬ exists y : DecimalLexeme,
y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
intro hx
obtain ⟨x', hx'⟩ := hstrip.2.2.2.2.1 hx
exact hclass.1 ⟨x', hx'⟩
have hn := hc.number_reject body1 hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) hnoBodyNum
simp [hn] at hparse
have hnotSpecial : ∀ sign nan,
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan))) -> False := by
intro sign nan hclass
have hnoFullNum : ¬ exists x : DecimalLexeme,
DecimalGoalVocabularyDefault.classifies
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inl x)) := by
intro hx
obtain ⟨x, hx⟩ := hx
have heq := ClassificationDeterminism.1
(DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan)))
(some (Sum.inl x)) hbytes hclass hx
cases heq
have hnoBodyNum : ¬ exists y : DecimalLexeme,
y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
intro hx
obtain ⟨x, hx⟩ := hstrip.2.2.2.2.1 hx
exact hnoFullNum ⟨x, hx⟩
have hn := hc.number_reject body1 hbodySource hbodyempty
(Nat.le_trans hbodyLength hA) hnoBodyNum
simp [hn] at hparse
obtain ⟨fast, hfast, hrun⟩ := bind_ok_inv _ _ _ hrun
cases fast with
| none =>
have hnativeNone : C.native
{ d with negative := decide (c = 45#u8), many_digits := d.many_digits } = none := by
change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
ok none at hfast
injection hfast with hnativeNone
obtain ⟨first, hfirst, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨phase1, hphase1, hrun⟩ := bind_ok_inv _ _ _ hrun
rcases phase1 with ⟨many1, many2, first1, fp, secondGuard⟩
obtain ⟨phase2, hphase2, hrun⟩ := bind_ok_inv _ _ _ hrun
rcases phase2 with ⟨post, secondExp, secondMant, secondResult,
secondEqual, forced⟩
obtain ⟨phase3, hphase3, hrun⟩ := bind_ok_inv _ _ _ hrun
rcases phase3 with ⟨selected, slowGuard, slowResult⟩
have hfirstC : C.integer d.exponent d.mantissa = first := by
change ok (C.integer d.exponent d.mantissa) = ok first at hfirst
injection hfirst with hfirstC
by_cases hmany : d.many_digits
· simp only [hmany, if_pos] at hphase1
cases hphase1
by_cases hfirstNegative : first.p_biased < 0#i32
· have hltVal : first.p_biased.val < 0 := by simpa using hfirstNegative
have hfirstBelow : ¬ 0 ≤ first.p_biased.val := by omega
simp [hfirstBelow] at hphase2
rcases hphase2 with ⟨hpost, hphase2⟩
subst post
simp only [hfirstNegative, if_pos] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate magnitude := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate magnitude := by rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true magnitude (C.negate magnitude) := by
change magnitude.val < 2 ^ 63 ∧
(C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all magnitude]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
(C.negate magnitude) := by rw [hlex]; exact hsign
exact ⟨C.negate magnitude, magnitude,
congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false magnitude magnitude := by
change magnitude.val < 2 ^ 63 ∧
magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
· have hnotLtVal : ¬ first.p_biased.val < 0 := by simpa using hfirstNegative
have hfirstNonneg : 0 ≤ first.p_biased.val := by omega
simp [hfirstNonneg] at hphase2
obtain ⟨next, hnext, hphase2⟩ := bind_ok_inv _ _ _ hphase2
obtain ⟨second, hsecond, hphase2⟩ := bind_ok_inv _ _ _ hphase2
obtain ⟨equal, hequal, hphase2⟩ := bind_ok_inv _ _ _ hphase2
cases equal
· simp at hphase2
rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
have hpostNegative : post.p_biased < 0#i32 := by
rw [← hpost]
simp
simp only [hpostNegative, if_pos] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate magnitude := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate magnitude := by rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true magnitude (C.negate magnitude) := by
change magnitude.val < 2 ^ 63 ∧
(C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all magnitude]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
(C.negate magnitude) := by rw [hlex]; exact hsign
exact ⟨C.negate magnitude, magnitude,
congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false magnitude magnitude := by
change magnitude.val < 2 ^ 63 ∧
magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
· simp at hphase2
rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
subst post
simp [hfirstNegative] at hphase3
have hselected : selected = first := by
exact hphase3.1.symm
subst selected
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
have hassemblyC : C.assemble first = assembly := by
change ok (C.assemble first) = ok assembly at hassembly
injection hassembly with hassemblyC
have hsecondC : C.integer d.exponent next = second := by
change ok (C.integer d.exponent next) = ok second at hsecond
injection hsecond with hsecondC
have hpair : first = second := by
have hm : first.m = second.m := by
by_contra h
simp [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, h] at hequal
have hp : first.p_biased = second.p_biased := by
have hh : decide (first.p_biased = second.p_biased) = true := by
simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, hm] using hequal
simpa using hh
have hf := And.intro hm hp
rcases hf with ⟨hm, hp⟩
cases first
cases second
cases hm
cases hp
rfl
have hnextval : next.val = d.mantissa.val + 1 := by
have hadd := UScalar.add_equiv d.mantissa (1#u64)
rw [hnext] at hadd
simpa using hadd.2.1
have hbounds := hc.record_bounds body1 d hbodySource hbodyempty hparse
have hfirstNormal := hc.integer_normal d.exponent d.mantissa
have hfirstRound : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
rw [hfirstC]
exact hnotLtVal
rcases hfirstNormal with hneg | ⟨hr, hclear⟩
· exact (hnot hneg).elim
· simpa only [DecimalGoalVocabularyDefault, hfirstC] using hr
have hfirstClear : (C.assemble first).val < 2 ^ 63 := by
have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
rw [hfirstC]
exact hnotLtVal
rcases hfirstNormal with hneg | ⟨hr, hclear⟩
· exact (hnot hneg).elim
· simpa [hfirstC] using hclear
have hsecondNormal := hc.integer_normal d.exponent next
have hsecondRound : DecimalGoalVocabularyDefault.roundsMagnitude
((next.val : Real) * (10 : Real) ^ d.exponent.val)
(C.assemble second) := by
have hnot : ¬ (C.integer d.exponent next).p_biased.val < 0 := by
rw [hsecondC, ← hpair]
exact hnotLtVal
rcases hsecondNormal with hneg | ⟨hr, hclear⟩
· exact (hnot hneg).elim
· simpa [hsecondC] using hr
have hsecondRound' : DecimalGoalVocabularyDefault.roundsMagnitude
((((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val))
(C.assemble first) := by
rw [← hpair] at hsecondRound
rw [hnextval] at hsecondRound
exact hsecondRound
have hupperRewrite :
((next.val : Real) * (10 : Real) ^ d.exponent.val) =
(((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
rw [hnextval]
have hsecondRound'' := hsecondRound
rw [hupperRewrite] at hsecondRound''
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hinterval :
DecimalGoalVocabularyDefault.decimalMagnitude d ≤
DecimalGoalVocabularyDefault.accumulatedMagnitude y ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude y <
(((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
simpa [hmany] using hacc
have hroundMag := P616_T1_RoundingCellConvexity
(DecimalGoalVocabularyDefault.decimalMagnitude d)
(((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val)
(DecimalGoalVocabularyDefault.accumulatedMagnitude y) (C.assemble first)
hfirstRound hsecondRound' hinterval.1 (le_of_lt hinterval.2)
have hround := hroundMag
rw [hnum.2.2.1] at hround
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate (C.assemble first) := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate (C.assemble first) := by rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true (C.assemble first) (C.negate (C.assemble first)) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.negate (C.assemble first)).val =
(C.assemble first).val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all]
constructor
· exact hfirstClear
· rw [if_pos hfirstClear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) (C.negate (C.assemble first)) := by
rw [hlex]
exact hsign
exact ⟨C.negate (C.assemble first), C.assemble first,
congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false (C.assemble first) (C.assemble first) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.assemble first).val =
(C.assemble first).val + (if false then 2 ^ 63 else 0)
constructor
· exact hfirstClear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) assembly := by
rw [hlex, ← hassemblyC]
exact hsign
exact ⟨assembly, C.assemble first, rfl, hround, hsignLex⟩
· simp only [hmany, Bool.false_eq_true, if_false] at hphase1
cases hphase1
simp only [Bool.false_eq_true, if_false] at hphase2
cases hphase2
by_cases hfirstNegative : first.p_biased < 0#i32
· simp only [hfirstNegative, if_pos] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
have hresult : result = C.negate magnitude := by
calc
result = C.negate assembly := hnegateC.symm
_ = C.negate magnitude := by
rw [← hassemblyC]
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true magnitude (C.negate magnitude) := by
change magnitude.val < 2 ^ 63 ∧
(C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all magnitude]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
(C.negate magnitude) := by
rw [hlex]
exact hsign
exact ⟨C.negate magnitude, magnitude, congrArg
(fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let magnitude := C.assemble (C.slow body1)
have hnum := hstrip.2.2.1 x hclass
have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
have hround := hslow.1
rw [hnum.2.2.1] at hround
have hclear := hslow.2
have hassemblyC : C.assemble (C.slow body1) = assembly := by
change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
injection hassembly with hassemblyC
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false magnitude magnitude := by
change magnitude.val < 2 ^ 63 ∧
magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
· simp only [hfirstNegative, if_neg] at hphase3
cases hphase3
obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
have hassemblyC : C.assemble first = assembly := by
change ok (C.assemble first) = ok assembly at hassembly
injection hassembly with hassemblyC
by_cases hnegative : c = 45#u8
· simp only [hnegative, if_pos] at hrun
obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
simpa [hmany] using hacc
have hinteger := hc.integer_normal d.exponent d.mantissa
have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hr
have hround := hroundD
rw [hdecimal, hnum.2.2.1] at hround
have hclear : (C.assemble first).val < 2 ^ 63 := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hclear
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = true := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
true (C.assemble first) (C.negate (C.assemble first)) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.negate (C.assemble first)).val =
(C.assemble first).val + (if true then 2 ^ 63 else 0)
rw [hc.negate_all]
constructor
· exact hclear
· rw [if_pos hclear]
simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) (C.negate (C.assemble first)) := by
rw [hlex]
exact hsign
have hresult : result = C.negate (C.assemble first) := by
have hnegateC : C.negate assembly = result := by
change ok (C.negate assembly) = ok result at hnegate
injection hnegate with hnegateC
simpa [hassemblyC] using hnegateC.symm
exact ⟨C.negate (C.assemble first), C.assemble first,
congrArg (fun z => core.result.Result.Ok z) hresult,
hround, hsignLex⟩
· simp only [hnegative, if_neg] at hrun
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
have hnum := hstrip.2.2.1 x hclass
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
simpa [hmany] using hacc
have hinteger := hc.integer_normal d.exponent d.mantissa
have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hr
have hround := hroundD
rw [hdecimal, hnum.2.2.1] at hround
have hclear : (C.assemble first).val < 2 ^ 63 := by
have hnonneg : ¬ first.p_biased.val < 0 := by
simpa using hfirstNegative
rw [← hfirstC] at hnonneg
rcases hinteger with hneg | ⟨hr, hclear⟩
· exact (hnonneg hneg).elim
· simpa [hfirstC] using hclear
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = false := by simp [hlist, hnegative]
have hsign : DecimalGoalVocabularyDefault.signedMagnitude
false (C.assemble first) (C.assemble first) := by
change (C.assemble first).val < 2 ^ 63 ∧
(C.assemble first).val =
(C.assemble first).val + (if false then 2 ^ 63 else 0)
constructor
· exact hclear
· simp
have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) (C.assemble first) := by
rw [hlex]
exact hsign
have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x)
(C.assemble first) assembly := by
rw [← hassemblyC]
exact hsignLex
exact ⟨assembly, C.assemble first, rfl, hround, hsignLexAssembly⟩
| some value =>
have hnative : C.native
{ d with negative := decide (c = 45#u8), many_digits := d.many_digits } = some value := by
change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
ok (some value) at hfast
injection hfast with hnative
cases hrun
constructor
· intro hclass
exact (hnotInvalid hclass).elim
constructor
· intro sign nan hclass
exact (hnotSpecial sign nan hclass).elim
· intro x hclass
let y : DecimalLexeme := { x with leadingSign := none }
let nativeRecord : num.imp.dec2flt.decimal.Decimal :=
{ d with negative := decide (c = 45#u8), many_digits := d.many_digits }
have hnum := hstrip.2.2.1 x hclass
have hnativeNormal := hc.native_normal nativeRecord value hnative
rcases hnativeNormal with ⟨hmd, hrest⟩
rcases hrest with ⟨magnitude, hround, hsigned⟩
have hmany : d.many_digits = false := by
change nativeRecord.many_digits = false at hmd
simpa [nativeRecord] using hmd
have hacc := hc.record_accumulated body1 y d hbodySource
(Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
simpa [hmany] using hacc
have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
(DecimalGoalVocabularyDefault.decimalMagnitude d) magnitude := by
simpa only [DecimalGoalVocabularyDefault] using hround
rw [hdecimal, hnum.2.2.1] at hroundD
have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = decide (c = 45#u8) := by
calc
DecimalGoalVocabularyDefault.lexicalNegative x =
decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
_ = decide (c = 45#u8) := by simp [hlist]
have hsigned' : DecimalGoalVocabularyDefault.signedMagnitude
(DecimalGoalVocabularyDefault.lexicalNegative x) magnitude value := by
rw [hlex]
simpa only [DecimalGoalVocabularyDefault, nativeRecord] using hsigned
exact ⟨value, magnitude, rfl, hroundD, hsigned'⟩
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- ClassificationDeterminism
- DispatchContracts
- ModelF64MantissaDigits
- ModelSliceFirst
- ModelStrAsBytes
- ModelU64BitOr
All 15 entries
- ClassificationDeterminism
- DispatchContracts
- ModelF64MantissaDigits
- ModelSliceFirst
- ModelStrAsBytes
- ModelU64BitOr
- ModelU64Shl
- RoundingCellConvexity
- SignStrippedClassification
- DispatchFrame
- EmbedComponents
- num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq
- num imp dec2flt pfe empty
- num imp dec2flt pfe invalid
- num imp traits Float SIG BITS default
Inspect related source (199)
- eq · dec2flt/common.rs:55 Program Rust
- pfe_empty · dec2flt/mod.rs:270 Program Rust
- pfe_invalid · dec2flt/mod.rs:277 Program Rust
More program dependencies (157)
- default · traits.rs:101 Program Rust
- Dec2flt_modelNumImpDec2fltLemireU64 · dec2flt/mod.rs:217 Program Rust
- Dec2flt_modelNumImpTraitsFloatExtU64 · traits.rs:339 Program Rust
- Dec2flt_modelNumImpTraitsFloatU64 · traits.rs:309 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- biased_fp_to_float · dec2flt/mod.rs:282 Program Rust
- BiasedFp · dec2flt/common.rs:56 Program Rust
- dec2flt · dec2flt/mod.rs:508 Program Rust
- dec2flt_with_trace · dec2flt/mod.rs:355 Program Rust
- try_fast_path · dec2flt/decimal.rs:59 Program Rust
- compute_float · dec2flt/lemire.rs:26 Program Rust
- parse_inf_nan · dec2flt/parse.rs:244 Program Rust
- parse_number · dec2flt/parse.rs:234 Program Rust
- parse_long_mantissa · dec2flt/slow.rs:27 Program Rust
- parse_long_mantissa_loop0 · dec2flt/slow.rs:51 Program Rust
- body · dec2flt/slow.rs:51 Program Rust
- parse_long_mantissa_loop1 · dec2flt/slow.rs:69 Program Rust
- body · dec2flt/slow.rs:69 Program Rust
- parse_long_mantissa_loop2 · dec2flt/slow.rs:94 Program Rust
- body · dec2flt/slow.rs:94 Program Rust
- Float · traits.rs:74 Program Rust
- MAX_EXPONENT_DISGUISED_FAST_PATH · dec2flt/mod.rs:220 Program Rust
- MAX_EXPONENT_FAST_PATH · dec2flt/mod.rs:219 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- pow10_fast_path · dec2flt/mod.rs:222 Program Rust
- from_u64_bits · traits.rs:341 Program Rust
- integer_decode · traits.rs:348 Program Rust
- BITS · traits.rs:319 Program Rust
- EXP_MASK · traits.rs:321 Program Rust
- INFINITY · traits.rs:312 Program Rust
- LARGEST_POWER_OF_TEN · traits.rs:327 Program Rust
- MAX_EXPONENT_ROUND_TO_EVEN · traits.rs:325 Program Rust
- MIN_EXPONENT_ROUND_TO_EVEN · traits.rs:324 Program Rust
- NAN · traits.rs:314 Program Rust
- NEG_INFINITY · traits.rs:313 Program Rust
- NEG_NAN · traits.rs:317 Program Rust
- SIG_MASK · traits.rs:322 Program Rust
- SIG_TOTAL_BITS · traits.rs:320 Program Rust
- SMALLEST_POWER_OF_TEN · traits.rs:328 Program Rust
- classify · traits.rs:334 Program Rust
- to_bits · traits.rs:330 Program Rust
- read_u64 · dec2flt/common.rs:22 Program Rust
- Dec2flt_modelNumImpTraitsInt · traits.rs:51 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- default · dec2flt/mod.rs:128 Program Rust
- default · dec2flt/mod.rs:121 Program Rust
- zero_pow2 · dec2flt/common.rs:66 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- can_use_fast_path · dec2flt/decimal.rs:42 Program Rust
- INT_POW10 · dec2flt/decimal.rs:8 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:68 Program Rust
- left_shift · dec2flt/decimal_seq.rs:130 Program Rust
- left_shift_loop0 · dec2flt/decimal_seq.rs:139 Program Rust
- body · dec2flt/decimal_seq.rs:139 Program Rust
- left_shift_loop1 · dec2flt/decimal_seq.rs:153 Program Rust
- body · dec2flt/decimal_seq.rs:153 Program Rust
- right_shift · dec2flt/decimal_seq.rs:176 Program Rust
- right_shift_loop0 · dec2flt/decimal_seq.rs:181 Program Rust
- body · dec2flt/decimal_seq.rs:181 Program Rust
- right_shift_loop0_loop0 · dec2flt/decimal_seq.rs:191 Program Rust
- body · dec2flt/decimal_seq.rs:191 Program Rust
- right_shift_loop1 · dec2flt/decimal_seq.rs:210 Program Rust
- body · dec2flt/decimal_seq.rs:210 Program Rust
- right_shift_loop2 · dec2flt/decimal_seq.rs:217 Program Rust
- body · dec2flt/decimal_seq.rs:217 Program Rust
- round · dec2flt/decimal_seq.rs:97 Program Rust
- round_loop · dec2flt/decimal_seq.rs:107 Program Rust
- body · dec2flt/decimal_seq.rs:107 Program Rust
- parse_decimal_seq · dec2flt/decimal_seq.rs:288 Program Rust
- parse_decimal_seq_loop0 · dec2flt/decimal_seq.rs:296 Program Rust
- body · dec2flt/decimal_seq.rs:296 Program Rust
- parse_decimal_seq_loop1 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- parse_decimal_seq_loop2 · dec2flt/decimal_seq.rs:309 Program Rust
- body · dec2flt/decimal_seq.rs:309 Program Rust
- parse_decimal_seq_loop3 · dec2flt/decimal_seq.rs:313 Program Rust
- body · dec2flt/decimal_seq.rs:313 Program Rust
- parse_decimal_seq_loop4 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- parse_decimal_seq_loop5 · dec2flt/decimal_seq.rs:313 Program Rust
- body · dec2flt/decimal_seq.rs:313 Program Rust
- parse_decimal_seq_loop6 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- parse_decimal_seq_loop7 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- set_precision · dec2flt/fpu.rs:99 Program Rust
- compute_product_approx · dec2flt/lemire.rs:134 Program Rust
- power · dec2flt/lemire.rs:121 Program Rust
- parse_partial_number · dec2flt/parse.rs:164 Program Rust
- MAX_SHIFT · dec2flt/slow.rs:28 Program Rust
- call · dec2flt/slow.rs:33 Program Rust
- CastInto · traits.rs:18 Program Rust
- default · traits.rs:116 Program Rust
- default · traits.rs:104 Program Rust
- default · traits.rs:119 Program Rust
- default · traits.rs:110 Program Rust
- default · traits.rs:113 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
- offset_from · dec2flt/common.rs:34 Program Rust
- write_u64 · dec2flt/common.rs:29 Program Rust
- Dec2flt_modelNumImpTraitsCastIntoI16 · traits.rs:45 Program Rust
- ONE · traits.rs:53 Program Rust
- ZERO · traits.rs:52 Program Rust
- is_8digits · dec2flt/common.rs:44 Program Rust
- default · dec2flt/decimal_seq.rs:34 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:64 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:67 Program Rust
- trim · dec2flt/decimal_seq.rs:83 Program Rust
- trim_loop · dec2flt/decimal_seq.rs:92 Program Rust
- body · dec2flt/decimal_seq.rs:92 Program Rust
- count_trailing_zeros · dec2flt/decimal_seq.rs:236 Program Rust
- count_trailing_zeros_loop · dec2flt/decimal_seq.rs:240 Program Rust
- body · dec2flt/decimal_seq.rs:240 Program Rust
- final_decimal_point · dec2flt/decimal_seq.rs:269 Program Rust
- number_of_digits_decimal_left_shift · dec2flt/decimal_seq.rs:375 Program Rust
- number_of_digits_decimal_left_shift_loop · dec2flt/decimal_seq.rs:441 Program Rust
- body · dec2flt/decimal_seq.rs:441 Program Rust
- parse_digits_into_seq · dec2flt/decimal_seq.rs:257 Program Rust
- parse_digits_into_seq_loop · dec2flt/decimal_seq.rs:259 Program Rust
- body · dec2flt/decimal_seq.rs:259 Program Rust
- full_multiplication · dec2flt/lemire.rs:126 Program Rust
- adjust_many_digit_count · dec2flt/parse.rs:86 Program Rust
- adjust_many_digit_count_loop · dec2flt/parse.rs:89 Program Rust
- body · dec2flt/parse.rs:89 Program Rust
- parse_many_digits · dec2flt/parse.rs:104 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
- try_parse_digits · dec2flt/parse.rs:30 Program Rust
- try_parse_digits_loop0 · dec2flt/parse.rs:33 Program Rust
- body · dec2flt/parse.rs:33 Program Rust
- try_parse_digits_loop1 · dec2flt/parse.rs:50 Program Rust
- body · dec2flt/parse.rs:50 Program Rust
- NUM_POWERS · dec2flt/slow.rs:29 Program Rust
- POWERS · dec2flt/slow.rs:30 Program Rust
- closure · dec2flt/slow.rs:33 Program Rust
- LARGEST_POWER_OF_FIVE · dec2flt/table.rs:10 Program Rust
- POWER_OF_FIVE_128 · dec2flt/table.rs:19 Program Rust
- SMALLEST_POWER_OF_FIVE · dec2flt/table.rs:9 Program Rust
- cast · traits.rs:46 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:74 Program Rust
- TABLE · dec2flt/decimal_seq.rs:377 Program Rust
- TABLE_POW5 · dec2flt/decimal_seq.rs:386 Program Rust
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- parse_8digits · dec2flt/parse.rs:18 Program Rust
- try_parse_19digits · dec2flt/parse.rs:61 Program Rust
- try_parse_19digits_loop · dec2flt/parse.rs:64 Program Rust
- body · dec2flt/parse.rs:64 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 Program Rust
Standard-library dependencies (39)
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- as_bytes · core/src/str/mod.rs:498 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
- 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_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
- split_first · core/src/slice/mod.rs:198 Rust library
- CoreOpsArithDivF64F64 · core/src/ops/arith.rs:511 Rust library
- CoreOpsArithMulF64F64 · core/src/ops/arith.rs:344 Rust library
- CoreOpsArithNegF64 · core/src/ops/arith.rs:713 Rust library
- CoreMarkerCopy · core/src/marker.rs:57 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
- CoreCloneClone · core/src/clone.rs:696 Rust library
- CoreOpsBitBitAndU64U64 · core/src/ops/bit.rs:174 Rust library
- CoreOpsBitBitOrU64U64 · core/src/ops/bit.rs:278 Rust library
- CoreOpsBitShlU32U64 · core/src/ops/bit.rs:483 Rust library
- CoreOpsBitShrU32U64 · core/src/ops/bit.rs:606 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
- Binary64Model
- Binary64ModelDefault
- ClassificationDeterminism
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
All 104 entries
- Binary64Model
- Binary64ModelDefault
- ClassificationDeterminism
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- DispatchContracts
- F64
- F64 Insts CoreCloneClone
- F64 Insts CoreMarkerCopy
- F64 Insts CoreOpsArithDivF64F64
- F64 Insts CoreOpsArithMulF64F64
- F64 Insts CoreOpsArithNegF64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT DISGUISED FAST PATH
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT FAST PATH
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 pow10 fast path
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 from u64 bits
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 integer decode
- F64 Insts Dec2flt modelNumImpTraitsFloatU64
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 BITS
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 EXP MASK
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 INFINITY
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 LARGEST POWER OF TEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 MAX EXPONENT ROUND TO EVEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 MIN EXPONENT ROUND TO EVEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NAN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NEG INFINITY
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NEG NAN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG MASK
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SMALLEST POWER OF TEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 classify
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 to bits
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- FrameCorrectness
- RoundingCellConvexity
- SignStrippedClassification
- AbstractComponents
- DispatchFrame
- DispatchOperations
- EmbedComponents
- Preamble
- SourceValidByteSlice
- U64 Insts CoreOpsBitBitAndU64U64
- U64 Insts CoreOpsBitBitOrU64U64
- U64 Insts CoreOpsBitShlU32U64
- U64 Insts CoreOpsBitShrU32U64
- U64 Insts Dec2flt modelNumImpTraitsCastIntoI16
- U64 Insts Dec2flt modelNumImpTraitsCastIntoI16 cast
- U64 Insts Dec2flt modelNumImpTraitsInt
- U64 Insts Dec2flt modelNumImpTraitsInt ONE
- U64 Insts Dec2flt modelNumImpTraitsInt ZERO
- core num FpCategory
- core ops arith Div
- core ops arith Mul
- core ops arith Neg
- core ops bit BitOr
- core ops bit Shl
- core ops bit Shr
- num float parse FloatErrorKind
- num float parse ParseFloatError
- num imp dec2flt Dec2FltAssemblyTrace
- num imp dec2flt Dec2FltTrace
- num imp dec2flt Lemire
- num imp dec2flt Lemire MAX MANTISSA FAST PATH default
- num imp dec2flt common BiasedFp
- num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq
- num imp dec2flt decimal Decimal
- num imp dec2flt pfe empty
- num imp dec2flt pfe invalid
- num imp traits CastInto
- num imp traits Float
- num imp traits FloatExt
- num imp traits Float EXP BIAS default
- num imp traits Float EXP BITS default
- num imp traits Float EXP MIN default
- num imp traits Float EXP SAT default
- num imp traits Float SIG BITS default
- num imp traits Int
Technical checking records
Local closure summary
{
"node": "P616_T1_FrameCorrectness",
"closure_version": "patch_c_v1",
"active_decl_hash": "81c41ad76837b03cfeca21241d48d9ae2f4f9396614477893e63775b433280fe",
"active_statement_hash": "30a7e9e6e93641aad3cdf56323e99428a145f940da881f4b9ab4dc20e2ea6af3",
"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": {
"ClassificationDeterminism": "1887cc51648312b8",
"DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
"DispatchContracts": "ae67c1a1a952d0f1",
"P616_T1_RoundingCellConvexity": "5c69841b2c941bc4",
"P616_T1_SignStrippedClassification": "4dbd872ba02a631e",
"P9_T1_DispatchFrame": "1b73cde8bfea548e",
"num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "986725aca5ee5702",
"DecimalGoalVocabularyDefault": "3016c00221d29252",
"DecimalLexeme": "8127b3eaeae00dd2",
"DispatchContracts": "008abfbd503545bf",
"F64": "ec4e25fbaf4e11d4",
"F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
"F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
"ModelSliceFirst": "a31394b3c1080f71",
"ModelStrAsBytes": "024fe35b4dbfa9a3",
"P9_T1_AbstractComponents": "0a7e8b7bdbce0180",
"P9_T1_DispatchFrame": "20ad2431db4aaf28",
"P9_T1_DispatchOperations": "c43614ff2149ecf2",
"P9_T1_EmbedComponents": "c6037220641c6c08",
"Preamble": "7a79218b23bce03e",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_float_parse_ParseFloatError": "c43614ff2149ecf2",
"num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
"num_imp_dec2flt_Dec2FltTrace": "f5d0731ff1ab56ce",
"num_imp_dec2flt_Lemire": "1923f90c53d323e6",
"num_imp_dec2flt_common_BiasedFp": "b22d5c76996d8b0d",
"num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
"num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e",
"num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
"num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
"num_imp_traits_Float": "02acccb9db3e30f2",
"num_imp_traits_FloatExt": "f996e5400649797d"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:ea02de75b595e4eec6820996dee652c8fc02066d41dc4d375c63328ff34d4324",
"current_fingerprint": "sound-v2:ea02de75b595e4eec6820996dee652c8fc02066d41dc4d375c63328ff34d4324",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}