Tag. guarded-recursion
Notes (10)
Predecessors simplify later predecessors-simplify-later
A predecessor of is a top element of its strict downset: a strict morphism through which every strict morphism into factors uniquely. Equivalently, β the downset is representable.
The Yoneda lemma then collapses later to evaluation:
with becoming restriction along . The name is from the naturals: every strict map into factors through , so on β in the topos of trees β later is just the shift
and a LΓΆb step is a base value together with a rule producing the value at from the value at .
When this predecessor exists, we can give a simpler description of later, as in the topos of trees, but this may not be possible in all direct categories.
Definition. Earlier on presheaves earlier-presheaf
Later takes a limit over smaller indices. Dually, the earlier modality takes a colimit over larger indices: an element of at is a -element sitting at some object strictly above , carried down along a chosen morphism .
Earlier is left adjoint to later:
Under this adjunction, corresponds to
.
Definition. Later on families later-family
Conjugation with the adjunction between presheaves and families lets us induce a later construction on families from the one on presheaves,
Concretely, later on families evaluates to
Definition. Later on presheaves later-presheaf
The later modality for presheaves on a direct category is given by the presheaf of natural transformations
out of the strict downset.
An element of at is a coherent choice of -elements at all objects strictly smaller than .
Restriction in along precomposes with the induced map . At an object of minimal degree the strict downset is empty, so is trivial there.
Via functoriality, every presheaf restricts to smaller indices. Thus we may define the map
that sends an element over to the family of all its restrictions along morphisms from strictly lower objects.
Theorem. LΓΆb induction on families lob-family
Like later on families, the recursion principle for families is inherited from that on presheaves. Given a family and a step
the construction is a chain of transpositions with LΓΆb for presheaves used in the middle:
Just as for presheaves, the fixed point constructed above is unique: the two transpositions are bijections, and the presheaf-level fixed point is already unique.
Theorem. LΓΆb induction for presheaves on a direct category lob-presheaf
Let be a direct category and a presheaf on it. Every map
has a fixed point: a global element with
and this fixed point is unique.
The hypothesis says: the value of at any object is determined by its values over the strict past β turns a coherent family over the strict downset of into a value at . The proof is recursion along the well-founded : at each , the section already constructed over the past assembles into an element of , and extends it to .
Definition. Locally contractive endofunctors locally-contractive-functor
Write for the presheaf of morphisms . An endofunctor on presheaves is locally contractive when its action on morphisms factors through later: there is a map
Definition. Later on Grammars grammar-later
Write when is a proper suffix of , that is, with . The later of a grammar is
A parse of over is a parse of over every proper suffix of . In particular is a singleton.
This is later on families for strings under the proper-suffix order. That order is well-founded because it strictly decreases length, so it is a thin direct category. There is at most one map , so the product over maps from the strict past has one factor per proper suffix. Guarded recursion is modelled by presheaves on , the topos of trees, and more generally by sheaves over a well-founded base [1]. Here the later acts on families, which is what grammars are, and there is no clock.
Later is the right adjoint of the proper-suffix derivative. Let be the grammar of non-empty strings. Then the derivative has the right adjoint
so . Splitting into its summands gives the form of that the calculus can define:
The component at says: if the string begins with , then the rest parses as .
The restriction to non-empty is what makes this a later. At the component is . Including it would give a projection , and LΓΆb would then prove every grammar. For the same reason the later is a product over suffixes. A sum such as is empty at , and at it is . The identity step would then give LΓΆb a proof of .
In the Agda this is β· in Grammar/Later/Base.agda, which is defined as the indexed conjunction of βl-string. The mirror image β·r, over proper prefixes, is defined in the same way. See also the bilateral later and the later along an arbitrary well-founded order.
Theorem. LΓΆb Induction for Grammars grammar-lob
For every grammar and every term , where is the later on grammars, there is a unique global parse with
Here restricts a global parse to every proper suffix.
The proof is recursion on the length of the string. At , the parses already built at the proper suffixes of form an element of , and turns it into a parse at . Uniqueness is LΓΆb for families over the proper-suffix order. In the Agda, lob in Grammar/Later/Base.agda is this recursion, done by well-founded induction on length.
To prove an entailment this way, apply LΓΆb to . The hypothesis is the induction hypothesis at every proper suffix. It becomes usable once a non-nullable grammar has been consumed. If , then
because a parse of over splits with non-empty, so . This is β·-app-NE in Grammar/Later/Properties.agda. Induction on a Kleene star is the standard use.
Theorem. Next on Grammars Is Presheaf Structure grammar-next-presheaf
For presheaves, restricts along the strict past, as in later on presheaves. A grammar is only a family over strings, so a map into the later on grammars is extra data. It sends a parse over to parses over every proper suffix of .
Let , so that . This is the comonad for the suffix order, and presheaves are comonadic over families. The counit law forces the first component of a coalgebra to be the identity. Hence:
- a presheaf on strings under the suffix order is the same as a grammar with a map that satisfies coassociativity. Restricting to and then to must agree with restricting to directly;
- for a proposition-valued grammar (a language), coassociativity is automatic, and exists exactly when the language is closed under suffixes. For example, has one, but does not, since is empty.
LΓΆb does not need on . The fixed-point equation only restricts a global parse , and a global parse can always be restricted. In the Agda, the grammar-level IsCoalgebra record, with only the field next, is in Grammar/Later/Coalgebra.agda on the guarded branch.
On presheaves the strict downset of is represented by , because every proper suffix of is a suffix of . So predecessors simplify later to . On grammars there is no such simplification, since the factors at different suffixes are unrelated.
References (15)
Context-Dependent Effects and Concurrency in Guarded Interaction Trees stepanenko-2025-context
A Modal Deconstruction of LΓΆb Induction gratzer-2025-a
Modelling Recursion and Probabilistic Choice in Guarded Type Theory stassen-2025-modelling
Denotational Semantics of Gradual Typing using Synthetic Guarded Domain Theory giovannini_ding_new_2025
Gradually typed programming languages, which allow for soundly mixing static and dynamically typed programming styles, present a strong challenge for metatheorists. Even the simplest sound gradually typed languages feature at least recursion and errors, with realistic languages featuring furthermore runtime allocation of memory locations and dynamic type tags. Further, the desired metatheoretic properties of gradually typed languages have become increasingly sophisticated: validity of type-based equational reasoning as well as the relational property known as graduality. Many recent works have tackled verifying these properties, but the resulting mathematical developments are highly repetitive and tedious, with few reusable theorems persisting across different developments.
In this work, we present a new denotational semantics for gradual typing developed using guarded domain theory. Guarded domain theory combines the generality of step-indexed logical relations for modeling advanced programming features with the modularity and reusability of denotational semantics. We demonstrate the feasibility of this approach with a model of a simple gradually typed lambda calculus and prove the validity of beta-eta equality and the graduality theorem for the denotational model. This model should provide the basis for a reusable mathematical theory of gradually typed program semantics. Finally, we have mechanized most of the core theorems of our development in Guarded Cubical Agda, a recent extension of Agda with support for the guarded recursive constructions we use.
Context-Dependent Effects in Guarded Interaction Trees stepanenko-2025-contextx
Solving Guarded Domain Equations in Presheaves over Ordinals and Mechanizing It stepanenko-2025-solving
Modular Denotational Semantics for Effects with Guarded Interaction Trees frumin-2024-modular
Towards Univalent Reference Types: The Impact of Univalence on Denotational Semantics sterling-2024-towards
A denotationally-based program logic for higher-order store aagaard-2023-a
Classifying topoi in synthetic guarded domain theory: the universal property of multi-clock guarded recursion palombi_sterling_2023
A Stratified Approach to LΓΆb Induction gratzer-2022-a
Coinduction in flow: the later modality in fibrations basold_2019
This paper provides a construction on fibrations that gives access to the so-called later modality, which allows for a controlled form of recursion in coinductive proofs and programs. The construction is essentially a generalisation of the topos of trees from the codomain fibration over sets to arbitrary fibrations. As a result, we obtain a framework that allows the addition of a recursion principle for coinduction to rather arbitrary logics and programming languages. The main interest of using recursion is that it allows one to write proofs and programs in a goal-oriented fashion. This enables easily understandable coinductive proofs and programs, and fosters automatic proof search.
Part of the framework are also various results that enable a wide range of applications: transportation of (co)limits, exponentials, fibred adjunctions and first-order connectives from the initial fibration to the one constructed through the framework. This means that the framework extends any first-order logic with the later modality. Moreover, we obtain soundness and completeness results, and can use up-to techniques as proof rules. Since the construction works for a wide variety of fibrations, we will be able to use the recursion offered by the later modality in various context. For instance, we will show how recursive proofs can be obtained for arbitrary (syntactic) first-order logics, for coinductive set-predicates, and for the probabilistic modal mu-calculus. Finally, we use the same construction to obtain a novel language for probabilistic productive coinductive programming. These examples demonstrate the flexibility of the framework and its accompanying results.