\section{Verification and reproducibility}\label{sec:reproducibility} \paragraph{Source and toolchain.} The \href{https://github.com/map9959/grid-graphs/tree/6fc87a38777650b7d092b2f0f2fa8a786d3c5db8}{public verification snapshot} is Git commit \nolinkurl{6fc87a38777650b7d092b2f0f2fa8a786d3c5db8}. It contains the Lean sources, the finite certificate inputs, and the standalone Python tree generator. The file \nolinkurl{lean/lean-toolchain} selects Lean 4.33.1 (with its bundled Lake); \nolinkurl{lean/lake-manifest.json} pins mathlib 4.33.1 at commit \nolinkurl{0df444a360eaa60ab8c11dca51a86af692955474} and locks the other Lean dependencies. The commands below use a POSIX shell on x86-64 Linux, Git, Elan, and \texttt{xz} on the executable search path. The reference versions are Lake \texttt{5.0.0-src+819816b}, XZ Utils 5.4.5, and Python 3.12.3 (for the generator and the independent output check). \paragraph{Proof replay and axiom audit.} For a fresh checkout use the commands below. The optional cache step obtains precompiled mathlib artifacts. Keep the checked-in manifest. \begin{verbatim} git clone https://github.com/map9959/grid-graphs.git cd grid-graphs git checkout --detach 6fc87a38777650b7d092b2f0f2fa8a786d3c5db8 cd lean lean --version lake --version lake exe cache get LEAN_NUM_THREADS=4 lake build \ +GridGraphs.Results.SquareFormula:olean lake env lean --stdin <<'LEAN' import GridGraphs.Results.SquareFormula #check GridGraphs.maxPreserved_square_exact #print axioms GridGraphs.maxPreserved_square_exact #eval GridGraphs.squareScore 161 LEAN \end{verbatim} The theorem equates \nolinkurl{GridGraphs.maxPreserved} at \((n,n)\) with \nolinkurl{GridGraphs.squareScore} at \(n\), for every natural \(n>0\). Its transitive \verb|#print axioms| output includes the three standard axioms \verb|propext|, \verb|Classical.choice|, and \verb|Quot.sound|, as well as the axioms generated by \nolinkurl{native_decide} for finite computations (listed with \nolinkurl{_native.native_decide} in their names). It contains no \verb|sorryAx|. The command above prints the complete list for the pinned snapshot; the final line evaluates the formula to \(8791\). \paragraph{Map from the statement to the proof.} In \verb|GridGraphs|, \verb|numPreserved| counts vertices of unchanged degree in a spanning tree of \verb|gridGraph| on \verb|Fin m| $\times$ \verb|Fin n|; \verb|maxPreserved| maximizes this count over spanning trees. \nolinkurl{maxPreserved_eq_maxForcedAcyclic} identifies this maximum with the largest vertex set whose incident grid edges form a forest; \verb|SquareMaskScore| expresses existence at a specified cardinality. \verb|squareScore| evaluates the piecewise formula, and \verb|ExactSquareFormula| asserts its equality with the maximum at every positive side. The file \nolinkurl{GridGraphs/Results/SquareFormulaAssembly.lean} combines the small cases, \nolinkurl{ResidueZero.maxPreserved_three_mul}, \nolinkurl{maxPreserved_residue_one}, and the residue-two bounds. The latter use \nolinkurl{squareScore_lower_residue_two} and \nolinkurl{ResidueTwoUpper.Stencil.upper_of_remaining}, with separate small-side bounds. In \nolinkurl{SquareFormulaFanResidual.lean}, \nolinkurl{exactSquareFormula_of_pending_fans} reduces the outstanding exclusions to failures at listed indices of the same physical forest. In \nolinkurl{ResidueTwoUpper/OneGap/ScoredFanFailure.lean} (relative to \texttt{lean/GridGraphs/}), \nolinkurl{pendingFanIndices_empty} checks that the list left after the geometric reductions and finite cuts is empty. \verb|exactSquareFormula| applies that fact in the final module \nolinkurl{GridGraphs.Results.SquareFormula}, which exports \nolinkurl{maxPreserved_square_exact}. \paragraph{What the certificate replay trusts.} Lean checks the graph-to-certificate reductions and the implications from successful checks. For instance, the side-eight proof checks the stored LRAT refutation using Lean's LRAT checker and its soundness theorem. For the southern-cap coverage, Lake tracks the compressed witness \nolinkurl{SouthCapCoverageAll.xz} and loads the native checker. The file \nolinkurl{lean/SouthCapCertificate.lean} decompresses the checked-in input, replays reverse unit propagation, and invokes \verb|rup_sound| to justify the resulting coverage statement. This component can also be replayed on its own from \texttt{lean/}: \begin{verbatim} LEAN_NUM_THREADS=4 lake build +SouthCapCertificate:olean \end{verbatim} The stored certificates are inputs to the replay; no external SAT or LP solver is needed. The closed propositions discharged by \verb|native_decide| rely on the correctness of Lean's native evaluation and execution environment in addition to kernel checking of the surrounding proof. The Python generator plays no role in this proof replay. \paragraph{Independently checking a generated tree.} From the repository root, run the commands below. The checker reads only the emitted JSON and takes the side and target score independently: here \(161=3\cdot53+2\), with target \(8791\) from the formula. For another side, change both commands and supply its target from the piecewise formula or small-side table. \begin{verbatim} python3 -B generate_square_tree.py 161 > tree.json python3 -E - 161 8791 tree.json <<'PY' import json import sys n, target = map(int, sys.argv[1:3]) with open(sys.argv[3], encoding="utf-8") as file: tree = json.load(file) assert n > 0 and tree["side"] == n adj = {(r, c): set() for r in range(n) for c in range(n)} def vertex(pair): r, c = pair assert type(r) is int and type(c) is int and (r, c) in adj return r, c for a, b in tree["edges"]: u, v = vertex(a), vertex(b) assert abs(u[0] - v[0]) + abs(u[1] - v[1]) == 1 assert v not in adj[u] adj[u].add(v) adj[v].add(u) assert len(tree["edges"]) == n*n - 1 seen, stack = {(0, 0)}, [(0, 0)] while stack: for v in adj[stack.pop()] - seen: seen.add(v) stack.append(v) assert len(seen) == n*n full = {(r, c) for (r, c), nbrs in adj.items() if len(nbrs) == sum((r > 0, r+1 < n, c > 0, c+1 < n))} reported = list(map(vertex, tree["full_degree_vertices"])) assert full == set(reported) assert len(reported) == len(full) == tree["score"] == target print(f"verified side {n}, score {target}") PY \end{verbatim} Connectivity and the distinct-edge count certify that the emitted subgraph is a spanning tree. Its exact full-degree set is recomputed from adjacency, and its optimality follows by comparison with the proved upper bound.