Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Product suffix executes
num.imp.dec2flt.lemire.power on q_{32}, obtaining p_0.
Compute I_{15}=p_0+u, lift the unsigned-to-I32 cast I_{16} of \ell,
compute I_{17}=I_{15}-I_{16}, bind the normal I32 literal -1022
as I_{18}, and compute I_{19}=I_{17}-I_{18} and
p=I_{19}+1. Every addition, subtraction, negation and shift described
here is the checked scalar operation of the extracted model.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.P822_T1_NormalRoundingExecution
import Tablet.IntegerPowerTableCertificate
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P822_T1_ProductTailExecution]
theorem P822_T1_ProductTailExecution (q : Std.I64) (l : Std.U32)
(lo hi : Std.U64) (hqlo : -342 ≤ q.val) (hqhi : q.val ≤ 308)
(hl : l.val ≤ 63) :
WP.spec (do
let i8 ← hi >>> 63#i32
let upperbit ← lift (UScalar.hcast .I32 i8)
let i9 ← upperbit + 64#i32
let i10 ← lift (UScalar.hcast .I32 52#u32)
let i11 ← i9 - i10
let i12 ← i11 - 3#i32
let mantissa ← hi >>> i12
let i13 ← lift (IScalar.cast .I32 q)
let i14 ← num.imp.dec2flt.lemire.power i13
let i15 ← i14 + upperbit
let i16 ← lift (UScalar.hcast .I32 l)
let i17 ← i15 - i16
let i18 ← ok (-1022)#i32
let i19 ← i17 - i18
let power2 ← i19 + 1#i32
if power2 <= 0#i32 then
let i20 ← -. power2
let i21 ← i20 + 1#i32
if i21 >= 64#i32 then
ok { m := 0#u64, p_biased := 0#i32 }
else
let i22 ← i20 + 1#i32
let mantissa1 ← mantissa >>> i22
let i23 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i23
let mantissa3 ← mantissa2 >>> 1#i32
let i24 ← 1#u64 <<< 52#u32
let power21 ← lift (IScalar.cast_fromBool .I32 (mantissa3 >= i24))
ok { m := mantissa3, p_biased := power21 }
else
let mantissa1 ←
if lo <= 1#u64 then
do
let i20 ← ok (-4)#i32
let i21 ← lift (IScalar.cast .I64 i20)
if q >= i21 then
let i22 ← ok 23#i32
let i23 ← lift (IScalar.cast .I64 i22)
if q <= i23 then
let i24 ← lift (mantissa &&& 3#u64)
if i24 = 1#u64 then
let i25 ← lift (UScalar.hcast .I32 52#u32)
let i26 ← i9 - i25
let i27 ← i26 - 3#i32
let i28 ← mantissa <<< i27
if i28 = hi then
let i29 ← lift (~~~ 1#u64)
ok (mantissa &&& i29)
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
do
let i20 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i20
let mantissa3 ← mantissa2 >>> 1#i32
let i21 ← 2#u64 <<< 52#u32
let (mantissa4, power21) ←
if mantissa3 >= i21 then do
let mantissa5 ← 1#u64 <<< 52#u32
let power22 ← power2 + 1#i32
ok (mantissa5, power22)
else ok (mantissa3, power2)
let i22 ← 1#u64 <<< 52#u32
let i23 ← lift (~~~ i22)
let mantissa5 ← lift (mantissa4 &&& i23)
if power21 >= 2047#i32 then
ok { m := 0#u64, p_biased := 2047#i32 }
else ok { m := mantissa5, p_biased := power21 }
: Result num.imp.dec2flt.common.BiasedFp) (fun _ => True) := by
Proof
Natural-language proof
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Proof
Lean proof
let coreRound (power2 : Std.I32) (mantissa1 : Std.U64) :
Result num.imp.dec2flt.common.BiasedFp := do
let i20 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i20
let mantissa3 ← mantissa2 >>> 1#i32
let i21 ← 2#u64 <<< 52#u32
let (mantissa4, power21) ←
if mantissa3 >= i21 then do
let mantissa5 ← 1#u64 <<< 52#u32
let power22 ← power2 + 1#i32
ok (mantissa5, power22)
else ok (mantissa3, power2)
let i22 ← 1#u64 <<< 52#u32
let i23 ← lift (~~~ i22)
let mantissa5 ← lift (mantissa4 &&& i23)
if power21 >= 2047#i32 then
ok { m := 0#u64, p_biased := 2047#i32 }
else ok { m := mantissa5, p_biased := power21 }
let coreTail (lo hi : Std.U64) : Result num.imp.dec2flt.common.BiasedFp := do
let i8 ← hi >>> 63#i32
let upperbit ← lift (UScalar.hcast .I32 i8)
let i9 ← upperbit + 64#i32
let i10 ← lift (UScalar.hcast .I32 52#u32)
let i11 ← i9 - i10
let i12 ← i11 - 3#i32
let mantissa ← hi >>> i12
let i13 ← lift (IScalar.cast .I32 q)
let i14 ← num.imp.dec2flt.lemire.power i13
let i15 ← i14 + upperbit
let i16 ← lift (UScalar.hcast .I32 l)
let i17 ← i15 - i16
let i18 ← ok (-1022)#i32
let i19 ← i17 - i18
let power2 ← i19 + 1#i32
if power2 <= 0#i32 then
let i20 ← -. power2
let i21 ← i20 + 1#i32
if i21 >= 64#i32 then
ok { m := 0#u64, p_biased := 0#i32 }
else
let i22 ← i20 + 1#i32
let mantissa1 ← mantissa >>> i22
let i23 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i23
let mantissa3 ← mantissa2 >>> 1#i32
let i24 ← 1#u64 <<< 52#u32
let power21 ← lift (IScalar.cast_fromBool .I32 (mantissa3 >= i24))
ok { m := mantissa3, p_biased := power21 }
else
let mantissa1 ←
if lo <= 1#u64 then
do
let i20 ← ok (-4)#i32
let i21 ← lift (IScalar.cast .I64 i20)
if q >= i21 then
let i22 ← ok 23#i32
let i23 ← lift (IScalar.cast .I64 i22)
if q <= i23 then
let i24 ← lift (mantissa &&& 3#u64)
if i24 = 1#u64 then
let i25 ← lift (UScalar.hcast .I32 52#u32)
let i26 ← i9 - i25
let i27 ← i26 - 3#i32
let i28 ← mantissa <<< i27
if i28 = hi then
let i29 ← lift (~~~ 1#u64)
ok (mantissa &&& i29)
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
coreRound power2 mantissa1
obtain ⟨q32, p, delta, index, a, b, hq32, hp, hpval,
hdelta, hindex, htable, _⟩ := IntegerPowerTableCertificate q hqlo hqhi
have hpRange : -1074 ≤ p.val ∧ p.val ≤ 1086 := by
rw [hpval]
constructor <;> omega
change WP.spec (coreTail lo hi) (fun _ => True)
unfold coreTail
step by scalar_tac
step by scalar_tac
have hi8le : i8.val ≤ 1 := by
have hhi : hi.val < 2 ^ 64 := hi.bv.isLt
have hdiv : hi.val / 2 ^ 63 < 2 := by
apply (Nat.div_lt_iff_lt_mul (by decide : 0 < 2 ^ 63)).2
have hbound : hi.val < 2 * 2 ^ 63 := by
have : 2 ^ 64 = 2 ^ 63 * 2 := by norm_num [pow_succ]
omega
exact hbound
rw [i8_post1, Nat.shiftRight_eq_div_pow]
omega
have hupval : upperbit.val = (i8.val : Int) := by
have hs := UScalar.hcast_inBounds_spec .I32 i8 (by scalar_tac)
simp only [lift, WP.spec_ok] at hs
rw [upperbit_post]
exact hs
have hup : 0 ≤ upperbit.val ∧ upperbit.val ≤ 1 := by
rw [hupval]
constructor
· exact_mod_cast (Nat.zero_le i8.val)
· exact_mod_cast hi8le
step by scalar_tac
step by scalar_tac
have hi9Range : 64 ≤ i9.val ∧ i9.val ≤ 65 := by
rw [i9_post]
omega
have hi10Val : i10.val = 52 := by
rw [i10_post]
rfl
step by scalar_tac
step by scalar_tac
step by scalar_tac
step by scalar_tac
have hq32' : IScalar.cast .I32 q = q32 := by
simp only [lift] at hq32
exact Result.ok.inj hq32
have hi13 : i13 = q32 := i13_post.trans hq32'
rw [hi13, hp]
simp only [bind_tc_ok]
step by scalar_tac
step by scalar_tac
have hi15Range : -1074 ≤ i15.val ∧ i15.val ≤ 1087 := by
rw [i15_post]
omega
have hi16val : i16.val = l.val := by
have hs := UScalar.hcast_inBounds_spec .I32 l (by
rw [IScalar.max_I32_eq]
omega)
simp only [lift, WP.spec_ok] at hs
rw [i16_post]
exact hs
have hi16Range : 0 ≤ i16.val ∧ i16.val ≤ 63 := by
rw [hi16val]
omega
have hi12Range : 9 ≤ i12.val ∧ i12.val ≤ 10 := by
rw [i12_post, i11_post, hi10Val, i9_post]
omega
have hmantissaBound : mantissa.val < 2 ^ 55 := by
rw [mantissa_post1, Nat.shiftRight_eq_div_pow]
have hhi : hi.val < 2 ^ 64 := hi.bv.isLt
have hpow : 2 ^ 64 ≤ 2 ^ 55 * 2 ^ i12.val.toNat := by
have hexp : 64 ≤ 55 + i12.val.toNat := by
have hnat : 9 ≤ i12.val.toNat := by omega
omega
rw [← Nat.pow_add]
exact Nat.pow_le_pow_right (by decide : 1 ≤ 2) hexp
have : hi.val / 2 ^ i12.val.toNat < 2 ^ 55 := by
apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < 2 ^ i12.val.toNat)).2
omega
exact this
step by scalar_tac
step by scalar_tac
step by scalar_tac
have hpower2Range : -114 ≤ power2.val ∧ power2.val ≤ 2110 := by
rw [power2_post, i19_post, i17_post, i15_post]
omega
have hroundSpec : ∀ (p : Std.I32) (m1 : Std.U64),
m1.val < 2 ^ 55 → -114 ≤ p.val → p.val ≤ 2110 →
0 < p.val → WP.spec (coreRound p m1) (fun _ => True) := by
intro p m1 hm _ hpHi hpPos
exact P822_T1_NormalRoundingExecution p m1 hm hpPos hpHi
by_cases hsub : power2 <= 0#i32
· simp only [hsub, if_pos]
step by scalar_tac
step by scalar_tac
by_cases hlarge : i21 >= 64#i32
· simp only [hlarge, if_pos]
simp [WP.spec_ok]
· simp only [hlarge, if_neg]
simp only [if_false]
step by scalar_tac
step by scalar_tac
step by scalar_tac
simp only [lift, IScalar.cast_fromBool, bind_tc_ok]
have hmantissa1Bound : mantissa1.val ≤ mantissa.val := by
rw [mantissa1_post1, Nat.shiftRight_eq_div_pow]
exact Nat.div_le_self _ _
have hmantissa1Lt : mantissa1.val < 2 ^ 55 :=
lt_of_le_of_lt hmantissa1Bound hmantissaBound
have hi23le : i23.val ≤ 1 := by
rw [i23_post1]
simp only [UScalar.val_and]
exact Nat.and_le_right
have haddMantissa : mantissa1.val + i23.val ≤ UScalar.max .U64 := by
norm_num [UScalar.max, U64.max_eq, UScalarTy.numBits]
omega
have hmspec := UScalar.add_spec (x := mantissa1) (y := i23) haddMantissa
obtain ⟨mantissa2', hmadd, hmval⟩ := WP.spec_imp_exists hmspec
rw [hmadd]
simp only [bind_tc_ok]
step by scalar_tac
step by scalar_tac
· simp only [hsub, if_neg]
simp only [if_false]
have hpPos : 0 < power2.val := by
have hnotle : ¬ power2.val ≤ 0 := by
simpa only [IScalar.le_equiv] using hsub
omega
by_cases hlosmall : lo <= 1#u64
· simp only [hlosmall, if_pos]
have hcast4 : lift (IScalar.cast .I64 (-4)#i32) =
ok (-4)#i64 := by rfl
rw [hcast4]
simp only [bind_tc_ok]
by_cases hqge : q ≥ (-4)#i64
· simp only [hqge, if_pos]
have hcast23 : lift (IScalar.cast .I64 23#i32) =
ok 23#i64 := by rfl
rw [hcast23]
simp only [bind_tc_ok]
by_cases hqle : q ≤ 23#i64
· simp only [hqle, if_pos]
have handSpec := UScalar.and_spec mantissa 3#u64
obtain ⟨i24', hand, _⟩ := WP.spec_imp_exists handSpec
rw [hand]
simp only [bind_tc_ok]
by_cases htie : i24' = 1#u64
· simp only [htie, if_pos]
have hcast52 : lift (UScalar.hcast .I32 52#u32) =
ok 52#i32 := by rfl
rw [hcast52]
simp only [bind_tc_ok]
have hsub26lo : IScalar.min .I32 ≤ i9.val - 52 := by
rw [IScalar.min_I32_eq, i9_post]
omega
have hsub26hi : i9.val - 52 ≤ IScalar.max .I32 := by
rw [IScalar.max_I32_eq, i9_post]
omega
have hsub26Spec := IScalar.sub_spec (x := i9)
(y := 52#i32) hsub26lo hsub26hi
obtain ⟨i26', hi26, hi26val⟩ :=
WP.spec_imp_exists hsub26Spec
rw [hi26]
simp only [bind_tc_ok]
have hi26range : 12 ≤ i26'.val ∧ i26'.val ≤ 13 := by
rw [hi26val, i9_post]
have h52 : (52#i32).val = 52 := rfl
rw [h52]
omega
have hsub27lo : IScalar.min .I32 ≤ i26'.val - 3 := by
rw [IScalar.min_I32_eq]
rcases hi26range with ⟨hlo, hhi⟩
omega
have hsub27hi : i26'.val - 3 ≤ IScalar.max .I32 := by
rw [IScalar.max_I32_eq]
rcases hi26range with ⟨hlo, hhi⟩
omega
have hsub27Spec := IScalar.sub_spec (x := i26')
(y := 3#i32) hsub27lo hsub27hi
obtain ⟨i27', hi27, hi27val⟩ :=
WP.spec_imp_exists hsub27Spec
rw [hi27]
simp only [bind_tc_ok]
have hi27range : 9 ≤ i27'.val ∧ i27'.val ≤ 10 := by
rw [hi27val, hi26val, i9_post]
have h52 : (52#i32).val = 52 := rfl
have h3 : (3#i32).val = 3 := rfl
rw [h52]
rw [h3]
omega
have hshift28 := UScalar.ShiftLeft_IScalar_spec
mantissa i27' (2 ^ 64) (by omega)
(by change i27'.val < 64; omega)
(by norm_num [U64.size_eq])
obtain ⟨i28', hi28, _⟩ := WP.spec_imp_exists hshift28
rw [hi28]
simp only [bind_tc_ok]
by_cases heq28 : i28' = hi
· simp only [heq28, if_pos]
have hnotSpec := UScalar.not_spec (1#u64)
obtain ⟨i29', hnot, _⟩ :=
WP.spec_imp_exists hnotSpec
rw [hnot]
simp only [bind_tc_ok]
have hm1bound : (mantissa &&& i29').val < 2 ^ 55 := by
rw [UScalar.val_and]
exact lt_of_le_of_lt Nat.and_le_left hmantissaBound
change WP.spec (coreRound power2 (mantissa &&& i29'))
(fun _ => True)
exact hroundSpec power2 _ hm1bound hpower2Range.1
hpower2Range.2 hpPos
· simp only [heq28, if_neg]
change WP.spec (coreRound power2 mantissa)
(fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [htie, if_neg]
change WP.spec (coreRound power2 mantissa)
(fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [hqle, if_neg]
change WP.spec (coreRound power2 mantissa)
(fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [hqge, if_neg]
change WP.spec (coreRound power2 mantissa) (fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [hlosmall, if_neg]
change WP.spec (coreRound power2 mantissa) (fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P822_T1_NormalRoundingExecution
import Tablet.IntegerPowerTableCertificate
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P822_T1_ProductTailExecution]
theorem P822_T1_ProductTailExecution (q : Std.I64) (l : Std.U32)
(lo hi : Std.U64) (hqlo : -342 ≤ q.val) (hqhi : q.val ≤ 308)
(hl : l.val ≤ 63) :
WP.spec (do
let i8 ← hi >>> 63#i32
let upperbit ← lift (UScalar.hcast .I32 i8)
let i9 ← upperbit + 64#i32
let i10 ← lift (UScalar.hcast .I32 52#u32)
let i11 ← i9 - i10
let i12 ← i11 - 3#i32
let mantissa ← hi >>> i12
let i13 ← lift (IScalar.cast .I32 q)
let i14 ← num.imp.dec2flt.lemire.power i13
let i15 ← i14 + upperbit
let i16 ← lift (UScalar.hcast .I32 l)
let i17 ← i15 - i16
let i18 ← ok (-1022)#i32
let i19 ← i17 - i18
let power2 ← i19 + 1#i32
if power2 <= 0#i32 then
let i20 ← -. power2
let i21 ← i20 + 1#i32
if i21 >= 64#i32 then
ok { m := 0#u64, p_biased := 0#i32 }
else
let i22 ← i20 + 1#i32
let mantissa1 ← mantissa >>> i22
let i23 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i23
let mantissa3 ← mantissa2 >>> 1#i32
let i24 ← 1#u64 <<< 52#u32
let power21 ← lift (IScalar.cast_fromBool .I32 (mantissa3 >= i24))
ok { m := mantissa3, p_biased := power21 }
else
let mantissa1 ←
if lo <= 1#u64 then
do
let i20 ← ok (-4)#i32
let i21 ← lift (IScalar.cast .I64 i20)
if q >= i21 then
let i22 ← ok 23#i32
let i23 ← lift (IScalar.cast .I64 i22)
if q <= i23 then
let i24 ← lift (mantissa &&& 3#u64)
if i24 = 1#u64 then
let i25 ← lift (UScalar.hcast .I32 52#u32)
let i26 ← i9 - i25
let i27 ← i26 - 3#i32
let i28 ← mantissa <<< i27
if i28 = hi then
let i29 ← lift (~~~ 1#u64)
ok (mantissa &&& i29)
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
do
let i20 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i20
let mantissa3 ← mantissa2 >>> 1#i32
let i21 ← 2#u64 <<< 52#u32
let (mantissa4, power21) ←
if mantissa3 >= i21 then do
let mantissa5 ← 1#u64 <<< 52#u32
let power22 ← power2 + 1#i32
ok (mantissa5, power22)
else ok (mantissa3, power2)
let i22 ← 1#u64 <<< 52#u32
let i23 ← lift (~~~ i22)
let mantissa5 ← lift (mantissa4 &&& i23)
if power21 >= 2047#i32 then
ok { m := 0#u64, p_biased := 2047#i32 }
else ok { m := mantissa5, p_biased := power21 }
: Result num.imp.dec2flt.common.BiasedFp) (fun _ => True) := by
-- BODY
let coreRound (power2 : Std.I32) (mantissa1 : Std.U64) :
Result num.imp.dec2flt.common.BiasedFp := do
let i20 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i20
let mantissa3 ← mantissa2 >>> 1#i32
let i21 ← 2#u64 <<< 52#u32
let (mantissa4, power21) ←
if mantissa3 >= i21 then do
let mantissa5 ← 1#u64 <<< 52#u32
let power22 ← power2 + 1#i32
ok (mantissa5, power22)
else ok (mantissa3, power2)
let i22 ← 1#u64 <<< 52#u32
let i23 ← lift (~~~ i22)
let mantissa5 ← lift (mantissa4 &&& i23)
if power21 >= 2047#i32 then
ok { m := 0#u64, p_biased := 2047#i32 }
else ok { m := mantissa5, p_biased := power21 }
let coreTail (lo hi : Std.U64) : Result num.imp.dec2flt.common.BiasedFp := do
let i8 ← hi >>> 63#i32
let upperbit ← lift (UScalar.hcast .I32 i8)
let i9 ← upperbit + 64#i32
let i10 ← lift (UScalar.hcast .I32 52#u32)
let i11 ← i9 - i10
let i12 ← i11 - 3#i32
let mantissa ← hi >>> i12
let i13 ← lift (IScalar.cast .I32 q)
let i14 ← num.imp.dec2flt.lemire.power i13
let i15 ← i14 + upperbit
let i16 ← lift (UScalar.hcast .I32 l)
let i17 ← i15 - i16
let i18 ← ok (-1022)#i32
let i19 ← i17 - i18
let power2 ← i19 + 1#i32
if power2 <= 0#i32 then
let i20 ← -. power2
let i21 ← i20 + 1#i32
if i21 >= 64#i32 then
ok { m := 0#u64, p_biased := 0#i32 }
else
let i22 ← i20 + 1#i32
let mantissa1 ← mantissa >>> i22
let i23 ← lift (mantissa1 &&& 1#u64)
let mantissa2 ← mantissa1 + i23
let mantissa3 ← mantissa2 >>> 1#i32
let i24 ← 1#u64 <<< 52#u32
let power21 ← lift (IScalar.cast_fromBool .I32 (mantissa3 >= i24))
ok { m := mantissa3, p_biased := power21 }
else
let mantissa1 ←
if lo <= 1#u64 then
do
let i20 ← ok (-4)#i32
let i21 ← lift (IScalar.cast .I64 i20)
if q >= i21 then
let i22 ← ok 23#i32
let i23 ← lift (IScalar.cast .I64 i22)
if q <= i23 then
let i24 ← lift (mantissa &&& 3#u64)
if i24 = 1#u64 then
let i25 ← lift (UScalar.hcast .I32 52#u32)
let i26 ← i9 - i25
let i27 ← i26 - 3#i32
let i28 ← mantissa <<< i27
if i28 = hi then
let i29 ← lift (~~~ 1#u64)
ok (mantissa &&& i29)
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
else ok mantissa
coreRound power2 mantissa1
obtain ⟨q32, p, delta, index, a, b, hq32, hp, hpval,
hdelta, hindex, htable, _⟩ := IntegerPowerTableCertificate q hqlo hqhi
have hpRange : -1074 ≤ p.val ∧ p.val ≤ 1086 := by
rw [hpval]
constructor <;> omega
change WP.spec (coreTail lo hi) (fun _ => True)
unfold coreTail
step by scalar_tac
step by scalar_tac
have hi8le : i8.val ≤ 1 := by
have hhi : hi.val < 2 ^ 64 := hi.bv.isLt
have hdiv : hi.val / 2 ^ 63 < 2 := by
apply (Nat.div_lt_iff_lt_mul (by decide : 0 < 2 ^ 63)).2
have hbound : hi.val < 2 * 2 ^ 63 := by
have : 2 ^ 64 = 2 ^ 63 * 2 := by norm_num [pow_succ]
omega
exact hbound
rw [i8_post1, Nat.shiftRight_eq_div_pow]
omega
have hupval : upperbit.val = (i8.val : Int) := by
have hs := UScalar.hcast_inBounds_spec .I32 i8 (by scalar_tac)
simp only [lift, WP.spec_ok] at hs
rw [upperbit_post]
exact hs
have hup : 0 ≤ upperbit.val ∧ upperbit.val ≤ 1 := by
rw [hupval]
constructor
· exact_mod_cast (Nat.zero_le i8.val)
· exact_mod_cast hi8le
step by scalar_tac
step by scalar_tac
have hi9Range : 64 ≤ i9.val ∧ i9.val ≤ 65 := by
rw [i9_post]
omega
have hi10Val : i10.val = 52 := by
rw [i10_post]
rfl
step by scalar_tac
step by scalar_tac
step by scalar_tac
step by scalar_tac
have hq32' : IScalar.cast .I32 q = q32 := by
simp only [lift] at hq32
exact Result.ok.inj hq32
have hi13 : i13 = q32 := i13_post.trans hq32'
rw [hi13, hp]
simp only [bind_tc_ok]
step by scalar_tac
step by scalar_tac
have hi15Range : -1074 ≤ i15.val ∧ i15.val ≤ 1087 := by
rw [i15_post]
omega
have hi16val : i16.val = l.val := by
have hs := UScalar.hcast_inBounds_spec .I32 l (by
rw [IScalar.max_I32_eq]
omega)
simp only [lift, WP.spec_ok] at hs
rw [i16_post]
exact hs
have hi16Range : 0 ≤ i16.val ∧ i16.val ≤ 63 := by
rw [hi16val]
omega
have hi12Range : 9 ≤ i12.val ∧ i12.val ≤ 10 := by
rw [i12_post, i11_post, hi10Val, i9_post]
omega
have hmantissaBound : mantissa.val < 2 ^ 55 := by
rw [mantissa_post1, Nat.shiftRight_eq_div_pow]
have hhi : hi.val < 2 ^ 64 := hi.bv.isLt
have hpow : 2 ^ 64 ≤ 2 ^ 55 * 2 ^ i12.val.toNat := by
have hexp : 64 ≤ 55 + i12.val.toNat := by
have hnat : 9 ≤ i12.val.toNat := by omega
omega
rw [← Nat.pow_add]
exact Nat.pow_le_pow_right (by decide : 1 ≤ 2) hexp
have : hi.val / 2 ^ i12.val.toNat < 2 ^ 55 := by
apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < 2 ^ i12.val.toNat)).2
omega
exact this
step by scalar_tac
step by scalar_tac
step by scalar_tac
have hpower2Range : -114 ≤ power2.val ∧ power2.val ≤ 2110 := by
rw [power2_post, i19_post, i17_post, i15_post]
omega
have hroundSpec : ∀ (p : Std.I32) (m1 : Std.U64),
m1.val < 2 ^ 55 → -114 ≤ p.val → p.val ≤ 2110 →
0 < p.val → WP.spec (coreRound p m1) (fun _ => True) := by
intro p m1 hm _ hpHi hpPos
exact P822_T1_NormalRoundingExecution p m1 hm hpPos hpHi
by_cases hsub : power2 <= 0#i32
· simp only [hsub, if_pos]
step by scalar_tac
step by scalar_tac
by_cases hlarge : i21 >= 64#i32
· simp only [hlarge, if_pos]
simp [WP.spec_ok]
· simp only [hlarge, if_neg]
simp only [if_false]
step by scalar_tac
step by scalar_tac
step by scalar_tac
simp only [lift, IScalar.cast_fromBool, bind_tc_ok]
have hmantissa1Bound : mantissa1.val ≤ mantissa.val := by
rw [mantissa1_post1, Nat.shiftRight_eq_div_pow]
exact Nat.div_le_self _ _
have hmantissa1Lt : mantissa1.val < 2 ^ 55 :=
lt_of_le_of_lt hmantissa1Bound hmantissaBound
have hi23le : i23.val ≤ 1 := by
rw [i23_post1]
simp only [UScalar.val_and]
exact Nat.and_le_right
have haddMantissa : mantissa1.val + i23.val ≤ UScalar.max .U64 := by
norm_num [UScalar.max, U64.max_eq, UScalarTy.numBits]
omega
have hmspec := UScalar.add_spec (x := mantissa1) (y := i23) haddMantissa
obtain ⟨mantissa2', hmadd, hmval⟩ := WP.spec_imp_exists hmspec
rw [hmadd]
simp only [bind_tc_ok]
step by scalar_tac
step by scalar_tac
· simp only [hsub, if_neg]
simp only [if_false]
have hpPos : 0 < power2.val := by
have hnotle : ¬ power2.val ≤ 0 := by
simpa only [IScalar.le_equiv] using hsub
omega
by_cases hlosmall : lo <= 1#u64
· simp only [hlosmall, if_pos]
have hcast4 : lift (IScalar.cast .I64 (-4)#i32) =
ok (-4)#i64 := by rfl
rw [hcast4]
simp only [bind_tc_ok]
by_cases hqge : q ≥ (-4)#i64
· simp only [hqge, if_pos]
have hcast23 : lift (IScalar.cast .I64 23#i32) =
ok 23#i64 := by rfl
rw [hcast23]
simp only [bind_tc_ok]
by_cases hqle : q ≤ 23#i64
· simp only [hqle, if_pos]
have handSpec := UScalar.and_spec mantissa 3#u64
obtain ⟨i24', hand, _⟩ := WP.spec_imp_exists handSpec
rw [hand]
simp only [bind_tc_ok]
by_cases htie : i24' = 1#u64
· simp only [htie, if_pos]
have hcast52 : lift (UScalar.hcast .I32 52#u32) =
ok 52#i32 := by rfl
rw [hcast52]
simp only [bind_tc_ok]
have hsub26lo : IScalar.min .I32 ≤ i9.val - 52 := by
rw [IScalar.min_I32_eq, i9_post]
omega
have hsub26hi : i9.val - 52 ≤ IScalar.max .I32 := by
rw [IScalar.max_I32_eq, i9_post]
omega
have hsub26Spec := IScalar.sub_spec (x := i9)
(y := 52#i32) hsub26lo hsub26hi
obtain ⟨i26', hi26, hi26val⟩ :=
WP.spec_imp_exists hsub26Spec
rw [hi26]
simp only [bind_tc_ok]
have hi26range : 12 ≤ i26'.val ∧ i26'.val ≤ 13 := by
rw [hi26val, i9_post]
have h52 : (52#i32).val = 52 := rfl
rw [h52]
omega
have hsub27lo : IScalar.min .I32 ≤ i26'.val - 3 := by
rw [IScalar.min_I32_eq]
rcases hi26range with ⟨hlo, hhi⟩
omega
have hsub27hi : i26'.val - 3 ≤ IScalar.max .I32 := by
rw [IScalar.max_I32_eq]
rcases hi26range with ⟨hlo, hhi⟩
omega
have hsub27Spec := IScalar.sub_spec (x := i26')
(y := 3#i32) hsub27lo hsub27hi
obtain ⟨i27', hi27, hi27val⟩ :=
WP.spec_imp_exists hsub27Spec
rw [hi27]
simp only [bind_tc_ok]
have hi27range : 9 ≤ i27'.val ∧ i27'.val ≤ 10 := by
rw [hi27val, hi26val, i9_post]
have h52 : (52#i32).val = 52 := rfl
have h3 : (3#i32).val = 3 := rfl
rw [h52]
rw [h3]
omega
have hshift28 := UScalar.ShiftLeft_IScalar_spec
mantissa i27' (2 ^ 64) (by omega)
(by change i27'.val < 64; omega)
(by norm_num [U64.size_eq])
obtain ⟨i28', hi28, _⟩ := WP.spec_imp_exists hshift28
rw [hi28]
simp only [bind_tc_ok]
by_cases heq28 : i28' = hi
· simp only [heq28, if_pos]
have hnotSpec := UScalar.not_spec (1#u64)
obtain ⟨i29', hnot, _⟩ :=
WP.spec_imp_exists hnotSpec
rw [hnot]
simp only [bind_tc_ok]
have hm1bound : (mantissa &&& i29').val < 2 ^ 55 := by
rw [UScalar.val_and]
exact lt_of_le_of_lt Nat.and_le_left hmantissaBound
change WP.spec (coreRound power2 (mantissa &&& i29'))
(fun _ => True)
exact hroundSpec power2 _ hm1bound hpower2Range.1
hpower2Range.2 hpPos
· simp only [heq28, if_neg]
change WP.spec (coreRound power2 mantissa)
(fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [htie, if_neg]
change WP.spec (coreRound power2 mantissa)
(fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [hqle, if_neg]
change WP.spec (coreRound power2 mantissa)
(fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [hqge, if_neg]
change WP.spec (coreRound power2 mantissa) (fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
· simp only [hlosmall, if_neg]
change WP.spec (coreRound power2 mantissa) (fun _ => True)
exact hroundSpec power2 _ hmantissaBound hpower2Range.1
hpower2Range.2 hpPos
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Inspect related source (46)
- power · dec2flt/lemire.rs:121 Program Rust
- POWER_OF_FIVE_128 · dec2flt/table.rs:19 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
More program dependencies (13)
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:56 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
Standard-library dependencies (30)
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
Technical checking records
Local closure summary
{
"node": "P822_T1_ProductTailExecution",
"closure_version": "patch_c_v1",
"active_decl_hash": "f0853cd957de5af99b13ab3ffd2c2af6f97c891638b47ff0cf8664c7efbded9c",
"active_statement_hash": "7764c2ec7ab58abc0fb4ce81e3c18c155a14d79bd37500705ae54b91a5024c21",
"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-192",
"boundary_theorems": {},
"strict_theorem_deps": {
"IntegerPowerTableCertificate": "c4b148e6d8bda215",
"P822_T1_NormalRoundingExecution": "fdec535eda64e0d0"
},
"strict_definition_deps": {
"num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
"num_imp_dec2flt_lemire_power": "56b7c3bd69ca3c6a",
"num_imp_dec2flt_table_POWER_OF_FIVE_128": "bdd28e83b60fa362"
}
}Prose assessment
{
"label": "Lean proof closed; predictive prose review no longer required",
"assessment_status": null,
"fingerprint_relation": "unknown",
"assessment_fingerprint": null,
"current_fingerprint": "sound-v2:945abe3b563af02a26bd08188294ffd72b2c5a42175a91931a6d5b428a558f3e",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}