Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma
roundsMagnitude of
DecimalGoalVocabularyDefault for the real value v10^i.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.Binary64FromU64Exact
import Tablet.Binary64Pow10FastPathExact
import Tablet.Binary64ExactPositiveMulRounds
import Tablet.Binary64ZeroMulRounds
import Tablet.P14_FiniteMagnitudeZero
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 1000000
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: P14_NativeMultiplyRounding]
theorem P14_NativeMultiplyRounding (v : Std.U64) (i : Std.Usize) (hv : v.val <= 2 ^ 53) (hi : i.val <= 22) :
exists a p m : F64, ModelF64FromU64 v = ok a /\
F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path i = ok p /\
ModelF64Mul a p = ok m /\ m.val < 2 ^ 63 /\
DecimalGoalVocabularyDefault.roundsMagnitude
((v.val : Real) * (10 : Real) ^ (i.val : Int)) m := 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
obtain ⟨a, ha, haFinite, haDecode, _⟩ := Binary64FromU64Exact v hv
obtain ⟨p, hp, hpFinite, hpDecode⟩ := Binary64Pow10FastPathExact i hi
have hpFinite' : p.val < 2047 * 2 ^ 52 := by norm_num at hpFinite ⊢; exact hpFinite
have tenPositive : (0 : Rat) < 10 ^ i.val := by positivity
have tenLower : (1 : Rat) <= 10 ^ i.val := one_le_pow₀ (by norm_num)
have tenUpper : (10 : Rat) ^ i.val <= 10 ^ (22 : Nat) :=
pow_le_pow_right₀ (by norm_num) hi
have vUpper : (v.val : Rat) <= 2 ^ (53 : Nat) := by exact_mod_cast hv
by_cases hvZero : v.val = 0
· have aZero := P14_FiniteMagnitudeZero a haFinite (by simpa only [hvZero, Nat.cast_zero] using haDecode)
obtain ⟨hm, hb, hr⟩ := Binary64ZeroMulRounds a p (10 ^ i.val)
aZero hpFinite' hpDecode tenPositive
refine ⟨a, p, a, ha, hp, hm, hb, ?_⟩
rw [hvZero, Nat.cast_zero, zero_mul]
exact hr
· have vLower : (1 : Rat) <= v.val := by
exact_mod_cast (by omega : 1 <= v.val)
have lo : (2 : Rat) ^ (-1022 : Int) <= (v.val : Rat) * 10 ^ i.val := by
have unit : (1 : Rat) <= (v.val : Rat) * 10 ^ i.val :=
one_le_mul_of_one_le_of_one_le vLower tenLower
have tiny : (2 : Rat) ^ (-1022 : Int) <= 1 := by
calc
(2 : Rat) ^ (-1022 : Int) <= (2 : Rat) ^ (0 : Int) :=
zpow_le_zpow_right₀ (by norm_num) (by norm_num)
_ = 1 := zpow_zero _
exact tiny.trans unit
have hiProduct : (v.val : Rat) * 10 ^ i.val < 2 ^ (128 : Nat) := by
calc
(v.val : Rat) * 10 ^ i.val <= (2 ^ (53 : Nat) : Rat) * 10 ^ (22 : Nat) :=
mul_le_mul vUpper tenUpper (by positivity) (by positivity)
_ < 2 ^ (128 : Nat) := by norm_num
obtain ⟨m, hm, hb, hr⟩ := Binary64ExactPositiveMulRounds a p
(v.val : Rat) (10 ^ i.val) haFinite hpFinite' haDecode hpDecode lo hiProduct
refine ⟨a, p, m, ha, hp, hm, hb, ?_⟩
have argEq : (((v.val : Rat) * (10 : Rat) ^ i.val : Rat) : Real) =
(v.val : Real) * (10 : Real) ^ (i.val : Int) := by
simp only [Rat.cast_mul, Rat.cast_pow, Rat.cast_natCast, Rat.cast_ofNat, zpow_natCast]
rw [argEq] at hr
exact hr
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.Binary64FromU64Exact
import Tablet.Binary64Pow10FastPathExact
import Tablet.Binary64ExactPositiveMulRounds
import Tablet.Binary64ZeroMulRounds
import Tablet.P14_FiniteMagnitudeZero
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 1000000
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: P14_NativeMultiplyRounding]
theorem P14_NativeMultiplyRounding (v : Std.U64) (i : Std.Usize) (hv : v.val <= 2 ^ 53) (hi : i.val <= 22) :
exists a p m : F64, ModelF64FromU64 v = ok a /\
F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64.pow10_fast_path i = ok p /\
ModelF64Mul a p = ok m /\ m.val < 2 ^ 63 /\
DecimalGoalVocabularyDefault.roundsMagnitude
((v.val : Real) * (10 : Real) ^ (i.val : Int)) m := by
-- BODY
obtain ⟨a, ha, haFinite, haDecode, _⟩ := Binary64FromU64Exact v hv
obtain ⟨p, hp, hpFinite, hpDecode⟩ := Binary64Pow10FastPathExact i hi
have hpFinite' : p.val < 2047 * 2 ^ 52 := by norm_num at hpFinite ⊢; exact hpFinite
have tenPositive : (0 : Rat) < 10 ^ i.val := by positivity
have tenLower : (1 : Rat) <= 10 ^ i.val := one_le_pow₀ (by norm_num)
have tenUpper : (10 : Rat) ^ i.val <= 10 ^ (22 : Nat) :=
pow_le_pow_right₀ (by norm_num) hi
have vUpper : (v.val : Rat) <= 2 ^ (53 : Nat) := by exact_mod_cast hv
by_cases hvZero : v.val = 0
· have aZero := P14_FiniteMagnitudeZero a haFinite (by simpa only [hvZero, Nat.cast_zero] using haDecode)
obtain ⟨hm, hb, hr⟩ := Binary64ZeroMulRounds a p (10 ^ i.val)
aZero hpFinite' hpDecode tenPositive
refine ⟨a, p, a, ha, hp, hm, hb, ?_⟩
rw [hvZero, Nat.cast_zero, zero_mul]
exact hr
· have vLower : (1 : Rat) <= v.val := by
exact_mod_cast (by omega : 1 <= v.val)
have lo : (2 : Rat) ^ (-1022 : Int) <= (v.val : Rat) * 10 ^ i.val := by
have unit : (1 : Rat) <= (v.val : Rat) * 10 ^ i.val :=
one_le_mul_of_one_le_of_one_le vLower tenLower
have tiny : (2 : Rat) ^ (-1022 : Int) <= 1 := by
calc
(2 : Rat) ^ (-1022 : Int) <= (2 : Rat) ^ (0 : Int) :=
zpow_le_zpow_right₀ (by norm_num) (by norm_num)
_ = 1 := zpow_zero _
exact tiny.trans unit
have hiProduct : (v.val : Rat) * 10 ^ i.val < 2 ^ (128 : Nat) := by
calc
(v.val : Rat) * 10 ^ i.val <= (2 ^ (53 : Nat) : Rat) * 10 ^ (22 : Nat) :=
mul_le_mul vUpper tenUpper (by positivity) (by positivity)
_ < 2 ^ (128 : Nat) := by norm_num
obtain ⟨m, hm, hb, hr⟩ := Binary64ExactPositiveMulRounds a p
(v.val : Rat) (10 ^ i.val) haFinite hpFinite' haDecode hpDecode lo hiProduct
refine ⟨a, p, m, ha, hp, hm, hb, ?_⟩
have argEq : (((v.val : Rat) * (10 : Rat) ^ i.val : Rat) : Real) =
(v.val : Real) * (10 : Real) ^ (i.val : Int) := by
simp only [Rat.cast_mul, Rat.cast_pow, Rat.cast_natCast, Rat.cast_ofNat, zpow_natCast]
rw [argEq] at hr
exact hr
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (45)
- from_u64 · dec2flt/mod.rs:263 Program Rust
- pow10_fast_path · dec2flt/mod.rs:222 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
More program dependencies (12)
- 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)
- mul · core/src/ops/arith.rs:350 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 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
- 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
- Binary64AdjacentNormalValues
- Binary64EncoderCarryArithmetic
- Binary64ExactPositiveMulRounds
- Binary64FiniteMagnitudeStrictMono
- Binary64FromU64Exact
- Binary64Model
All 46 entries
- Binary64AdjacentNormalValues
- Binary64EncoderCarryArithmetic
- Binary64ExactPositiveMulRounds
- Binary64FiniteMagnitudeStrictMono
- Binary64FromU64Exact
- Binary64Model
- Binary64ModelDefault
- Binary64NativeCallDomain
- Binary64NormalEncoderRounds
- Binary64Pow10FastPathExact
- Binary64ZeroMulRounds
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- F64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 pow10 fast path
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- P14 FiniteMagnitudeZero
- P14 NativeMultiplyRounding
- Preamble
- core num FpCategory
- num imp dec2flt common BiasedFp
- num imp dec2flt decimal Decimal
Technical checking records
Local closure summary
{
"node": "P14_NativeMultiplyRounding",
"closure_version": "patch_c_v1",
"active_decl_hash": "f099b02b2f3df301da9c0f6bc8e65dca1da1c8a672f8425a6a5947f3076d2603",
"active_statement_hash": "e7542c475c18eee33b896bfe66fa764a299d1fd287c7bc4c28e2cab1ac6d5c41",
"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-199",
"boundary_theorems": {},
"strict_theorem_deps": {
"Binary64ExactPositiveMulRounds": "a05b820da3503675",
"Binary64FromU64Exact": "f1dc380dae903c52",
"Binary64Pow10FastPathExact": "93bbdd6f862814f8",
"Binary64ZeroMulRounds": "c57caade6d34c32a",
"P14_FiniteMagnitudeZero": "85653a611cd111c5"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "f76c8174a4d58eb5",
"DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
"F64": "ec4e25fbaf4e11d4",
"F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path": "c0ce6fdd5caeca22",
"ModelF64FromU64": "97a26f5bc593ff7a",
"ModelF64Mul": "ba97971db93c2ae2"
}
}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:330dffe035011a7b4c7abf58514bff9795e7d5751df6d10d5dc957b2e3ef807f",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}