An FP32 word is recovered exactly from its round-to-nearest-even BF16 word, its low 16 bits, and one tie flag
For all , if , , and , then
What the notation means · or point at any symbol
- NNatural numbers
- The natural numbers 0, 1, 2, …. In Lean they start at 0. (
ℕ) - x ∈ TVariables
- u, H, L, b range over natural numbers: the statement must hold for every choice. (
(u H L b : ℕ)) - <Less than
- u is strictly smaller than 2^32. (
u < 2 ^ 32) - =Equality
- H and u/2^16 are the same. (
H = u / 2 ^ 16) - ∨Or
- At least one holds: b = H, or b = H + 1. (
b = H ∨ b = H + 1) - aᵇPower
- 2 raised to the power 32. (
2 ^ 32) - a/bDivision
- u divided by 2^16. In Lean, dividing by 0 gives 0. (
u / 2 ^ 16) - modRemainder
- The remainder when u is divided by 2^16. (
u % 2 ^ 16) - ≠Not equal
- L and 2^15 are different. (
L ≠ 2 ^ 15) - ⟹Implies
- If L ≠ 2^15, then u = (b − 1 if 2^15 < L, else 0) · 2^16 + L. (Between types, A → B is the type of functions from A to B.) (
L ≠ 2 ^ 15 → u = (b - (if 2 ^ 15 < L th…) - ·Multiplication
- b − 1 if 2^15 < L, else 0 times 2^16. (
(b - (if 2 ^ 15 < L then 1 else 0)) * 2…) - -Subtraction
- b minus 1 if 2^15 < L, else 0. On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (
b - (if 2 ^ 15 < L then 1 else 0)) - +Addition
- H plus 1. (
H + 1) - { a if c; b otherwiseCases (if … then … else)
- H when H % 2 = 0, and H + 1 otherwise. (
if H % 2 = 0 then H else H + 1) - ≤At most
- b − H is less than or equal to 1. (
b - H ≤ 1) - ∧And
- Both hold: b − H ≤ 1, and u = (b − (b − H)) · 2^16 + L. (
b - H ≤ 1 ∧ u = (b - (b - H)) * 2 ^ 16 …)
theorem fp32-from-bf16-plus-low-half-and-tie-flag (u H L b : ℕ) (hu : u < 2 ^ 32) (hH : H = u / 2 ^ 16) (hL : L = u % 2 ^ 16) (hb : b = if L < 2 ^ 15 then H else if 2 ^ 15 < L then H + 1 else if H % 2 = 0 then H else H + 1) :
(b = H ∨ b = H + 1) ∧ (L ≠ 2 ^ 15 → u = (b - (if 2 ^ 15 < L then 1 else 0)) * 2 ^ 16 + L) ∧ (L = 2 ^ 15 → b - H ≤ 1 ∧ u = (b - (b - H)) * 2 ^ 16 + L) ∧ (b * 2 ^ 16 ≤ u + 2 ^ 15 ∧ u ≤ b * 2 ^ 16 + 2 ^ 15)For the 33-bit master-weight codec proposed for Baguette, which keeps the BF16 operand bank and drops the FP32 master. Let u < 2^32 be a raw FP32 bit pattern. H = u / 2^16 and L = u mod 2^16 are its high and low halves. b is the round-to-nearest-even of u to its upper 16 bits: H if L < 2^15; H + 1 if L > 2^15; at the tie L = 2^15, H if H is even and H + 1 if it is odd. For finite FP32 values this is exactly the BF16 conversion: BF16 is FP32's upper half, and rounding the magnitude bits carries into the exponent. The statement has four parts. (1) b is H or H + 1. (2) Off the tie, u = (b - c) * 2^16 + L, where c = 1 when L > 2^15 and 0 otherwise, so b and L alone recover u. (3) At the tie L = 2^15, u = (b - f) * 2^16 + L with one flag f = b - H <= 1. (4) The integer residual u - b * 2^16 lies in [-2^15, 2^15]: 65,537 values, one more than 16 bits hold.
How it was proved
- Proved
- 5 October 2026
- By
- Ajax
- Checked by
- Lean's kernel (Lean 4.33.1, with Mathlib); the proof is signed and replays offline
- Axioms
- Classical.choice, Quot.sound, propext
- Proof
- 31 lines of Lean