Strengthening by unification [01KT]
- April 13, 2026
- Jon Sterling
In my last post, I commented that an important component of a reliable implementation of Epigram-style eliminator-refinement is strengthening. The goal of strengthening is to determine whether a term in a given context is equal to a weakened term, coming from a smaller context.
Can’t we look at free variables? [01KU]
- April 13, 2026
- Jon Sterling
People who, shall we say, have no idea what they are doing tend to think that strengthening is an easy problem to solve: just calculate the set of free variables! (Go grep your favourite proof assistant’s implementation for free variable checks; I’ll wait.)
The problem with this approach is that it is not stable under definitional equivalence: in the simplest case, a dependency can be removed by \beta -reduction. That’s not hard to deal with, of course, but there are still \eta -laws to contend with. You might think that you could contend with the latter by filtering the set of free variables to remove those that are definitional singletons (like the Unit type, or powers thereof). That will also not work, because you need to consider the way the variable is used: for example, x : Unit * Nat is not irrelevant, but it is used irrelevantly in x.pi1.
In the end, if you insist on computing free variable sets for whatever misguided or confused reason, the only non-broken way to do so is to compute it only on the \beta -short \eta -long normal form. But we all know that nobody is doing this…
Maybe we already solved this problem… [01KV]
- April 13, 2026
- Jon Sterling
I think there may be a simpler way to deal with strengthening that takes advantage of all the hard work I put into implementing higher-order nested pattern unification in Project Pterodactyl. Suppose we have a term in context x : A, y : B |- t : T and we want to see if this term can be strengthened into the context x:A. Of course, for this to make any sense, we need to see if the type T can be strengthened away from y : B.
To that end, create a global metavariable ?S : (x : A) -> Type. Now attempt to unify ?S x == T in the current context. If there is a solution, then that solution is the strengthening of T away from y. Once we have done this, we may then create a global metavariable ?s : (x : A) -> ?S x and unify ?s x == t. (Of course, if the first unification resulted in any postponements, we must block or insert a coercion.)
Because higher-order nested pattern unification natively respects \eta -equivalence and definitional singletons, it seems to me that it is the ideal solution to the strengthening problem.