TL;DR
The authors present a lightweight Coq library that leverages type classes to introduce standard mathematical notations (like $\in$, $\cup$, $\subseteq$, and $\circ$) for sets and relations. Designed specifically for undergraduate courses in denotational semantics, the library drastically improves readability and simplifies proof automation without introducing any proof-term overhead.
What Problem Does This Paper Address?
Interactive theorem provers like Coq are powerful tools for teaching programming language theory, providing students with immediate, machine-checked feedback on homework. However, Coq's native formalization of sets can be incredibly unintuitive for beginners.
Typically, Coq represents a subset as a curried function to Prop (e.g., A -> Prop for a set, or A -> B -> Prop for a binary relation). This leads to two major issues in an educational setting:
- Poor Readability: Set membership is written as function application (
X aorX a b) rather than the familiar $a \in X$ or $(a,b) \in X$. - Duplicated Definitions: Standard operations like union ($\cup$) or composition ($\circ$) must be defined separately for every relation arity (e.g.,
union1for sets,union2for binary relations). This forces students to memorize multiple versions of the same semantic theorems (e.g., commutativity and associativity).
Methods
To bridge the gap between formal logic and standard mathematical notation, the authors developed a Coq library based on two core components:
- Type Class Overloading: The library defines type classes (
SETS,RELS, andSETS_ELE) to overload standard notations. This allows a single symbol like $\cup$ or $\circ$ to work seamlessly across sets, binary relations, ternary relations, and labeled relations. - Zero-Cost Unfolding Tactic (
Sets_unfold): When proving set properties, standard Coq unfolding tactics often reduce goals into messy, low-level lambda expressions. The authors designed a custom Ltac tactic,Sets_unfold, which uses a helper function calledset_transferto safely transform variables into intuitive propositions containing the $\in$ symbol. Crucially, this transformation relies on $\beta\iota\delta$-equivalence, meaning it introduces absolutely no extra rewrite steps or proof-term bloat.
Datasets
While this paper does not use machine learning datasets, the library was evaluated empirically across three undergraduate computer science courses at Shanghai Jiao Tong University.
The student cohorts varied significantly in their prior exposure to discrete math and programming experience, providing a robust test bed for the library's educational clarity.
Key Insights and Ideas
- Notation is a Cognitive Load: In education, forcing students to translate
X a bto $(a,b) \in X$ distracts from the actual course content (learning language semantics). Standard mathematical notation acts as a user interface that lowers this cognitive barrier. - Arity-Agnostic Unification: By treating a unary relation (
A -> Prop) as a binary relation to a unit type (A -> unit -> Prop), the authors demonstrate how type classes can elegantly unify relation composition across different dimensions. This helps students visualize properties like the distribution of composition over union using intuitive diagrams.
- The "Zero-Cost" Sweet Spot: Abstracting notations for the sake of readability usually comes at the cost of performance or proof complexity. This library proves that with clever tactic design, you can have human-readable goals during interactive proofs while maintaining identical underlying proof terms.
Key Results
- Comprehensive Lemma Library: The library provides 61 pre-proven lemmas detailing the commutativity, associativity, and distributivity of set operations, eliminating the need for students to hunt for type-specific theorem names.
- Seamless Automation: The library's operators are proven to preserve set equivalence and inclusion using Coq's standard morphism type classes, allowing students to use Coq's built-in
rewritetactic directly on sets. - Identical Proof Terms: The proof terms generated using
Sets_unfoldmatch manual, low-level proofs exactly, validating the "zero-cost" claim.
Limitations and Future Work
Despite minimizing the friction of set notation, integrating a theorem prover into a course still requires dedicating valuable lecture time to teaching the tool itself. To keep the course manageable, the instructors had to intentionally omit advanced Coq concepts like the Curry-Howard correspondence and inductively defined propositions.
Currently, the library is optimized for simple imperative languages and textbook denotational semantics. Extending this user-friendly notation system to handle highly complex, concurrent language features remains an open avenue for future development.
Summary updated