What can every typing of one recursive call tell its consumer?

One recursive call can have many typings of the same runtime arguments. Every terminating result must satisfy the result package of each admitted typing. InvarGenT now checks this condition over the whole rational tuple of package indices. The compiler accepts the example that needs to move \((k,j)\) from \((0,0)\) to \((n,n)\) with a two-pass budget. The preceding revision still rejected it at budget 10,000. At odd input widths a second program needs a fractional type index. Both programs compile and execute with native OCaml integers. Tied indices · Fractional index · Previous obstruction

The complete guard check for a fixed scheme

Fix the numeric coordinates \(x\) of the runtime argument types. Let \(A(x,z)\) say that the written and inferred domains both admit the arrow with package coordinates \(z\). It is the intersection of their projections onto the full arrow. Let \(P(x,z,r,w)\) be the facts from opening that package at payload \(r\) with private witnesses \(w\). Write \(B(x,r)\) for the facts already available from the ordinary call, with its original typing and witnesses in scope. A guard \(G\) is excluded by the rational package information exactly when the following formula has no model.

\[ B(x,r)\land G(x,r)\land \forall z.\bigl(A(x,z)\Rightarrow\exists w.\ P(x,z,r,w)\bigr). \]

Soundness. A real execution reaching the guard gives the original observation. At every admitted tuple the recursive typing supplies a witness for that same result. This would give a model. Completeness for these facts. A model permits the observation under every admitted typing. Every probe chosen from the input, the result, or facts from earlier openings draws on one of those typings. Repeating such openings cannot eliminate the model. The next predicate update in Table 4.4 can still change the scheme itself. All-probes lemma · Arrow admission · Table 4.4

This check is invariant under changes of numeric coordinates that cover all admitted typings and preserve their sets of possible results. Several new tuples may describe the same old typing. For each old tuple choose a preimage to recover its package, and apply the forward map for the converse. The implementation invokes this test for recognized numeric guard bands on a recursive call with a written scheme and a single numeric payload. It can decline a check if a computed coefficient exceeds its term representation. The checker keeps all argument coordinates fixed, including a sum appearing as one argument index. Only the return package coordinates range over \(z\). Change-of-coordinates theorem · Compound argument example

A refuting tuple and a strict boundary

Project \(w\) out of \(P\) first. A tuple refutes \(r\) when \(A\) holds there and every cell of the projected package fails. Project \(z\) out of that refutation. The remaining question is whether an observation in \(B\land G\) lies outside every projected refutation. InvarGenT uses its existing rational equality and inequality solver for the projections. A finite conjunction of strict comparisons uses a shared positive slack \(d\), chosen separately at each observation. Tuple checker and arithmetic oracle · Strict comparisons in the finite check

The order of these choices matters. Let \(0\le x\le1\) and admit \(0\le k\le x\), with an additional key \(k=2\) at \(x=0\). Suppose the package requires \(k\le0\). Every observation has a refuting key. For \(x>0\) choose \(k=x\), and for \(x=0\) choose 2. No single positive margin works at all observations, since the positive values of \(x\) approach zero.

At a fixed observation the refutation with margin \(d\) persists when \(d\) decreases toward zero. Projection preserves that property for the union of cells. For a row \(u+cd>0\), its eventual truth as \(d\downarrow0\) is \(u\ge0\) if \(c>0\), and \(u>0\) if \(c\le0\). Take a common threshold for the finitely many rows before deciding their Boolean combination. This gives the exact complement of the projected refutations, including their boundaries. The compiler prunes a branch when its constraints already preclude positive slack under the guard. Sign and finite-threshold lemmas · Boundary, empty-domain and private-witness checks

The search can stop as soon as one projected refutation covers the guard. When several refutations matter, the search visits regions left over after excluding earlier cells. If a region and the next cell are disjoint at every positive slack, the search can skip that cell. An observation in the region persists as its slack shrinks. If it belonged to the limiting cell, the two would meet at sufficiently small positive slack. The argument needs neither a uniform margin nor a bound on the size of the recursive solution. The finite product of possible failed rows can still be large. On arithmetic problem 548 the first projected refutation covers the guard. An instrumented eager search visited 25,800 cases before interruption. The new search projects one and returns the same answer as Z3. Disjoint-cell lemma

There is also a constructive statement about possible probes. Every fixed finite rational-linear formula of this kind admits a finite family of rational-affine tuple expressions covering all refutable observations. Expand its refutation into linear cases, including open inequalities. Eliminate the tuple coordinates in one case. When reconstructing a witness, choose the midpoint of its greatest lower and least upper bounds if both exist. If they coincide, feasibility makes that endpoint legal. With only lower bounds choose their maximum plus one, with only upper bounds their minimum minus one, and with no bounds choose zero. Solved equalities give their unique values. On each choice of active bounds these expressions are rational-affine. There are finitely many choices, and back-substitution preserves affinity on each resulting region. The implemented projection checks coverage without constructing this family. One-coordinate reconstruction

An integer result needs a rational typing

Rescale the old key in the flag program to \(2k\). At flag one the admitted range is \(0\le 2k\le n\). The package permits a payload \(r\) if \(2k+r\le n\) or \(n+2\le2k+r\), along with \(0\le r\le f\). At the guard \(f=r=1\), so the refuting tuples satisfy \(n-1<2k<n+1\). Key \(n/2\) works for every \(n\ge2\). At odd \(n\), no integer \(k\) can satisfy the two strict inequalities. Even a collection containing every integral key would leave the guard feasible at width five. The compiler now retains the full rescaled scheme, and running the program at widths four and five prints zero twice. The thesis assigns the numeric type variables to rational arithmetic. Program · Odd-width proof · Numeric sort in the thesis

Two affine tuple expressions are sometimes necessary

Let the observed offset satisfy \(-2n\le s\le0\). Give the result package another visible parameter \(j=\max(0,k+s)\) and a bound \(r\le j+2\). The flag-one guard again needs a key \(n-1<k\le n\). Two tuple expressions suffice. Use \((n,0)\) when \(s\le-n\), and \((n,n+s)\) when \(s\ge-n\). The exported type retains the entire offset range. The compiled example visits both sides and their shared endpoint. Program · Exported type and four executions

One rational-affine tuple expression cannot certify this guard on all inputs. Fix \(f=r=1\), \(n\ge2\) and the ordinary tuple \((0,0)\), which permits this result at every offset. At \(s=-2n\) and \(s=-n\), every admitted refutation has \(j=0\). At \(s=0\), every refutation has \(j=k>0\). An affine expression in \(s\) that vanishes at the first two offsets also vanishes at the third. Clearing the denominators gives the same argument for rational coefficients. This is a sharp lower bound for affine proposals in the original observations. Two proposals and the three-offset obstruction

How many affine proposals can a small package require?

Give the call \(d\ge1\) independent integer offsets \(s_i\in[-2n,0]\). Add one visible coordinate \(j_i=\max(0,k+s_i)\) and one package bound \(r\le j_i+2\) per offset. The number of coordinates and atoms grows linearly with \(d\). The one-equation result \(r=0\) still solves the recursive example. To exclude the guard using the written package, exactly \(2^d\) rational-affine full-tuple proposals in the original observations suffice and can be necessary. A single expression using \(d\) maxima suffices if maxima are allowed.

Upper bound. Use \(k=n\). For each coordinate choose either zero or \(n+s_i\). The \(2^d\) combinations include the admitted tuple at every offset. Its package excludes \(r=1\).

Lower bound using only integer observations. Fix the ordinary observation \(f=r=1\) and \((k,j_1,\ldots,j_d)=0\). Fix even the width, taking \(n=2^d+1\) and \(L=n-1\). For each coordinate choose a grid of \(L\) cold offsets in \([-2n,-n-1]\) or all \(L\) hot offsets in \([2-n,0]\). This gives \(2^d\) grids of \(L^d\) input tuples. Any refuting typing needs \(n-1<k\le n\). Its \(j_i\) is zero on a cold axis and strictly positive on a hot axis.

Suppose fewer than \(L\) affine proposals cover every input. In each grid some proposal covers more than \(L^{d-1}\) points, since otherwise their union is too small. A nonzero affine row vanishes at most \(L^{d-1}\) times on a grid. For a nonconstant row, fix all coordinates except one with nonzero coefficient. There is at most one root on each of the \(L^{d-1}\) resulting lines. A nonzero constant has no roots. Hence every cold coordinate of the selected proposal is identically zero as a function of the offsets at this width. Every hot coordinate is nonzero somewhere. These identically zero rows identify the grid’s hot/cold pattern uniquely. Distinct patterns therefore need distinct proposals, which gives the contradiction. The argument also allows the proposed \(k\) to depend on all the offsets. The unbounded family uses mathematical integers. At \(d=2\), width five suffices for all four grids. Grid-counting and affine-root lemmas

The bound concerns flattening the admissible tuples into a list of affine expressions. The linear-size graph with its original maxima is also a certificate. The refutation procedure above can use this graph directly. In dimensions one through four, Z3 checks coverage of the affine proposals on all rational offsets. InvarGenT’s arithmetic checker retains zero and excludes one directly from each graph. Coverage replay

The isolated two-offset definition compiles with budget two. Its exported domain selects \(f=1\) and retains every written offset and key there. The public package has both hinge bounds. At width five a separate OCaml caller ran the generated function at all 121 integer offset pairs in \([-10,0]^2\) and obtained zero each time. Flag zero also has a valid typing in the written scheme. The source-level inference still has to choose the domain on which the guard certificate runs. Two-offset definition · Signature comparison and native grid

What the quantifiers protect

At flag one, a function returning the flag can reach a guard for positive results. The correct checker rejects its Boolean guarded arm. A mutant quantifies the input slots too, which lets the checker use the zero result at flag zero to rule out a result at flag one. Another version of the program carries a private witness \(m\) with \(r=m+k\). Each key \(k\) admits its own \(m=r-k\). A second mutant shares these witnesses across all keys. Both mutants accept their respective programs and reach the compiler-generated assertion at the erased arm. Fixed-input program · Mutations and assertion locations

The rational closure also identifies a limit of the native-integer analysis. A seed package permits \(0\le r\), \(2r\le3\) and \(r\le0\lor3\le2r\). Its rational results are \(0\) and \(3/2\). Its only integer result is zero. At flag two, \(3/2\) remains possible under every rational typing and lies in the guard \(1\le r\le2\). Revision ea0cf2c rejected the Boolean arm. The later native guard checker uses integrality of the actual payload and accepts this program. The phantom key in the width-five example can take fractional values, while the returned native integer here has a stronger interpretation. Seed program · Integer proof · Mixed native decision

Where candidate inference can still stop

Change the package to require \(0\le r\le f\) and \(\min(k+r-n,n-k)\le0\). The base case and the numeric recursive arm both return zero. At \(r=0\) the package asks for \(\min(k-n,n-k)\le0\), which holds at every key. At the guarded observation \(f=r=1\), any key strictly between \(n-1\) and \(n\) refutes the package. For example \(k=n-1/2\) is admitted for every \(n\ge2\). These two facts give a supplier and a guard certificate for the written scheme. Executable variants

Even with the annotation \(r=0\), revision 4785b90 failed during supplier abduction. Its equality solver substituted zero and left both opposing arms in the abduction problem. InvarGenT now discards a disjunction \(u\le0\lor v\le0\) when positive weights \(a,b\) give a constant \(au+bv\le0\). If both arms were positive their weighted sum would be positive. The compiler accepts the annotated program with budget two, and it prints zero twice. Removing just \(r=0\) still produced a type mismatch at revision ea0cf2c. A later comparison isolated the joint inference of the definition and its attached clients. Carrying unconditional numeric consequences into guarded premises now lets this example reach the guard check at iteration two. Opposing-arms lemma · Historical replay · Client comparison and repair

Reproducing the checks

InvarGenT revisions 4785b90, a810765 and ea0cf2c implement tuple checking, the opposing-arm simplification and the coverage pruning respectively. At the last revision the OCaml 5.3 compatibility build passed all 367 active suite cases, with ten recorded as TODO. All 186 previous example signatures were byte-identical. Run Lean 4.19 on the proof file. With OCaml and Python’s z3-solver available, run python3 thesis-review-39.py /path/to/InvarGenT.native --interior --double-hinge. The replay compares the exported domains and packages over both integer and real coordinates and runs the generated OCaml. The optional --before takes the compiler at e3b1348. For --trace, build a copy with the iteration trace and the tuple trace.

To check the arithmetic separately, copy the OCaml driver to src/JointOracle.ml, build its native target alongside InvarGenT, and pass the executable as --numeric-driver. The driver uses the compiler’s numeric solver. Of the 780 arithmetic checks, 768 compare the answers with independently quantified formulas in Z3 and 12 fix expected boundary cases. They include fractional coefficients, empty fibres, private witnesses and disjunctive packages. Add --problem 548 to print and check that input. Building the driver with the tuple trace also prints its projection count.