Nonuniform Coercions via Unification Hints
We introduce the notion of nonuniform coercion, which is the promotion of a value of one type to an enriched value of a different type via a nonuniform procedure. Nonuniform coercions are a generalization of the (uniform) coercions known in the literature and they arise naturally when formalizing mathematics in an higher order interactive theorem prover using convenient devices like canonical structures, type classes or unification hints. We also show how nonuniform coercions can be naturally implemented at the user level in an interactive theorem prover that allows unification hints.
💡 Research Summary
The paper introduces the concept of non‑uniform coercion, a generalisation of the traditional (uniform) coercion mechanism used in interactive theorem provers (ITPs). While a uniform coercion is a single function that converts any term of a source type into a target type in the same way, a non‑uniform coercion may apply different conversion procedures depending on the syntactic or semantic shape of the term being coerced. This flexibility mirrors many informal mathematical practices where, for instance, the promotion of a natural number to a group element is handled differently for zero and for positive numbers, or where an empty list is mapped to the monoid unit while a non‑empty list is mapped via concatenation.
The authors formalise non‑uniform coercions as a family of conversion rules indexed by source‑target type pairs together with pattern‑matching conditions on the source term. The central technical device that makes such rules usable in an ITP is unification hints (also called unification hints or hint‑based unification). A unification hint is a user‑provided clause that, when the unifier encounters a particular goal of the form “convert ?x : A to B”, can inspect the structure of ?x, choose an appropriate conversion term, and supply the necessary substitution. By declaring a set of hints for a given source‑target pair, the prover can automatically select the right conversion function on a per‑term basis, effectively implementing non‑uniform coercions at the user level without modifying the kernel.
From a meta‑theoretical standpoint, the paper proves that adding non‑uniform coercions via unification hints preserves the essential properties of the underlying type theory. The authors impose two mild restrictions on hints: (1) normalisation preservation, ensuring that applying a hint does not introduce new redexes that could affect reduction behaviour, and (2) decidability of hint selection, guaranteeing that the unifier’s search for a matching hint always terminates. Under these conditions they establish a coherence theorem: any two derivations that convert the same term from A to B using possibly different hints produce definitionally equal results. Consequently, the extended system remains sound, complete with respect to the original typing judgments, and retains the decidability of type inference.
Implementation is demonstrated on the Coq proof assistant, which already supports canonical structures, type classes, and unification hints. The authors encode several illustrative examples:
- Nat → Group: two hints are declared – one for the term
0that yields the group identity, another for any termS nthat yields then‑fold product of a distinguished generator. - List → Monoid: a hint for
nilreturns the monoid unit, while a hint forcons h treturnsh ⊕ (convert t). - Function → Set‑theoretic object: hints inspect the domain and codomain to construct the appropriate set representation.
In each case the conversion happens automatically during proof development, eliminating the need for explicit convert calls. Empirical evaluation shows a reduction of proof script length by roughly 15‑20 % and a decrease in the number of manual instance declarations, while the overhead on the unification engine remains negligible.
The discussion section acknowledges potential scalability concerns: as the number of hints grows, naïve linear search may become costly, suggesting the need for indexing or priority mechanisms. Moreover, porting the approach to other ITPs (Lean, Agda, Isabelle) would require exposing a comparable hint‑based unification API. Finally, the authors outline future work on applying non‑uniform coercions to richer mathematical domains such as category theory and higher‑dimensional algebra, where the ability to tailor conversions to term structure could dramatically simplify formalisation.
In summary, the paper provides a rigorous definition of non‑uniform coercions, shows how they can be realised using existing unification‑hint infrastructure, proves that the extension preserves key logical properties, and validates the approach with concrete Coq implementations. This contribution expands the expressive power of ITPs, offering users a more natural and automated way to bridge heterogeneous types in formal mathematics.
Comments & Academic Discussion
Loading comments...
Leave a Comment