% Appendix A. The formal companion. \section{Formal verification}\label{app:formal} \subsection{Scope}\label{ss:formal-scope} The main text is written without reference to the formal verification, and every statement in it is proved there in the usual way. This appendix records, in addition, which of these statements have a formally verified counterpart, what exactly is verified, and how. The formal companion is a Lean~4 package of seven modules, each importing only Mathlib: \begin{center} \begin{tabular}{@{}lll@{}} \code{AHM2.RamanujanHodge} & \code{AHM2.Deficit} & \code{AHM2.S5Certificate}\\ \code{AHM2.SpinCert} & \code{AHM2.Universe} & \code{AHM2.Converse}\\ \code{AHM2.Involution} & & \end{tabular} \end{center} with declarations in namespaces of the form \code{SC2.M}, where \code{M} is the name of the module, except that the declarations of \code{AHM2.S5Certificate} lie in \code{SC2.S5}; the anchors of the paper omit the prefix \code{SC2}. It is built with the toolchain \code{leanprover/lean4:v4.36.0-rc2}, a release candidate, and with Mathlib at the commit \code{b7fb16a940e9d6383e4376cecea18bb818a2d2e3}, the same as the companion of the first paper. The statements recalled from the first paper carry anchors to declarations of its companion, in the namespace \code{GaiMua.Research.StandardConjectures} \cite{Liu2026AHM}; that companion is part of the formal development of this paper by reference and is not rebuilt here. The Lean statements formalise the linear algebra and the finite combinatorics of the proofs. The geometric inputs, namely the intersection formulas of Tian--Xiao and Helm--Tian--Xiao, the spanning of the Tate classes, the Ramanujan bounds and the comparison isomorphisms, enter as hypotheses: a Lean theorem such as \code{RamanujanHodge.posDef\_of\_gauge} says that a symmetric matrix of the shape that \cref{prop:gauge} gives is positive definite when $G$ is, and the paper supplies, from the geometry, that the intersection matrix has that shape. \Cref{tab:formal} lists, for the main statements of the paper, the declarations they rest on and the hypotheses of these declarations that are geometric. \begin{longtable}{@{}>{\raggedright\arraybackslash}p{.22\textwidth}>{\raggedright\footnotesize\arraybackslash}p{.39\textwidth} >{\raggedright\arraybackslash}p{.3\textwidth}@{}} \caption{Main statements, their Lean declarations (namespace prefix \texttt{SC2} omitted), and the hypotheses of the declarations that the paper supplies from the geometry.}\label{tab:formal}\\ \toprule Statement & Lean declarations & Geometric hypotheses\\\midrule\endfirsthead \toprule Statement & Lean declarations & Geometric hypotheses\\\midrule\endhead \Cref{prop:gauge,lem:gauge} & \code{RamanujanHodge.gauge\_congr}, \code{posDef\_of\_gauge} & the shape $H_{ab}=p_ad_aG_{ab}d_b^{-1}$ (\cref{thm:tx-formula,prop:tx-cycle}) \\ \Cref{ex:d4,prop:G4-eigen} & \code{RamanujanHodge.G4}, \code{G4\_quad}, \code{G4\_posDef} & none \\ \Cref{thm:spin}, $d=4,6$ & \code{SpinCert.spin\_gram\_g4}, \code{spin\_gram\_g6} & none (kernel decision) \\ \Cref{cor:spin-positive} & \code{RamanujanHodge.posDef\_of\_gram\_det}, \code{gram\_posDef} & the determinant formula of \cite[Thm.~3.5]{TianXiao2019} \\ \Cref{lem:u-vandermonde} & \code{RamanujanHodge.vandermonde\_mul\_lagU}, \code{lagU\_isUnit} & none \\ \Cref{thm:u-gram}, $n=3$ & \code{RamanujanHodge.U3\_det}, \code{H3\_eq\_gram}, \code{H3\_posDef} & the entries \eqref{eq:htx-entries} \\ \Cref{thm:AU}(iii) & \code{RamanujanHodge.lagrange\_gram\_posDef}; \code{Deficit.deficit\_posDef\_iff}, \code{permForm\_posDef\_iff} & the factorisation of \cref{thm:u-gram} \\ \Cref{prop:u-perm,thm:U5} & \code{Deficit.permForm\_neg\_dir}, \code{deficit\_posDef\_iff}; \code{Universe.U5\_hyperbolic} & as above \\ \Cref{prop:brandt} & \code{S5.T3\_symm}, \code{T3\_diag}, \code{P\_det}, \code{T3\_rowsum} & that $T_3$ is the Brandt matrix (computation) \\ \Cref{lem:generic-integral} & \code{S5.ramanujan\_strict}, \code{generic}, \code{T\_in\_interval}, \code{T\_ne\_zero} & the eigenvalues $a_3(\pi)$ \\ \Cref{thm:Bprecise}(ii) & \code{RamanujanHodge.s5\_cusp\_posDef}, \code{s5\_cusp\_posDef\_p5}; \code{S5.prim\_onedim\_pos} & the reduction to $G(T)$; the intersection numbers of the $e_ie_j$ \\ \Cref{thm:Bprecise}(iii) & \code{Universe.U3\_B\_realization}, \code{U3\_nondeg} & all cohomology spanned by algebraic classes \\ \Cref{prop:C-matrix,thm:Cprecise}(iii) & \code{RamanujanHodge.neg\_G2\_posDef}, \code{kron\_negDef\_posDef}, \code{theoremC\_sign} & the negative definite coefficient pairing (\cref{prop:C-negative}) \\ \Cref{thm:U1,thm:univ-products} & \code{Universe.U1\_block}, \code{U1\_sum} & axioms \ref{UH1}--\ref{UH3} \\ \Cref{lem:conv-minor,thm:conv-quat} & \code{Converse.quad\_neg}, \code{minor\_entries}, \code{gram\_not\_posSemidef} & the principal minor of $G(T)$ (\cref{lem:conv-minor}) \\ \Cref{cor:conv-unit-surface} & \code{Converse.unitary\_n2\_det} & the form $-M$ for $n=2$ \\ \Cref{thm:U9} & \code{Involution.trace\_mul\_transpose\_pos}, \code{eq\_zero\_of\_symm\_trace\_sq} & an orthonormal basis for the positive definite form $q$ \\ \Cref{thm:l1-signlaw,cor:l1-decide} & first paper: \code{AlienHodgePrinciples.rank2\_sign\_law}, \code{decide\_le3}, \code{blind\_rank4} & as there \\ \bottomrule \end{longtable} Not formalised: the spin-chain identity for general $d$ (\cref{thm:spin}), whose proof uses the theorem of turning tangents; the Bezout and Gram identities of the unitary family for general $n$ (\cref{prop:u-bezout,thm:u-gram}), proved in the text and checked by computation; the inertia computation of \cref{thm:bey}; the arithmetic of $\Q(\zeta_{16})^+$ and the Brandt module beyond the integer facts listed; and the cited theorems of \cref{app:inputs}. \subsection{Verification record}\label{ss:formal-record} The package was built with the pinned toolchain and Mathlib, reusing the Mathlib build of the workspace. All modules compiled without errors. For each of the $47$ theorems of the seven modules the command \texttt{\#print axioms} was run; each depends on no axioms other than \code{propext}, \code{Classical.choice} and \code{Quot.sound}. The environment of the package was then replayed by the kernel checker \code{leanchecker} in fresh mode. The certificates \code{SpinCert.spin\_gram\_g4} and \code{spin\_gram\_g6} are decided by the kernel, with \code{decide +kernel}; for $d=8$ the corresponding decision ($4900$ ordered pairs) did not complete within our resources, and the case is covered by the proof for all $d$ (\cref{thm:spin}) and by the exact computation of \cref{ss:app-spin}. The axiom report, the build log and the replay log are part of the deposit. \subsection{Anchors}\label{ss:formal-anchors} Every statement of the paper that rests on the formal companion carries an anchor, a list of the declarations it rests on, which the build of the paper checks against the declarations of the two companions. The table below gives, for each section, the number of anchored statements and of distinct declarations, and the modules in which they lie. The statement-by-statement list is in the deposit. \AHMleansummary \subsection{Possible extensions}\label{ss:formal-extensions} Two extensions would strengthen the verification: a formal proof of the spin-chain identity (\cref{thm:spin}) for all $d$, which requires a formalisation of the combinatorics of loops on a cylinder and of the parity argument of \cref{ss:spin-turning} (a discrete form of the theorem of turning tangents suffices); and a certificate for $d=8$ that checks the identity pair by pair rather than as a single decision.