When does a recursive guard have a finite certificate?
Fix the numeric inputs of a recursive call. If no result in a closed, bounded guard satisfies every admitted typing, finitely many rational typings already exclude the guard. The number needed can grow without bound as the input varies, even when the input, key and guarded result all stay in \([0,1]\). For a native integer payload the same example needs at most two keys. Topological and counting proofs · Previous sharp count at unbounded widths
Finite certificates at one input
Let \(x\) contain the input coordinates and any surrounding parameters shared by the admission and package. Let \(A(x,k)\) admit a tuple of package indices. Write \(B(x,k,r)\) for the result package after existentially projecting its private witnesses, and \(G(x,r)\) for the possible guarded observations before further openings. A key refutes an observation when \(A(x,k)\land\neg B(x,k,r)\). One execution has to satisfy the package at every admitted key. Quantifiers for recursive typings
The thesis’s weak linear inequalities, equations and extrema describe finite unions of closed rational polyhedra. Projecting private witnesses preserves this property. In each linear cell Fourier–Motzkin elimination pairs lower and upper bounds with weak inequalities. The projected package \(B\) is therefore closed jointly in \((x,k,r)\). Its complement is open. Projection in InvarGenT · Fourier–Motzkin elimination
Finite-certificate theorem. Fix a rational input \(x\). Suppose the real interpretation of \(G_x\) is closed and bounded and every rational guarded result has an admitted rational refuting key. Then a single finite set of admitted rational keys refutes the whole guard, including its real interpretation.
The quantified exclusion statement is first-order linear arithmetic with rational coefficients once \(x\) is fixed. Elimination gives the same truth value over the rationals and the reals, so every real guarded result has a real refuting key. Keep the result fixed. Refutation persists in a neighborhood of that key since \(B\) is closed. The admission cell at this input is a rational polyhedron, and rational points are dense in it, also on a lower-dimensional face. To see density, intersect the cell with any open rational box containing the real point. The feasible rational linear system has a rational solution. Thus some admitted rational key refutes the real result and an open neighborhood of results. These neighborhoods cover the compact real guard. A finite subcover gives the desired keys. Taking the real interpretation matters here. A closed bounded interval of rational points can fail to be compact. Finite-subcover proof · Heine–Borel theorem
There is a terminating construction for a bounded scalar guard. Check the all-keys formula first to detect a surviving result. For an excluded guard, enclose it in a rational interval. At each node discard an empty piece, or solve for one admitted rational key that refutes every guard result in that piece. Bisect any other piece. A finite open subcover has a positive Lebesgue number on the compact guard, so sufficiently short intervals all pass the one-key test. The replay constructs certificates and checks admission and coverage again on the original formulas. At radius \(1/16\) in the example below, bisection returns 16 keys and the optimum is nine. Certificate construction
Both hypotheses on the guard matter. The open guard \(0<r\le1\) in the interior-key example admits no finite certificate. For an unbounded closed guard \(r\ge0\), admit \(k\ge0\) and let the package require \(r\le-1\) or \(k+1\le r\). Key \(k=r\) refutes every guarded result. Any finite sample still permits all sufficiently large results. A supplier returning \(-1\) satisfies every typing. Bounded open-guard example
A uniform bound when admission varies continuously from below
Now let \(x\) vary in the real interpretation. Assume the joint guard \(G\subseteq X\times R\) is compact. Give the legal input domain \(X\) its relative topology. For an open key neighborhood \(W\), define its set of inputs by \(H_W=\{x\mid A_x\cap W\ne\varnothing\}\). Admission is lower hemicontinuous if each \(H_W\) is open. Informally, a key admitted at an input can be approximated by admitted keys at every sufficiently nearby input.
Uniform-certificate theorem. If admission is lower hemicontinuous, the package is jointly closed, and every guarded point has a refutation, a finite family of partial choices \(k_j(x)\) covers the joint guard. Each choice depends only on the input. Whenever it returns a key, that key is admitted.
For each guarded pair \((x,r)\) pick a refuting \(k\). Openness gives a product \(U\times W\) around \(((x,r),k)\) on which the package fails. Intersect \(U\) with the observations whose input lies in \(H_W\). This is an open neighborhood of \((x,r)\). Select one key from \(A_{x'}\cap W\) for each \(x'\in H_W\). The same selection works for every result in the neighborhood at \(x'\). A finite subcover of the joint guard now yields finitely many such selections. A key equal to \(x'\) may have to move with the input. The proof keeps the result out of the selection. Machine-checked uniform theorem
For rational-linear data the neighborhoods above can use boxes with rational endpoints. The test \(A_x\cap W\ne\varnothing\) is rational-linear, and a key there can be selected piecewise rational-affinely in \(x\) by reconstructing the eliminated coordinates. This gives input-only expressions on their regions of admission. For a prescribed positive bound \(t\), there is a direct arithmetic check. For each input with a nonempty guard, ask for \(t\) admitted keys such that every guarded result fails at least one of their packages. Repetition pads a smaller nonempty certificate. The order is \(\forall x\,\exists k_1\ldots k_t\,\forall r\). Eliminate private witnesses separately in each package. If the uniform theorem applies, increasing \(t\) from one eventually succeeds. Piecewise-affine selection
One frequent admission relation satisfies the continuity hypothesis. Let \(A\) be a single convex polyhedron, and \(X\) its input projection. Fix \((x_0,k_0)\in A\) and a small open box \(W\) about \(k_0\). Suppose inputs outside \(H_W\) accumulate at \(x_0\). Their set is semilinear by elimination, so some one of its finitely many convex linear cells has \(x_0\) in its closure. Choose \(x_1\) in that cell and any \(k_1\in A_{x_1}\). Every point strictly between \(x_0\) and \(x_1\) belongs to the bad cell. Its strict inequalities hold at \(x_1\) and hold weakly at \(x_0\). Convexity of \(A\) admits the interpolated keys on that segment. Near \(x_0\) those keys lie in \(W\), a contradiction. The argument extends to a finite union of such cells when each has the same input projection.
Unbounded counts inside a unit box
Let \(0\le x\le1\). Admit ordinary keys \(0\le k\le1\), and admit an extra key \(k=3\) exactly when \(x=0\). The package is \[ -1\le r\le1,\qquad (r=-1\lor0\le r),\qquad (r+x\le k\lor k+x\le r),\qquad (k\le1\lor r\le-1). \] A supplier can always return \(-1\). The guard is the compact square \(0\le x,r\le1\). At \(x>0\) the admitted key \(k=r\) refutes every guarded result. At \(x=0\) the extra key refutes the entire guard. The common result set is \(\{-1\}\) at every input. The extra key is isolated and disappears at every positive input. To put every key in \([0,1]\), use the coordinate \(h=k/3\) and substitute \(3h\) for \(k\) throughout. This bijection preserves exactly which observations each key refutes.
At \(x=1/n\), an ordinary key refutes the open interval \((k-1/n,k+1/n)\). Multiplying the result and key by \(n\) reduces this to radius one on \([0,n]\). Exactly \(\lfloor n/2\rfloor+1\) keys are needed. In particular, against any proposed bound \(t\ge1\), choose \(x=1/(2t)\). Among the \(t+1\) marks \(0,1/t,\ldots,1\), any one key refutes at most one. This defeats arbitrary input-only selection rules, including nonlinear choices. The admission graph is closed and bounded. It fails lower hemicontinuity at the extra key. The reciprocal inputs are legal because the thesis interprets the type coordinate \(x\) over the rationals. Scaled obstruction in Lean · Matching midpoint construction · Compiler arithmetic checks
For an integer payload the same bounded guard has just two observations, zero and one. At \(x>0\) choose keys zero and one. Both are needed for \(x\le1/2\), since an open interval of radius at most \(1/2\) cannot contain both endpoints. For \(x>1/2\) the midpoint alone suffices. At zero the extra key suffices. More generally, if at most \(M\) distinct native results occur anywhere in the guard, one refuting key per possible result gives a uniform per-input bound \(M\) with no continuity assumption. The certificate can be chosen before seeing which value the call returns. Finite-observation proof
The native value has an integer index
A seed package allows \(r=0\) or
\(r=3/2\). A recursive function returns
that seed at depth zero and tests \(1\le r\le
f\) on its child’s result. InvarGenT at f11480e
rejected a Boolean expression in the guarded arm because \(3/2\) is a rational countermodel at flag
two. On a native OCaml int target, only zero can actually
arrive. InvarGenT revision 581f479 accepts the program with
iteration budget two and preserves the declared rational package. The
generated program prints zero. On a float target a seed returning \(1.5\) reaches the arm. A second native seed
allowing zero and two also reaches it. Both Boolean arms are rejected. A
numeric replacement prints the observed values \(1.5\) and \(2\) inside the guards. Source · Schemes, controls and executions
The all-typings checker already projects rational tuple coordinates and private witnesses. Its remaining uncovered regions describe the possible original observations with a shared positive slack \(d\) for strict inequalities. At any such leaf, a fixed feasible observation remains feasible as \(d\) decreases toward zero. For a native guard introduce one fresh coordinate \(p\) equal to the term indexing the observed payload. Project everything except \(p,d\) from that leaf. The projected formula is a finite union of linear cells. A fixed \(p\) survives at some positive slack exactly when some cell holds for all sufficiently small positive \(d\). In one direction, downward closure gives arbitrarily small feasible slack at the same \(p\), and each of the finitely many linear cells has an eventual truth value. In the other direction, any sufficiently small positive slack gives a witness. Slack and finite-threshold lemmas
A row \(ap+bd+c\le0\) then requires \(ap+c<0\) when \(b>0\) and \(ap+c\le0\) otherwise. In a strict row clear the rational denominators of \(a,c\) by a positive multiple. For integral \(p\), the resulting integer-valued expression must be at most \(-1\). Rounding the lower and upper bounds tests interval feasibility, including open endpoints, unbounded intervals and singletons. Split the remaining extremum alternatives and accept a leaf if any resulting interval contains an integer. This computes the exact mixed test for one designated integral term when the projections fit the compiler’s coefficient representation. Keys and private witnesses still range over the rationals. If that term is \(2l\), the observation \(l=1/2\) supplies the native value one. Arithmetic driver · Differential replay
The new check assumes integrality only of the observed value. A relation \(i+r=1/2\) with \(i,r\in[0,1]\) illustrates the next boundary if both coordinates arise from native values. Requiring \(r\) integral allows \((1/2,0)\), and requiring \(i\) integral allows \((0,1/2)\). Requiring both simultaneously excludes the whole relation. The finite-certificate theorems and mixed decision each concern one candidate recursive scheme. Table 4.4 can still change that scheme on its next update. Predicate iteration and the induction jump · Which inputs a changing interface must retain
Reproducing the checks
Use Lean 4.19 and mathlib v4.19.0 to run
lake env lean thesis-review-41.lean. The file proves the
compact-cover implications, the finite-result bound and the obstruction
for arbitrarily many keys at reciprocal inputs. The rational-to-real
transfer and the polyhedral continuity argument are proved above. With
Python’s z3-solver, run
python3 thesis-review-41.py to synthesize and recheck
finite certificates. Add
--compiler /path/to/InvarGenT.native for the native and
float programs and --before with the compiler at
f11480e for the earlier failure. To replay the arithmetic
checks, copy the numeric
driver to src/NativeOracle.ml in an InvarGenT build at
581f479. Build the src/NativeOracle.native
target with the same ocamlbuild options as the compiler. Pass the
resulting executable as --driver for the 244 boundary cases
and 44 cases from the compact family.
The separate --stress option adds 480 seeded formulas
with up to two private witnesses. Its oracle eliminates rational keys
and witnesses in Z3, then checks both rational payloads and an integral
observed term. Add --case-timeout 2 to try each compiler
query for up to two seconds and report the numbers of all unfinished
queries. On the OCaml 5.5 compatibility build of 581f479,
472 cases agreed on both answers. Cases 170, 185, 224, 258, 282, 359,
374 and 426 exceeded that limit and remain unverified in this
comparison. The OCaml 5.3 regression suite passed all 371 active cases,
with ten recorded as TODO. All 190 earlier example signatures were
byte-identical.