Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma
roundsMagnitude
for the real value of x/y.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.Binary64NormalEncoderRounds
import Tablet.Binary64ModelDefault
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelF64Div
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 1000000
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: Binary64ExactPositiveDivRounds]
theorem Binary64ExactPositiveDivRounds :
∀ (a b : F64) (x y : Rat),
a.val < 2047 * 2 ^ 52 → b.val < 2047 * 2 ^ 52 →
(let bits := a.val
let e := bits / (2 ^ 52 : Nat)
let m := bits % (2 ^ 52 : Nat)
if e = 0 then (m : Rat) / (2 : Rat) ^ (1074 : Nat)
else if 1075 ≤ e then (((2 ^ 52 : Nat) + m : Nat) : Rat) * (2 : Rat) ^ (e - 1075)
else (((2 ^ 52 : Nat) + m : Nat) : Rat) / (2 : Rat) ^ (1075 - e)) = x →
(let bits := b.val
let e := bits / (2 ^ 52 : Nat)
let m := bits % (2 ^ 52 : Nat)
if e = 0 then (m : Rat) / (2 : Rat) ^ (1074 : Nat)
else if 1075 ≤ e then (((2 ^ 52 : Nat) + m : Nat) : Rat) * (2 : Rat) ^ (e - 1075)
else (((2 ^ 52 : Nat) + m : Nat) : Rat) / (2 : Rat) ^ (1075 - e)) = y →
0 < x → 0 < y → (2 : Rat) ^ (-1022 : Int) ≤ x / y →
x / y < (2 : Rat) ^ (128 : Nat) →
∃ w : F64, ModelF64Div a b = ok w ∧ w.val < 2 ^ 63 ∧
DecimalGoalVocabularyDefault.roundsMagnitude ((x / y : Rat) : Real) w := 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
roundsMagnitude relation. That relation
bounds the returned raw word by 2047\,2^{52}<2^{63}, proving the final
clear-sign bound.Lean proof
intro a b x y ha hb hax hby hx hy hlo hhi
let roundEvenNat := fun z : Rat =>
let q := z.num.natAbs / z.den
let r := z.num.natAbs % z.den
if z.den < 2 * r ∨ (z.den = 2 * r ∧ q % 2 = 1) then q + 1 else q
let normalExponent := fun z : Rat =>
(List.range 2046).foldl (fun (old : Nat) (i : Nat) =>
let e : Nat := i + 1
if ((2 : Rat) ^ ((e : Int) - 1023)) ≤ z then e else old) 1
let e := normalExponent (x / y)
let significand := roundEvenNat ((x / y) * ((2 : Rat) ^ ((1075 : Int) - (e : Int))))
let bits := if significand = 2 ^ 53 then (e + 1) * 2 ^ 52
else e * 2 ^ 52 + (significand - 2 ^ 52)
let w : F64 := ⟨BitVec.ofNat 64 bits⟩
have hround : DecimalGoalVocabularyDefault.roundsMagnitude (((x / y : Rat) : Real)) w := by
exact Binary64NormalEncoderRounds (x / y) hlo hhi
have haexp : a.val / (2 ^ 52 : Nat) < 2047 := by
apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < (2 ^ 52 : Nat))).2
simpa [Nat.mul_comm] using ha
have hbexp : b.val / (2 ^ 52 : Nat) < 2047 := by
apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < (2 ^ 52 : Nat))).2
simpa [Nat.mul_comm] using hb
have hasign : a.val / (2 ^ 63 : Nat) = 0 := Nat.div_eq_of_lt (by omega)
have hbsign : b.val / (2 ^ 63 : Nat) = 0 := Nat.div_eq_of_lt (by omega)
have hamag : a.val % (2 ^ 63 : Nat) = a.val := Nat.mod_eq_of_lt (by omega)
have hbmag : b.val % (2 ^ 63 : Nat) = b.val := Nat.mod_eq_of_lt (by omega)
refine ⟨w, ?_, ?_, hround⟩
· simp only [ModelF64Div, Binary64ModelDefault]
have ha2047 : a.val / (2 ^ 52 : Nat) ≠ 2047 := by omega
have hb2047 : b.val / (2 ^ 52 : Nat) ≠ 2047 := by omega
simp only [hasign, hbsign, hamag, hbmag, ha2047, hb2047, if_false]
let ca := if a.val / 4503599627370496 = 0 then
if a.val % 4503599627370496 = 0 then 2 else 3 else 4
let cb := if b.val / 4503599627370496 = 0 then
if b.val % 4503599627370496 = 0 then 2 else 3 else 4
have ca0 : ca ≠ 0 := by
dsimp [ca]
by_cases h : a.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have ca1 : ca ≠ 1 := by
dsimp [ca]
by_cases h : a.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have cb0 : cb ≠ 0 := by
dsimp [cb]
by_cases h : b.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have cb1 : cb ≠ 1 := by
dsimp [cb]
by_cases h : b.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have ca2 : ca ≠ 2 := by
intro hca
have he : a.val / 4503599627370496 = 0 := by
dsimp [ca] at hca
split at hca <;> omega
have hm : a.val % 4503599627370496 = 0 := by
dsimp [ca] at hca
rw [if_pos he] at hca
split at hca <;> omega
have haz : a.val = 0 := by
have hdecomp := Nat.mod_add_div a.val 4503599627370496
omega
simp [haz] at hax
linarith
have cb2 : cb ≠ 2 := by
intro hcb
have he : b.val / 4503599627370496 = 0 := by
dsimp [cb] at hcb
split at hcb <;> omega
have hm : b.val % 4503599627370496 = 0 := by
dsimp [cb] at hcb
rw [if_pos he] at hcb
split at hcb <;> omega
have hbz : b.val = 0 := by
have hdecomp := Nat.mod_add_div b.val 4503599627370496
omega
simp [hbz] at hby
linarith
change (if ca = 0 ∨ cb = 0 then _ else
if (ca = 1 ∧ cb = 1) ∨ (ca = 2 ∧ cb = 2) then _ else
if ca = 1 ∨ cb = 2 then _ else if cb = 1 ∨ ca = 2 then _ else _) = _
simp only [ca0, ca1, ca2, cb0, cb1, cb2, false_or, false_and,
and_false, if_false]
rw [hax, hby]
have hover : ¬ (2 ^ 1024 - 2 ^ 970 : Rat) ≤ x / y := by
intro h
have impossible : (2 ^ 1024 - 2 ^ 970 : Rat) < 2 ^ 128 := h.trans_lt hhi
set_option exponentiation.threshold 2048 in norm_num at impossible
rw [if_neg hover, if_neg (not_lt_of_ge hlo)]
have hneg : decide (((0 : Nat) != 0) = true) = false := rfl
rw [hneg]
simp only [Bool.false_eq_true, if_false, Nat.add_zero]
change ok w = ok w
rfl
· dsimp [DecimalGoalVocabularyDefault] at hround
exact lt_of_le_of_lt hround.2.1 (by norm_num)
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.Binary64NormalEncoderRounds
import Tablet.Binary64ModelDefault
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelF64Div
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 1000000
set_option maxHeartbeats 2000000
namespace dec2flt_model
-- [TABLET NODE: Binary64ExactPositiveDivRounds]
theorem Binary64ExactPositiveDivRounds :
∀ (a b : F64) (x y : Rat),
a.val < 2047 * 2 ^ 52 → b.val < 2047 * 2 ^ 52 →
(let bits := a.val
let e := bits / (2 ^ 52 : Nat)
let m := bits % (2 ^ 52 : Nat)
if e = 0 then (m : Rat) / (2 : Rat) ^ (1074 : Nat)
else if 1075 ≤ e then (((2 ^ 52 : Nat) + m : Nat) : Rat) * (2 : Rat) ^ (e - 1075)
else (((2 ^ 52 : Nat) + m : Nat) : Rat) / (2 : Rat) ^ (1075 - e)) = x →
(let bits := b.val
let e := bits / (2 ^ 52 : Nat)
let m := bits % (2 ^ 52 : Nat)
if e = 0 then (m : Rat) / (2 : Rat) ^ (1074 : Nat)
else if 1075 ≤ e then (((2 ^ 52 : Nat) + m : Nat) : Rat) * (2 : Rat) ^ (e - 1075)
else (((2 ^ 52 : Nat) + m : Nat) : Rat) / (2 : Rat) ^ (1075 - e)) = y →
0 < x → 0 < y → (2 : Rat) ^ (-1022 : Int) ≤ x / y →
x / y < (2 : Rat) ^ (128 : Nat) →
∃ w : F64, ModelF64Div a b = ok w ∧ w.val < 2 ^ 63 ∧
DecimalGoalVocabularyDefault.roundsMagnitude ((x / y : Rat) : Real) w := by
-- BODY
intro a b x y ha hb hax hby hx hy hlo hhi
let roundEvenNat := fun z : Rat =>
let q := z.num.natAbs / z.den
let r := z.num.natAbs % z.den
if z.den < 2 * r ∨ (z.den = 2 * r ∧ q % 2 = 1) then q + 1 else q
let normalExponent := fun z : Rat =>
(List.range 2046).foldl (fun (old : Nat) (i : Nat) =>
let e : Nat := i + 1
if ((2 : Rat) ^ ((e : Int) - 1023)) ≤ z then e else old) 1
let e := normalExponent (x / y)
let significand := roundEvenNat ((x / y) * ((2 : Rat) ^ ((1075 : Int) - (e : Int))))
let bits := if significand = 2 ^ 53 then (e + 1) * 2 ^ 52
else e * 2 ^ 52 + (significand - 2 ^ 52)
let w : F64 := ⟨BitVec.ofNat 64 bits⟩
have hround : DecimalGoalVocabularyDefault.roundsMagnitude (((x / y : Rat) : Real)) w := by
exact Binary64NormalEncoderRounds (x / y) hlo hhi
have haexp : a.val / (2 ^ 52 : Nat) < 2047 := by
apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < (2 ^ 52 : Nat))).2
simpa [Nat.mul_comm] using ha
have hbexp : b.val / (2 ^ 52 : Nat) < 2047 := by
apply (Nat.div_lt_iff_lt_mul (by positivity : 0 < (2 ^ 52 : Nat))).2
simpa [Nat.mul_comm] using hb
have hasign : a.val / (2 ^ 63 : Nat) = 0 := Nat.div_eq_of_lt (by omega)
have hbsign : b.val / (2 ^ 63 : Nat) = 0 := Nat.div_eq_of_lt (by omega)
have hamag : a.val % (2 ^ 63 : Nat) = a.val := Nat.mod_eq_of_lt (by omega)
have hbmag : b.val % (2 ^ 63 : Nat) = b.val := Nat.mod_eq_of_lt (by omega)
refine ⟨w, ?_, ?_, hround⟩
· simp only [ModelF64Div, Binary64ModelDefault]
have ha2047 : a.val / (2 ^ 52 : Nat) ≠ 2047 := by omega
have hb2047 : b.val / (2 ^ 52 : Nat) ≠ 2047 := by omega
simp only [hasign, hbsign, hamag, hbmag, ha2047, hb2047, if_false]
let ca := if a.val / 4503599627370496 = 0 then
if a.val % 4503599627370496 = 0 then 2 else 3 else 4
let cb := if b.val / 4503599627370496 = 0 then
if b.val % 4503599627370496 = 0 then 2 else 3 else 4
have ca0 : ca ≠ 0 := by
dsimp [ca]
by_cases h : a.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have ca1 : ca ≠ 1 := by
dsimp [ca]
by_cases h : a.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have cb0 : cb ≠ 0 := by
dsimp [cb]
by_cases h : b.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have cb1 : cb ≠ 1 := by
dsimp [cb]
by_cases h : b.val / 4503599627370496 = 0
· rw [if_pos h]; split <;> omega
· rw [if_neg h]; omega
have ca2 : ca ≠ 2 := by
intro hca
have he : a.val / 4503599627370496 = 0 := by
dsimp [ca] at hca
split at hca <;> omega
have hm : a.val % 4503599627370496 = 0 := by
dsimp [ca] at hca
rw [if_pos he] at hca
split at hca <;> omega
have haz : a.val = 0 := by
have hdecomp := Nat.mod_add_div a.val 4503599627370496
omega
simp [haz] at hax
linarith
have cb2 : cb ≠ 2 := by
intro hcb
have he : b.val / 4503599627370496 = 0 := by
dsimp [cb] at hcb
split at hcb <;> omega
have hm : b.val % 4503599627370496 = 0 := by
dsimp [cb] at hcb
rw [if_pos he] at hcb
split at hcb <;> omega
have hbz : b.val = 0 := by
have hdecomp := Nat.mod_add_div b.val 4503599627370496
omega
simp [hbz] at hby
linarith
change (if ca = 0 ∨ cb = 0 then _ else
if (ca = 1 ∧ cb = 1) ∨ (ca = 2 ∧ cb = 2) then _ else
if ca = 1 ∨ cb = 2 then _ else if cb = 1 ∨ ca = 2 then _ else _) = _
simp only [ca0, ca1, ca2, cb0, cb1, cb2, false_or, false_and,
and_false, if_false]
rw [hax, hby]
have hover : ¬ (2 ^ 1024 - 2 ^ 970 : Rat) ≤ x / y := by
intro h
have impossible : (2 ^ 1024 - 2 ^ 970 : Rat) < 2 ^ 128 := h.trans_lt hhi
set_option exponentiation.threshold 2048 in norm_num at impossible
rw [if_neg hover, if_neg (not_lt_of_ge hlo)]
have hneg : decide (((0 : Nat) != 0) = true) = false := rfl
rw [hneg]
simp only [Bool.false_eq_true, if_false, Nat.add_zero]
change ok w = ok w
rfl
· dsimp [DecimalGoalVocabularyDefault] at hround
exact lt_of_le_of_lt hround.2.1 (by norm_num)
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Used by
Inspect related source (44)
- BiasedFp · dec2flt/common.rs:52 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
More program dependencies (11)
- 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
- ByteSlice · dec2flt/common.rs:4 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 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)
- div · core/src/ops/arith.rs:515 Rust library
- clone · core/src/clone.rs:698 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
- Binary64AdjacentNormalValues
- Binary64EncoderCarryArithmetic
- Binary64ExactPositiveDivRounds
- Binary64FiniteMagnitudeStrictMono
- Binary64Model
- Binary64ModelDefault
All 15 entries
- Binary64AdjacentNormalValues
- Binary64EncoderCarryArithmetic
- Binary64ExactPositiveDivRounds
- Binary64FiniteMagnitudeStrictMono
- Binary64Model
- Binary64ModelDefault
- Binary64NormalEncoderRounds
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- F64
- ModelF64Div
- core num FpCategory
- num imp dec2flt common BiasedFp
- num imp dec2flt decimal Decimal
Technical checking records
Local closure summary
{
"node": "Binary64ExactPositiveDivRounds",
"closure_version": "patch_c_v1",
"active_decl_hash": "ed7fea7204c1cb1f6ec7b0175b4eaaa852e63f5fc2a4a86e4f443dc98a1e91ba",
"active_statement_hash": "b661b8b9f88fc89e2ad71a8443b9e6bc2e627f4cea22c73911f997f8cbd86849",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-131",
"boundary_theorems": {},
"strict_theorem_deps": {
"Binary64ModelDefault": "c722a2c00805b545",
"Binary64NormalEncoderRounds": "e7e60775e2c3fcdc",
"DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b"
},
"strict_definition_deps": {
"Binary64Model": "c98c2c511cf0ced6",
"Binary64ModelDefault": "dc548d1e27696ba4",
"DecimalGoalVocabulary": "f76c8174a4d58eb5",
"DecimalGoalVocabularyDefault": "512f8d0aea894250",
"F64": "ec4e25fbaf4e11d4",
"ModelF64Div": "f8da2e585a4f4183",
"core_num_FpCategory": "f500de642a5d5148"
}
}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:2905db8bc13490ceb75ee7b0124103294bfc419facca050cb4155593503072d0",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}