\begin{lemma}[Binary64 grid certificate and assembly]
Let $A$ be real, $fp$ a biased pair, and $w$ an F64 word assembled from that
pair.  Put $U=2^{52}$, $T=2047U$, let
$H=2^{1024}-2^{970}$, and let $r$ be the raw word computed by the
\texttt{assembledWord} formula.  Assume $A\ge0$ and that one of the following
three alternatives holds:
\begin{enumerate}
\item $r=T$ and $H\le A$;
\item there is a natural number $j$ such that
\[
\begin{gathered}
j\le2^{53},\qquad r=j,\qquad A\le2^{53}2^{-1074},\\
A\le j2^{-1074}+2^{-1075},\qquad
j2^{-1074}\le A+2^{-1075},
\end{gathered}
\]
and
\[
\bigl(A=(j+\tfrac12)2^{-1074}\ \lor\
      A=(j-\tfrac12)2^{-1074}\bigr)
\quad\Longrightarrow\quad j\bmod 2=0;
\]
\item there are natural numbers $p,j$ such that
\[
2\le p\le2046,\qquad 2^{52}\le j\le2^{53},\qquad
(p<2046\ \lor\ j<2^{53}),
\]
\[
r=pU+(j-U),\qquad \Delta=2^{p-1075},
\]
\[
U\Delta\le A,\qquad A\le2^{53}\Delta,\qquad A<H,
\]
\[
A\le j\Delta+\frac{\Delta}{2},\qquad
j\Delta\le A+\frac{\Delta}{2},
\]
and
\[
\bigl(A=(j+\tfrac12)\Delta\ \lor\
      A=(j-\tfrac12)\Delta\bigr)
\quad\Longrightarrow\quad j\bmod 2=0.
\]
\end{enumerate}
Then $w$ is a binary64 magnitude-rounding target for $A$.
\end{lemma}
\begin{proof}
Unfold \noderef{DecimalGoalVocabularyDefault}.  The assembled-word hypothesis
is exactly $w.\mathit{val}=r$.  We prove the three clauses of
\texttt{roundsMagnitude}.

In the overflow alternative, $r=T$ and $H\le A$ are precisely the bound on
the word and the infinity branch of the definition.  Thus assume one of the
finite-grid alternatives.  Their raw formulas and ranges give $r<T$: on the
lowest grid $r\le2^{53}<2047U$; in the normal grid the excluded top endpoint
is the only way for $pU+(j-U)$ to equal $T$.  Both alternatives explicitly
give $A<H$, except that the lowest grid gives the stronger bound
$A\le2^{53}2^{-1074}=2^{-1021}<H$.

Let $F(n)$ denote the finite-magnitude decoder in the vocabulary.  On the
lowest grid, direct division and remainder by $U$ show
\[
                         F(j)=j2^{-1074}                \tag{1}
\]
for every $0\le j\le2^{53}$.  For $j<U$ this is the subnormal formula.  For
$U\le j\le2U$, its exponent field is one (with the upper endpoint represented
as field two and zero fraction), and the normal formula reduces to the same
quantity.  Hence the minimum normal $j=U$ is an interior grid index, not a
case boundary.

The two half-step inequalities say exactly that $F(j)$ is no farther from
$A$ than either existing adjacent grid point.  At $j=0$ nonnegativity of $A$
excludes a lower competitor; at $j=2^{53}$ the assumed upper endpoint bound
excludes the higher binade.  Every other finite raw word is ordered away from
one of those adjacent points.  Strict monotonicity from
\noderef{Binary64FiniteMagnitudeStrictMono} then makes it at least as far from
$A$.  Thus $F(r)$ minimizes absolute error globally.

For a normal certificate, the raw formula has exponent field $p$ and
significand $j$.  For $p\le2045$ and $j<2^{53}$, the decoder calculation in
\noderef{Binary64AdjacentNormalValues} gives the value and its adjacent
successor.  When $j=2^{53}$, apply that same statement to $j-1$ and its
successor.  The remaining top finite field $p=2046$, necessarily with
$j<2^{53}$, follows by substituting quotient $2046$ and remainder $j-U$
directly in the product branch of the displayed decoder.  In every case,
\[
                         F(r)=j\Delta,\qquad
                         \Delta=2^{p-1075}.             \tag{2}
\]
The binade bounds put $A$ between $U\Delta$ and $2U\Delta$.  Consequently a
word in a lower binade cannot improve on the lower endpoint and a word in a
higher binade cannot improve on the upper endpoint.  Within the binade, the
finite words are the consecutive grid $k\Delta$; the two half-step
inequalities make $j\Delta$ no farther than its neighbors, and monotonicity
again makes it no farther than any other finite word.  The same argument at
$j=U$ and $j=2U$ uses the shared endpoint, so no gap is introduced between
adjacent binades.  The condition $A<H$ handles the top finite binade.

It remains to check ties.  In the lowest grid the raw word is $j$, so the
certificate's evenness of $j$ is exactly $r\bmod2=0$.  In a normal grid,
\[
 r=pU+(j-U),
\]
and $U=2^{52}$ is even, so $r$ and $j$ have the same parity, including the
carry endpoint $j=2U$.  Equality of distances between consecutive ordered
grid points occurs only at their midpoint.  The certificate's implication
therefore makes $r$ even in every exact tie.  We have proved nonnegativity,
$w.\mathit{val}=r\le T$, the correct overflow/finite branch, global minimal
distance to every finite competing F64 word, and the even-word tie clause.
These are exactly all conjuncts of \texttt{roundsMagnitude($A$,$w$)}.
\end{proof}
