Proving and Computing: The Infinite Pigeonhole Principle and Countable Choice
Structural recursion is a common technique used by programmers in modern languages and is taught to introductory computer science students. But what about its dual, structural corecursion? Structural corecursion is an elegant technique, supported in languages like Haskell and proof assistants such as Rocq or Agda. It enables the design of compositional algorithms by decoupling the generation and consumption of potentially infinite or large data collections. Despite these strengths, structural corecursion is generally considered more advanced than structural recursion and is primarily studied in the context of pure functional programming. Our aim is to illustrate the expressive power of different notions of structural corecursion in the presence of classical reasoning. More specifically, we study coiteration and corecursion combined with the classical callcc operator, which provides a computational interpretation of classical reasoning. This combination enables interesting stream-processing algorithms. As an application, we present a corecursive, control-based proof of the Infinite Pigeonhole Principle and compare it with the continuation-passing proof of Escardó and Oliva in Agda. To further demonstrate the power of mixing corecursion and control, we give an implementation of the Axiom of Countable Choice. In contrast to the usual continuation-passing implementations of this axiom, which rely on general recursion whose termination is established externally, our approach justifies termination by coiteration alone.
💡 Research Summary
The paper investigates the expressive power of structural corecursion when combined with classical control operators, focusing on two classic non‑constructive principles: the Infinite Pigeonhole Principle (IPP) and the Countable Choice axiom. While structural recursion is a staple of introductory programming education, its dual—structural corecursion—remains largely confined to pure functional languages and proof assistants. The authors aim to demystify corecursion by presenting a systematic taxonomy of corecursive patterns in Coq, and by showing how the call‑cc operator (a computational embodiment of classical reasoning) can be used to obtain executable programs from proofs that rely on non‑constructive reasoning.
The paper begins by defining coinductive streams in Coq and illustrating the pitfalls of eager evaluation when extracting code to call‑by‑value languages such as OCaml. By redefining the tail component as a delayed function (unit → stream) the authors achieve true laziness and avoid unnecessary computation of the Ackermann function used as a dummy infinite computation. This technical groundwork sets the stage for the three corecursive schemes they develop:
-
Coiteration – a simple state‑driven generator where the head is computed from a base function and the next state is produced by a transition function. This pattern captures many familiar stream definitions (always, countUp, map) and serves as the most elementary form of corecursion.
-
Minimal Corecursion (Apomorphism) – extends coiteration by allowing the corecursive loop to terminate early. The next function returns a sum type (stream Y + X); an
inlcontinuation yields a fresh seed for further generation, while aninrsupplies a fully constructed tail, effectively ending the loop. This scheme is essential for defining streams such as countDown, which stops at zero and switches to a pre‑computed zero stream, and for implementing list‑append on streams without resorting to general recursion. -
Continuation‑Based Corecursion – the most powerful pattern, which leverages the classical control operator
callcc. Here the tail step receives two continuations: an implicit one that continues the corecursive process, and an explicit one that captures the caller’s request for the next element. The authors formalise this using the Peirce law (¬(S + X) → S + X) → S + X, whose computational content is preciselycallcc. They provide a Coq derivation of the required typing judgments and definecorecCthat integrates continuations into the corecursive loop.
With these tools the authors construct a corecursive, control‑based proof of the Infinite Pigeonhole Principle. Given an infinite Boolean stream, they simultaneously generate two sub‑streams (one of all true values, one of all false values) via coiteration. The callcc operator then selects the sub‑stream that yields infinitely many elements, guaranteeing a constant subsequence. This proof is compared to the continuation‑passing style proof by Escardó and Oliva in Agda; the corecursive version is more direct, preserving the stream‑like intuition and avoiding the need for an explicit CPS transformation.
The second major contribution is an implementation of the Countable Choice axiom in a purely corecursive fashion. The classical double‑negated formulation ¬¬∃x R(n,x) → ¬¬∃f ∀n R(n,f n) is realised by using callcc to eliminate double negation and minimal corecursion to ensure termination without any external well‑foundedness argument. The resulting choice function is built as a stream of witnesses, each extracted lazily as needed, demonstrating that even strong non‑constructive axioms can be computationally interpreted using only coiteration, apomorphism, and classical control.
All definitions, lemmas, and extracted programs are formalised in Coq 8.17 and made publicly available in the “infinite‑pigeonhole” repository. The paper also reflects on the broader implications of mixing corecursion with classical logic: it bridges the gap between functional programming and proof theory, suggests new language design directions where corecursive primitives and control operators are first‑class citizens, and opens the door to extracting executable algorithms from a wider class of classical proofs.
Comments & Academic Discussion
Loading comments...
Leave a Comment