What happens to a recursive call behind an impossible guard?

A bound on solution size cannot guarantee that Table 4.4 finds a solution. Two examples fail at different points. In the first, the induction jump loses an inequality that the caller asks for again on every pass. In the second, the InvarGenT search at revision 16509d9 exhausts its type proposals before reaching the induction jump. Both examples have fixed-size certificates. Arithmetic program · Guarded two-call counterexample

A demand that survives every induction jump

A binary postcondition \(\chi_K(\delta,\delta')\) relates the type of an existential result to the tuple of parameters carried by its package. In climb m t, the result has type \(\mathrm{Num}(r)\) and the parameter tuple carries \(m\). Write \(B_t\) for the band \(m\le r\le m+t\). When the stored relation is \(B_{20}\), projecting the base and recursive suppliers gives \(B_{19}\). The caller requires \(B_{20}\). Both bands satisfy the original clauses. Table 4.4, equations (4.1–4.8) · Exact supplier projection

Here is a recurrence test for this part of the table. Fix the input predicate and the package parameters. Let \(W(R)\) be the supplier summary after the jump and \(D\) the caller demand. Suppose abduction restores \(D\) whenever \(W(R)\) fails to entail it, every supplier justifies the restoration, and the remaining update state repeats. The relation stored by (4.6) is \(W(R)\land D\). If this is \(R\) again and some value satisfies \(W(R)\land\neg D\), induction gives the same relation and a fresh nonempty demand at every later pass. The stopping test observes that demand. Repetition of the stored predicate alone cannot establish convergence. The Lean lemma covers extensional predicate updates. For an implementation that inspects syntax, the repeated representations and auxiliary state also have to be checked. Recurrence and sufficient condition for no renewal

At revision 772b9b4, the common-atom jump on \(B_{20}\) and \(B_{19}\) keeps only \(m\le r\). The caller restores \(r\le m+20\), so the recurrence applies. The current solver keeps the old inequality when the new suppliers entail it. On the same program it needs outer budget 9 and exports \(\forall m.\,\mathrm{Num}(m)\to\mathrm{Nat}\to\exists r[m\le r\le m+20].\,\mathrm{Num}(r)\). Budget 8 still times out. A two-inequality size promise covers the original infinite run’s solution and every band it stores. The table leaves choices to its component routines, so this refutes a guarantee for all such runs. Original pass trace · Current executable checks

Which part of a guarded branch can disappear?

Consider the constructor Pick : ∀i[i≤0]. Num i ⟶ Seed. A client matches Pick n when 1 <= n. Inside the arm it calls a recursive function f on Third Box, opens the returned pair and requires its first component to have type Cargo. The pattern gives \(n\le0\), so the client will never make this call. The previous implementation still tried to accommodate it at every positive outer budget. Original clauses and certificate

Write \(F\) for the other obligations, \(P\) for matching the pattern, \(E\) for checking the guard operands, \(G\) for the guard succeeding, and \(B\) for the body obligations. Suppose \(F\land P\land E\land G\) is impossible independently of \(B\). Then \[ F\land(P\Rightarrow E\land(G\Rightarrow B)) \quad\longleftrightarrow\quad F\land(P\Rightarrow E). \] The equivalence holds on each valuation. It therefore preserves every winning witness strategy under the original quantifier prefix, including strategies that share witnesses across guards. A contradiction that uses \(B\) itself would be circular. For example, the two bodies \(P\Rightarrow x\) and \(P\Rightarrow\neg x\) together force \(\neg P\). Deleting both admits \(P\). Lean proofs for dependent quantifier games

InvarGenT now compares numeric literals and variables bound by the pattern against the constructor facts. An impossible subset of guard comparisons suffices. It still checks and emits the guard operands in their original order. With observed n <= n && 1 <= n, the effectful identity function observed runs once at \(n=0\). Reversing the tests runs it zero times. The old emitter also dropped entire guarded assert false arms, losing this effect on the way to the next arm. The repair keeps the guard and replaces only a proven-unreachable body. Package declarations local to that body disappear with it. The same client can now contain separate calls on both Third Box and First Box. Inference on pass 5 gives exactly the type of the definition in isolation. Moving the guard endpoint from 1 to 0 restores a live call and selects a different type on pass 6. Effect and short-circuit checks · Trace-preserving replacement lemma

The machine representation matters

With native OCaml integers, \(n+1\le n\) holds at max_int. Overflow can also happen before the match. Feed min_int + 1 to fun n -> Pick (n+n) under the input refinement \(n\le0\). The mathematical sum is nonpositive, yet its machine value is 2. A later match on Pick n when 1 <= n must take the arm. With the float backend, converting the integer \(2^{53}+3\) yields the same float as \(2^{53}+4\), making a strict gap disappear even without addition in the source. All three examples execute the selected positive branch. Executable machine-boundary cases

The compiler enables this erasure for the native integer target when the compilation unit contains no source addition or scalar multiplication. Checking the whole unit covers a function that constructs a value later consumed by an earlier definition. A library caller generating annotations for multiple backends retains the bodies by default. As elsewhere in inference, external implementations are assumed to respect their declared types. The restriction leaves opportunities for a more precise analysis of where numeric values originate.

Trying a type that works even if the guard succeeds

Replace the comparison by 1 <= observed n, with observed : ∀i. Num i → Num i. Its type preserves the index. The local erasure test treats the application as opaque. After a type-search failure the solver can try a different question. Can it type the call even if the numeric test succeeds? It removes numeric hypotheses from a recursive call at an external client and from that client’s dependent positive clauses. It retains the quantifier prefix, the conclusions, the recursive suppliers and the final negative checks. More precisely, it selects client rows whose premises contain the original guarded call premise. Removing hypotheses strengthens their implications. A witness strategy solving the stronger obligations also solves the originals with the same witnesses. This costs at most one further invocation of the existing search. Proof for a family of calls

For one call on Third Box, the retry succeeds on pass 6 with \(\forall a.\,\mathrm{Tag}(M,M,a,M)\to\mathrm{Nat}\to\exists().\,(a,a)\), where \(M\) stands for Marker. The emitted OCaml keeps the original body and evaluates observed 0 once. The retry also handles the same test split across an outer constructor match and an inner match on its payload. Generated-code and budget checks

A constant-size solution missed at every positive budget in 16509d9

Put both calls behind 1 <= observed n. Each uses a fresh instance of f, opens the pair, and tests the first component against Box. The normalized guard-evaluation row requires \(i\le0\Rightarrow o=i\land h=o\land l=1\). Every client call, opening and payload-use row contains \(i\le0\land l\le h\). These premises are impossible whenever the guard-evaluation row holds. The definition and its suppliers have exactly the constant-size solution from the one-call example. Interpret the unary predicate as the instances of the displayed arrow type and the binary predicate as the pairs \((a,a)\) carried with parameter tuple \(\langle a\rangle\). Pick \(a=M\) for the initial instance. The third constructor supplies \(a\) directly, and each other constructor forces \(a=M\). Recursion preserves the parameter. Choosing \(o=h=i\) and \(l=1\) respects the guard’s witness dependencies. This verifies the original erased constraints. Writing the third-axis type explicitly while retaining both OCaml call sites still produces a type mismatch at the first-axis call. Guard witnesses and supplier induction in Lean · One-axis certificate · Written and erased controls

There is a structural obstacle to making both calls unconditional. Project a conjunctive free-type pattern to the four input axes and the first output component. Its ground leaves on these examples are fixed constructors or type holes. A domain admitting both marked inputs also admits the all-\(M\) input, by assigning \(M\) to the varying holes. On the all-\(M\), third-marked and first-marked inputs the actual outputs are \(M,C,C\), where \(C\) is Cargo. No fixed constructor has that column. No input axis has it either, since every axis is \(M\) on at least one of the two marked rows. Thus the output has an independent hole. Setting that hole to \(M\) preserves the third-marked input and admits a result its client rejects. This proves the obstruction even for a postcondition allowed to overapproximate the producer. Independent output hole lemma · Pattern classification

For this program, the original and strengthened searches together make 25 pass attempts. Ten pass-0 updates reach the budget comparison. Each leads to a type failure on pass 1. Five further attempts fail on pass 0. No proposal finishes, so the comparison before replaying a finished proposal is unreachable. The final use of the budget to extract an answer is unreachable as well. With the remaining settings fixed, every positive outer budget therefore gives the same finite quantifier violation. Budget zero stops at the first successful update. We compared the complete pass traces at budgets 1 and 10,000. This refutes successful convergence of the search at 16509d9 on size-bounded satisfiable constraints without claiming an infinite run of its repaired arithmetic jump. Instrumentation · Budget sweep and trace check

The remaining opportunity is to use the guard-evaluation row itself to prove that the body cannot run, while retaining the computation that produced the row. A certificate for a false guard can justify a conditional call that no single conjunctive scheme can type unconditionally. A general guarantee from a size promise still requires a search that can reach every bounded certificate, together with a decision procedure for checking each one. Bounded certificate theorem and its hypotheses

A later solver uses the guard-evaluation obligations and checks this two-call program on pass 5. A local helper whose return is itself packaged gives a new constant-size certificate and three failed pass-6 replays. Guard contracts and the second binary postcondition

Reproduction

Run python3 thesis-review-21.py /path/to/InvarGenT.native with a 64-bit OCaml on the path. The optional flags --before and --before-retry take executables at 253cd6b and 18f071c. To reproduce the pass counts, apply the trace patch in a separate checkout, build the executable and pass it as --trace. The driver compiles and executes the fully annotated OCaml for every positive case. Lean 4.19 checks thesis-review-21.lean with the standard library. Build instructions

The InvarGenT commits are 18f071c for preserving guard evaluation, 6c58471 for the stronger caller query and 16509d9 for the machine-arithmetic boundary. The OCaml 5.3 compatibility build ran 318 active tests with 10 existing TODOs. All 155 signatures generated at 253cd6b compared byte for byte with the final build. The budget and runtime driver used OCaml 5.5.1.