When the guard needs a second recursive postcondition
Two calls behind an effectful guard now typecheck when its helper
returns an ordinary number. At InvarGenT revision 82587e2,
changing one keyword from function to
efunction gives a constant-size solution that joint
inference misses at every outer budget. The change packages the returned
number. Its relation to the input index must now be carried by a second
binary postcondition. Runnable
counterexample · Budget, type and
runtime checks
Two binary postconditions
The client matches a value of type Seed. Its constructor
Pick : ∀i[i≤0]. Num i ⟶ Seed binds a number n
at an index \(i\le0\). The client
computes another number with a local recursive helper.
let rec relay n = efunction
| Z -> observed n
| S d -> relay n dThe primitive observed : ∀i. Num i → Num i counts its
calls and returns its argument. The client opens
relay n (S Z) and tests whether the returned number is at
least 1. Inside that arm it asks a second recursive function
f for a pair, once at Third Box and once at
First Box. Both uses require the first component to have
type Cargo. The guard always fails. Moving the helper to a
preceding top-level definition gives it the inferred type \(\forall
i.\,\mathrm{Num}(i)\to\mathrm{Nat}\to\exists().\,\mathrm{Num}(i)\).
The client then typechecks and the emitted OCaml evaluates
observed once. Complete
program and separately inferred control
Here is a certificate for the joint normalized
clauses. Write \(M\) for
Marker, \(K_1,K_2\) for
the two package constructors and \(\langle
t\rangle\) for a one-element parameter tuple. Interpret the unary
function predicates as the sets of instances of the following arrows.
Interpret the binary predicates as the accompanying payload
relations.
| Function | Admitted arrow | Admitted payload \(u\) at parameter tuple \(s\) |
|---|---|---|
| \(f\) | \(\mathrm{Tag}(M,M,a,M)\to\mathrm{Nat}\to K_1(\langle a\rangle)\) | \(s=\langle a\rangle\land u=(a,a)\) for some \(a\) |
| \(\mathrm{relay}\) | \(\mathrm{Num}(i)\to\mathrm{Nat}\to K_2(\langle\mathrm{Num}(i)\rangle)\) | \(s=\langle\mathrm{Num}(i)\rangle\land u=\mathrm{Num}(i)\) for some \(i\) |
Choose \(a=M\) and \(i=0\) for the initial existence
obligations. At each definition choose the package parameter from its
input. For \(f\), the third constructor
supplies \(a\) directly and each other
constructor forces \(a=M\). The
successor keeps the parameter and repacks the pair. For
relay, the base receives \(\mathrm{Num}(i)\) from
observed. The successor instantiates the recursive arrow at
the same \(i\), opens its result and
repacks it at the same parameter. At the client, the Pick
index is already in scope when choosing the helper instance. Opening its
package therefore gives \(r=i\). Every
subsequent call or opening in the guarded arm requires \(i\le0\land 1\le r\). All four predicates
have fixed total description length. Four-axis supplier proof · Package certificate and broader supplier
model
The implemented search finishes a producer proposal on pass 5. Reintroducing the clients fails on pass 6. At budgets 0 through 4 a pass hits the budget comparison. At budget 5 the proposal finishes, then the check before replay stops it. For every budget of at least 6 the full search makes 28 pass attempts, including three failed pass-6 replays. No successful update advances past pass 5. The pass-6 failures occur before the budget comparison, and the final answer-extraction code is never reached. This accounts for every outer budget with all other settings at their defaults. The complete event and discard traces at 6 and 10,000 agree. A single jointly checked marked call succeeds. Instrumentation · Reproduction
A subsequent revision checks this package relation against an explicit negative obligation on the client. Its retry succeeds on pass 5 as soon as the original search has enough budget to reach a failure on pass 6. Joint exclusion and the least producer relation
The original common-atom induction jump can renew the same numeric demand forever. This newer example exhausts a finite search. Its two-inequality predecessor and its four-predicate certificate both rule out a completeness guarantee for those concrete updates based solely on a polynomial size promise. A fair enumeration with a decidable certificate checker has a different progress argument. Original infinite recurrence · Bounded search theorem
What an ordinary helper already tells the guard
With function in the helper, the normalized definition
includes \(X(t)\Rightarrow\exists k.\
t=\mathrm{Num}(k)\to\mathrm{Nat}\to\mathrm{Num}(k)\) among its
consequences. The base arm justifies the result index. The actual call
supplies \(X(\mathrm{Num}(i)\to\mathrm{Nat}\to\mathrm{Num}(r))\).
Injectivity gives \(r=i\) for
every interpretation that satisfies the definition and
admits this call. The interpretation may admit only a few input indices.
Membership at this particular call is enough. With both marked calls,
InvarGenT now uses this fact and finishes the retry on pass 5. Specialization lemma and program checks
· Driver
To obtain such a contract, inference collects unconditional first-order observations from the definition. If the collected type equations already prove the constructor premise of an arm, it can also use that arm’s consequences. It projects the result onto the function type and keeps equations for captured variables. Each use instantiates local witnesses afresh. No proposed solution for the helper predicate is needed. The original definition, guard operands and negative clauses still go through inference. A helper that returns 1 in the base case leaves the marked calls live and the program is rejected.
For a packaged return, the supplier obliges the binary relation to contain the base result and the results repacked by successors. On this example both \(R(i,r)\equiv r=i\) and \(R(i,r)\equiv\top\) satisfy those supplier obligations. The second interpretation admits \(r=1\) even at \(i=0\). The client needs the more precise relation. Using a relation merely because it covers the producers would lose this distinction. A proof that fixes the exact relation and checks both its defining branches and its clients could close this remaining loop. Two supplier interpretations
A witness inside an opening
A safe guard certificate must cover every returning evaluation that can reach the test. If reaching state \(s\) guarantees some local witness \(w\) satisfying \(O(s,w)\), then infeasibility of \(O(s,w)\land G(s)\) proves that the guard cannot succeed. Two observations compose when the second provides a witness for the very state and first witness already chosen. Sharing the input state preserves correlations. Separate polymorphic calls may still need different instantiations. When the projection is exact, the infeasibility criterion is also necessary. Coverage, composition and exact-image lemmas
For example, give seal the type \(\forall i.\,\mathrm{Num}(i)\to\exists j[j\le
i].\,\mathrm{Num}(j)\). In
let k = seal n in match k with r when 1 <= r -> …,
entry into the body supplies the actual witness \(j\le i\). With \(i\le0\) the guard is impossible. Widen the
package guarantee to \(j\le i+1\) and
the declared contract admits 1 at zero. The implementation keeps the
calls in that case. For an ordinary let whose RHS has a known
non-package head, the universally quantified binding equation can be
specialized at the RHS type itself. This recovers equalities across
aliases and nested lets. Earlier guard facts enter the body only after
the earlier guard succeeds. Opening
proof · Executed guard and boundary
cases
Moving the package opening inside the numeric operand
changes the typing question. In
1 <= (let k = seal n in k) the operand has to provide a
singleton index chosen before the hidden \(j\). Even with the arm replaced by
True, inference rejects this example. The required \(\exists r.\forall j\le i.\ r=j\) fails at
\(j=i\) and \(j=i-1\). A comparison made inside the
opening can choose its operand index after observing \(j\). Witness-order proof
More generally, preserving satisfiability after erasure can require only one legal witness strategy that avoids the guard on every play. Preserving every strategy for every possible body requires every legal strategy to avoid it. An existential Boolean choice that can take either value separates the two conditions. For operational erasure the compiler must cover the returning executions. It retains the original guards, including effects and short-circuit order. The existing native-integer and arithmetic restrictions still apply. Strategy equivalences · Machine-arithmetic boundary
Why the solver retries after failure
Erasing the impossible arm eagerly produced the definition-alone
scheme \(\forall
a,b.\,\mathrm{Tag}(a,b,b,b)\to\mathrm{Nat}\to\exists().\,(a,a)\).
The existing one-call program instead exported \(\forall
a.\,\mathrm{Tag}(M,M,a,M)\to\mathrm{Nat}\to\exists().\,(a,a)\). A
later top-level Third Box call typechecked against the
second scheme and failed against the first. Both schemes type the same
implementation. To preserve every previously accepted one-call client, a
replacement interface must include every previously admissible client
instantiation. An instantiation includes the demanded result as well as
the input. A singleton client witnesses necessity. InvarGenT
consequently keeps a successful inference and tries the additional
certificates only after failure. It respects exhaustion of the outer
budget. Interface criterion · Previously accepted downstream caller
There is an exact lower bound for the family with \(d\ge2\) axes. Consider clients that mark
one axis with Cargo and require a Cargo
result. A single conjunctive free-type pattern can serve at most one of
these clients. If its domain admits two distinct marked rows, it also
admits the all-\(M\) row by filling the
varying holes with \(M\). Soundness for
the producer requires an \(M\) output
there. The output is therefore a hole. No input coordinate can share it,
since each coordinate is \(M\) on at
least one of the two marked rows, where the actual output is
Cargo. Setting the independent output hole to \(M\) at either marked input violates the
client. Consequently the map from marked axes to supporting exported
schemes must be injective. One scheme fixing every other axis at \(M\) attains the bound. This explains why
changing a valid inferred scheme can break a later caller even with
unlimited search time. Arbitrary-axis
proof and matching construction
A discard that sent inference back to pass 0
There was a second obstacle with a local ordinary helper. At revision
16509d9, pass 0 proposed a type, pass 1 rejected it, and
the solver added a type substitution to the list of answers to discard.
It then retried pass 0. I stopped an instrumented run after 64
identical discards. Its outer budget was 1. Each of the 64
pass-1 failures happened before the budget comparison. Adding a second
copy of an existing discard cannot change an existential membership test
on that list. These observations expose ineffective retries without
assuming an infinite execution from a finite trace. Trace probe · Duplicate-discard lemma
The term abducer replaces arithmetic and order leaves with fresh variables on its first pass. When inference records a rejected proposal it restores the original side terms. The old structural comparator recognized two side variables and two wrapped side terms, but missed a variable paired with a wrapped term of its own sort. It could also equate leaves of different sorts. The repaired comparison keeps the identity of each type variable, the constructor and its arity, the arrow positions, and the sort of each side leaf. Changing only a side leaf’s representation preserves this shape. The one-call program with a local recursive helper now succeeds on pass 6. This comparison applies to the term phase that abstracts the side leaves. Numeric abduction retains its own entailment tests. Shape lemma · Successful one-call case
Reproduction
Run
python3 thesis-review-22.py /path/to/InvarGenT.native with
OCaml on the path. Pass --before for an ordinary executable
at 16509d9. To check the traces, apply the supplied patch
in separate build checkouts and pass their executables as
--trace and --old-trace. The old trace
deliberately exits once it has recorded 64 discards. The
--trace executable at 82587e2 runs to its own
outcome. Use --before-joint with the ordinary executable at
that revision to reproduce its original budget sweep. Positive examples
compile with full annotations and execute the resulting OCaml. Lean 4.19
checks the proof file using the standard library. Driver · Proofs · Compiler build notes
InvarGenT commits b3c9681, 7eb6e19 and
82587e2 implement the guard retry, the discard comparison
and the local helper contract respectively. The full suite passed all
323 active tests, with 10 existing TODOs. Of the 158 previous example
interfaces, 157 reproduced byte for byte. The remaining interface gained
the new downstream test declaration and retained its previous text
verbatim.