Relating Structure and Power: Comonadic Semantics for Computational Resources

Combinatorial games are widely used in finite model theory, constraint satisfaction, modal logic and concurrency theory to characterize logical equivalences between structures. In particular, Ehrenfeucht-Fraisse games, pebble games, and bisimulation games play a central role. We show how each of these types of games can be described in terms of an indexed family of comonads on the category of relational structures and homomorphisms. The index k is a resource parameter which bounds the degree of access to the underlying structure. The coKleisli categories for these comonads can be used to give syntax-free characterizations of a wide range of important logical equivalences. Moreover, the coalgebras for these indexed comonads can be used to characterize key combinatorial parameters: tree-depth for the Ehrenfeucht-Fraisse comonad, tree-width for the pebbling comonad, and synchronization-tree depth for the modal unfolding comonad. These results pave the way for systematic connections between two major branches of the field of logic in computer science which hitherto have been almost disjoint: categorical semantics, and finite and algorithmic model theory.


Introduction
There is a remarkable divide in the field of logic in Computer Science, between two distinct strands: one focusing on semantics and compositionality ("Structure"), the other on expressiveness and complexity ("Power"). It is remarkable because these two fundamental aspects of our field are studied using almost disjoint technical languages and methods, by almost disjoint research communities. We believe that bridging this divide is a major issue in Computer Science, and may hold the key to fundamental advances in the field.
In this paper, we develop a novel approach to relating categorical semantics, which exemplifies the first strand, to finite model theory, which exemplifies the second. It builds on the ideas introduced in [3], but goes much further, showing clearly that there is a strong and robust connection, which can serve as a basis for many further developments. These developments were first introduced in the conference version of this paper [5]. In this journal version, we have added more detailed proofs, and three additional sections demonstrating how game comonads generalize constructions in finite model theory. We have also introduced a new and more satisfactory unified account of back-and-forth equivalences, in terms of open pathwise embeddings, which capture a general notion of property-preserving bisimulation.

Note on the presentation
Since this work aims at connecting what are at present largely disjoint research areas and communities, we have attempted to provide enough background exposition in the paper to make it reasonably self-contained. In the following section, we provide some background on model comparison games, and their correspondence with logical equivalences, to assist readers mainly coming from the categorical semantics side. For those whose background is mainly in finite model theory and descriptive complexity, we assume only some prior exposure to the basic notions of category, functor, and natural transformation. Notions relating to comonads are presented in a self-contained way.
We thank the journal referees for their encouragement of, and indeed insistence on, our efforts in this regard.

Model theory and deception
In a sense, the purpose of model theory is "deception". It allows us to see structures not "as they really are", i.e. up to isomorphism, but only up to definable properties, where definability is relative to a logical language L.
The key notion is logical equivalence ≡ L . Given structures A , B over the same vocabulary: If a class of structures K is definable in L, then it must be saturated under ≡ L . Moreover, for a wide class of cases of interest in finite model theory, the converse holds [31].
The idea of syntax-independent characterizations of logical equivalence is quite a classical one in model theory, exemplified by the Keisler-Shelah theorem [43]. It acquires additional significance in finite model theory, where model comparison games such as Ehrenfeucht-Fraïssé games, pebble games and bisimulation games play a central role [32].
We offer a new perspective on these ideas. We shall study these games, not as external artefacts, but as semantic constructions in their own right. Each model-theoretic comparison game encodes "deception" in terms of limited access to the structure. These limitations are indexed by a parameter which quantifies the resources which control this access. For Ehrenfeucht-Fraïssé games and bisimulation games, this is the number of rounds; for pebble games, the number of pebbles.

Main Results
We now give a conceptual overview of our main results. Technical details will be provided in the following sections.
We shall consider three forms of model comparison game: Ehrenfeucht-Fraïssé games, pebble games and bisimulation games [32]. For each of these notions of game G, and value of the resource parameter k, we shall define a corresponding comonad C k on the category of relational structures and homomorphisms over some relational vocabulary. For each structure A , C k A is another structure over the same vocabulary, which encodes the limited access to A afforded by playing the game on A with k resources. There is always an associated homomorphism ε A : C k A → A (the counit of the comonad), so that C k A "covers" A . Moreover, given a homomorphism h : C k A → B, there is a Kleisli coextension homomorphism h * : C k A → C k B. This allows us to form the coKleisli category Kl(C k ) for the comonad. The objects are relational structures, while the morphisms from A to B in Kl(C k ) are exactly the homomorphisms of the form C k A → B. Composition of these morphisms uses the Kleisli coexten-sion. The connection between this construction and the corresponding form of game G is expressed by the following result: Theorem 1.1. The following are equivalent: 1. There is a coKleisli morphism C k A → B 2. Duplicator has a winning strategy for the existential G-game with k resources, played from A to B.
The existential form of the game has only a "forth" aspect, without the "back". This means that Spoiler can only play in A , while Duplicator only plays in B. This corresponds to the asymmetric form of the coKleisli morphisms C k A → B. Intuitively, Spoiler plays in C k A , which gives them limited access to A , while Duplicator plays in B. The Kleisli coextension guarantees that Duplicator's strategies can always be lifted to C k B; while we can always compose a strategy C k A → C k B with the counit on B to obtain a coKleisli morphism.
This asymmetric form may seem to limit the scope of this approach, but in fact this is not the case. For each of these comonads C k , we have the following equivalences: Note that there need be no relationship between these morphisms.
• A ∼ = Kl(C k ) B iff A and B are isomorphic in the coKleisli category Kl(C k ). This means that there are morphisms C k A → B and C k B → A which are inverses of each other in Kl(C k ).
Clearly, ∼ = Kl(C k ) strictly implies ⇄ k . We can also define an intermediate "back-and-forth" equivalence ↔ k , in terms of the existence of a suitable kind of span of coKleisli morphisms. For each of our three types of game, there are corresponding fragments L k of first-order logic: • For Ehrenfeucht-Fraïssé games, L k is the fragment of quantifier-rank ≤ k.
• For pebble games, L k is the k-variable fragment.
• For bisimulation games over relational vocabularies with symbols of arity at most 2, L k is the modal fragment [9] with modal depth ≤ k.
In each case, we write ∃L k for the existential positive fragment of L k , and L k (#) for the extension of L k with counting quantifiers [32].
We can now state our first main result, in a suitably generic form.

Theorem 1.2. For finite structures A and B:
( Note that this is really a family of three theorems, one for each type of game G. Thus in each case, we capture the salient logical equivalences in syntax-free, categorical form.
We now turn to the significance of indexing by the resource parameter k. When k ≤ l, we have a natural inclusion morphism C k A → C l A , since playing with k resources is a special case of playing with l ≥ k resources. This tells us that the smaller k is, the easier it is to find a morphism C k A → B. Intuitively, the more we restrict Spoiler's abilities to access the structure of A , the easier it is for Duplicator to win the game.
The contrary analysis applies to morphisms A → C k B. The smaller k is, the harder it is find such a morphism. Note, however, that if A is a finite structure of cardinality k, then A ⇄ k C k A . In this case, with k resources we can access the whole of A . What can we say when k is strictly smaller than the cardinality of A?
It turns out that there is a beautiful connection between these indexed comonads and combinatorial invariants of structures. This is mediated by the notion of coalgebra, another fundamental (and completely general) aspect of comonads. A coalgebra for a comonad C k on a structure A is a morphism A → C k A satisfying certain properties. We define the coalgebra number of a structure A , with respect to the indexed family of comonads C k , to be the least k such that there is a C k -coalgebra on A .
We now come to our second main result. 2. For the pebbling comonad, the coalgebra number of A corresponds precisely to the tree-width of A .
3. For the modal comonad, the coalgebra number of A corresponds precisely to the modal unfolding depth of A .
The main idea behind these results is that coalgebras on A are in bijective correspondence with decompositions of A of the appropriate form. We thus obtain categorical characterizations of these key combinatorial parameters.
These two results appeared in the first version of this paper [5], and unify logical resources with combinatorial resources. In this expanded version of the paper, we provide two new families of results that can be seen as further aspects of this unification. The first result utilizes a general fact about comonads to link the logical resource characterized by coKleisli morphisms C k A → B to the combinatorial resource characterized by the coalgebas A → C k A . For each game comonad C k , we can define a preorder → C k over the category of structures, where A → C k B iff for all structures C with combinatorial resource parameter ≤ k, C → A ⇒ C → B. This preorder, when instantiated to the case of Ehrenfeucht-Fraïssé games and tree-depth, is used extensively in [41]. We demonstrate that this preorder is characterized by the coKleisli category of C k .
For the second result, we show how coalgebras can be interpreted syntactically. We show that a coalgebra A → C k A encodes a witness to the fact that the canonical conjunctive query Q A of A is equivalent to a sentence in the logical fragment corresponding to the comonad. Theorem 1.5. A has a C k -coalgebra iff Q A can be rewritten into a formula ϕ, where ϕ has logical resource at most k.
The formula ϕ can be read out from the coalgebra map. We also show how to rephrase the coalgebra results of Theorem 1.3 in the language of adjunctions. Theorem 1.6. Each game comonad arises from an adjunction between the category of structures and a category of tree-ordered structures: • For the Ehrenfeucht-Fraïssé comonad, the associated category is kheight tree-ordered structures.
• For the pebbling comonad, the associated category is k-pebble treeordered structures.
• For the modal comonad, the associated category is k-height tree-ordered Kripke structures.
In each case, the left adjoint is the evident forgetful functor which forgets the order. The right adjoint is given by the functor part of the comonad.
We have also put the notion of I-morphism introduced in [3], and used extensively in [5], on a more systematic basis, in terms of relative comonads [8].
Finally, an important contribution of this expanded version of the paper is to give a unified, general treatment of back-and-forth equivalences, which play a central role in finite model theory. To do this, we use a refined version of the well-known notion of open map bisimulation [28], in which the maps in the span witnessing a bisimulation are required not only to be open, but to be pathwise embeddings. This supports a general notion of property-preserving bisimulation, which specialises to yield all the back-and-forth equivalences we study here, as well as many other examples, e.g. guarded bisimulation [3].

Background
We shall now review some background on logics, model comparison games, and comonads.

Notational preliminaries
A relational vocabulary σ is a set of relation symbols R, each with a specified positive integer arity. A σ-structure A is given by a set A, the universe of the structure, and for each R in σ with arity n, a relation R A ⊆ A n . A homomorphism h : A → B is a function h : A → B such that, for each relation symbol R of arity n in σ, for all a 1 , . . . , a n in A: R A (a 1 , . . . , a n ) ⇒ R B (h(a 1 ), . . . , h(a n )). We write R(σ) for the category of σ-structures and homomorphisms.
A homomorphism h : A → B is strong if for n-ary R in σ and a 1 , . . . , a n ∈ A, R B (h(a 1 ), . . . , h(a n )) ⇒ R A (a 1 , . . . , a n ). An embedding of relational structures is an injective strong homomorphism. It is easily verified that the embeddings in R(σ) are exactly the extremal monomorphisms; those monomorphisms m such that, whenever m = f • e for an epimorphism e, e is an isomorphism.
A partial homomorphism from A to B is a finite relation r ⊆ A×B which is single-valued on its domain and which is a homomorphism on the substructure of A determined by A 0 . A partial isomorphism from A to B is a partial homomorphism r such that the converse relation r c ⊆ B × A is a partial homomorphism from B to A .
We shall write A ≤k for the set of non-empty sequences of length ≤ k on a set A. We use list notation [a 1 , . . . , a j ] for such sequences, and indicate concatenation by juxtaposition, i.e. ss ′ is the concatenation of the sequences s and s ′ . We write s ⊑ t for the prefix ordering on sequences. If s ⊑ t, there is a unique s ′ such that ss ′ = t, which we refer to as the suffix of s in t. For each positive integer n, we define n := {1, . . . , n}.
We shall need a few notions on posets. The comparability relation on a poset (P, ≤) is x↑y iff x ≤ y or y ≤ x. A chain in a poset (P, ≤) is a subset C ⊆ P such that, for all x, y ∈ C, x↑y. A forest is a poset (F, ≤) such that, for all x ∈ F , the set of predecessors ↓(x) := {y ∈ F | y ≤ x} is a finite chain. The height ht(F ) of a forest F is sup C |C|, where C ranges over chains in F . A tree is a forest with a least element ⊥ (the root). We write the covering relation for a poset as ≺; thus x ≺ y iff x ≤ y, x = y, and for all z, x ≤ z ≤ y implies z = x or z = y.

Logic fragments
We shall be considering logics L which arise as fragments of L ∞,ω , the extension of first-order logic with infinitary conjunctions and disjunctions, but where formulas contain only finitely many variables. In particular, we will consider the fragments L k , of formulas with quantifier rank ≤ k, and L k , the k-variable fragment. These play a fundamental rôle in finite model theory.
We shall also consider two variants for each of these fragments L. One is the existential positive fragment ∃L, which contains only those formulas of L built using existential quantifiers, conjunction and disjunction. The other is L(#), the extension of L with counting quantifiers. These have the form ∃ ≤n , ∃ ≥n , where the semantics of A |= ∃ ≥n x. ψ is that there exist at least n distinct elements of A satisying ψ.
For modal logic, we will consider M k , the modal fragment of modal depth ≤ k. This arises from the standard translation of (multi)modal logic into L ∞,ω [10]. Let us fix a relational vocabulary σ with symbols of arity ≤ 2. For each unary symbol P , there will be a corresponding propositional variable p. Formulas are built from these propositional variables by propositional connectives, and modalities α , ♦ α corresponding to relations R α indexed by the binary relation symbols from the given alphabet. Modal formulas ϕ then admit a translation into formulas ϕ = ψ(x) in one free variable. The translation sends propositional variables p to P (x), commutes with the propositional connectives, and sends ♦ α ϕ to ∃y. R α (x, y) ∧ ψ(y), and α ϕ to ∀y. R α (x, y) → ψ(y), where ψ(x) = ϕ . This translation is semanticspreserving: given a σ-structure A and a ∈ A, then A , a |= ϕ in the sense of Kripke semantics iff A |= ψ(a) in the standard model-theoretic sense, where ψ(x) = ϕ .
We define the modal depth of a modal formula ϕ as the maximum nesting depth of modalities occurring in ϕ. M k is then the image of the translation of modal formulas of modal depth ≤ k. The existential positive fragment ∃M k arises from the modal sublanguage in which formulas are built from propositional variables using only conjunction, disjunction and the diamond modalities ♦ α .
Extensions of the modal language with counting capabilities have been studied in the form of graded modalities [17]. These have the form ♦ n α , n α , where A , a |= ♦ n α ϕ if there are at least n R α -successors of a which satisfy ϕ. We define M k (#) to be the extension of the modal fragment with graded modalities.

Model comparison games
We review the model comparison games we will be concerned with in this paper. We are given structures A and B. Each game is a 2-person game, played between Spoiler, who is trying show that the structures are different, and Duplicator, who is trying to show they are the same. Each game is played in a number of rounds: • In the Ehrenfeucht-Fraïssé game, in the i'th round Spoiler chooses an element in one of the structures, and Duplicator then chooses an element in the other structure. Thus after k rounds have been played, we have sequences [a 1 , . . . , a k ] and [b 1 , . . . b k ] of elements from A and B respectively. Duplicator wins this play if r := {(a i , b i ) | 1 ≤ i ≤ k} is a partial isomorphism. Duplicator wins the k-round game if they have a winning strategy in the usual sense. The resource parameter here is k, the number of rounds.
• In the pebble game, each player has k pebbles available, which can be "placed" on elements of either structure. We label the pebbles by integers in k. In the i'th round, Spoiler places some pebble p i on an element of one of the structures. Note that if p i was previously placed on some other element, the effect is to remove it from that element, and place it on the newly chosen element. Duplicator then places their corresponding pebble p i on an element of the other structure.
Thus the current positions of the pebbles determine "windows" of size bounded by k onto the structures. These windows can slide around over different parts of the structures as moves are played.
After n rounds of the game have been played, we have sequences [(p 1 , a 1 ), . . . , (p n , a n )] and [(p 1 , b 1 ), . . . (p n , b n )] which record the placings of pebbles on elements during the play. The current placing of pebble p is the last element in the sequence with first component p. Duplicator wins this play if the relation r determined by the current placings of the pebbles is a partial isomorphism. Duplicator wins the k-pebble game if they have a strategy which is winning after n rounds, for all n. The resource parameter here is k, the number of pebbles.
• Finally, in the bisimulation game, we have structures over a relational signature with symbols of arity at most 2. The game is played between "pointed structures" (A , a), (B, b), with specified elements a ∈ A and b ∈ B. We start with elements (a 0 , b 0 ), where a 0 = a and b 0 = b. At each round i+1, where the current elements are (a i , b i ), Spoiler chooses one of the structures, e.g. A , one of the binary relations R i , and an element a i+1 such that R A i (a i , a i+1 ). Duplicator must respond in the other structure, in our example in . If Duplicator has no such response available, they lose. Duplicator wins after k rounds if, for all unary predicates P in the signature, we have P A (a i ) ⇐⇒ P B (b i ) for all i with 0 ≤ i ≤ k. The resource parameter here is the number of rounds k.
1. Duplicator has a winning strategy in the k-round Ehrenfeucht-Fraïssé game from A to B iff A and B satisfy the same sentences of quantifier rank ≤ k.
2. Duplicator has a winning strategy in the k-pebble game from A to B iff A and B satisfy the same sentences of k-variable logic.
3. Duplicator has a winning strategy in the k-round bisimulation game from (A , a) to (B, b) iff (A , a) and (B, b) satisfy the same modal formulas of depth ≤ k.
The above games are symmetric or "back-and-forth", since Spoiler can choose which structure to play in at each round. There are also asymmetric (forth only) or existential versions, in which Spoiler always plays in A , and Duplicator always responds in B. The winning conditions are modified for these existential versions: • For the existential Ehrenfeucht-Fraïssé game, the winning condition is that r is a partial homomorphism.
• Similarly for the existential k-pebble game.
• For the k-round simulation game, as the existential version of the bisimulation game is called, the winning condition is that, for all unary predicates P , P (a i ) ⇒ P (b i ) for all i with 0 ≤ i ≤ k.
For these existential games, we obtain a corresponding version of Theorem 2.1.
Theorem 2.2. Let A and B be structures.
1. Duplicator has a winning strategy in the existential k-round Ehrenfeucht-Fraïssé game from A to B iff for every existential-positive sentence ϕ of quantifier rank ≤ k, A |= ϕ implies B |= ϕ.
2. Duplicator has a winning strategy in the existential k-pebble game from A to B iff for every existential-positive sentence ϕ of k-variable logic, 3. Duplicator has a winning strategy in the k-round simulation game from (A , a) to (B, b) iff for every existential-positive sentence ϕ of the modal fragment with modal depth ≤ k, A |= ϕ implies B |= ϕ.

Comonads
We recall that a comonad (G, ε, δ) on a category C is given by a functor G : C → C, and natural transformations ε : G ⇒ I (the counit), and δ : G ⇒ G 2 (the comultiplication), subject to the conditions that the following diagrams commute, for all objects A of C: An equivalent formulation is comonad in Kleisli form [34]. This is given by an object map G, arrows ε A : GA → A for every object A of C, and a Kleisli coextension operation which takes f : GA → B to f * : GA → GB. These must satisfy the following equations: We can then extend G to a functor by Gf = (f • ε) * ; and if we define the comultiplication δ : G ⇒ G 2 by δ A = id * GA , then (G, ε, δ) is a comonad in the standard sense. Conversely, given a comonad (G, ε, δ), we can define the coextension by f * = Gf • δ A . This allows us to define the coKleisli category Kl(G), with objects the same as those of C, and morphisms from A to B given by the morphisms in C of the form GA → B. Kleisli composition of f : GA → B with g : GB → C is given by g • f := g • f * .

Game Comonads
We shall now define the three comonads we shall study, corresponding to the three forms of model comparison game described in the previous section.

The Ehrenfeucht-Fraïssé Comonad
We shall define a comonad E k on R(σ) for each positive integer k. It will be convenient to define E k in Kleisli form. For each structure A , we define a new structure E k A , with universe E k A := A ≤k . We define the map ε A : E k A → A by ε A [a 1 , . . . , a j ] = a j . For each relation symbol R of arity n, we define R E k A to be the set of n-tuples (s 1 , . . . , s n ) of sequences which are pairwise comparable in the prefix ordering, and such that R A (ε A s 1 , . . . , ε A s n ). Finally, we define the coextension. Given a homo- Proof. It is well known that non-empty lists form a comonad on Set [7]. This is easily adapted to showing that non-empty lists of length ≤ k form a comonad. To lift this to R(σ), we must show that each ε A is a homomorphism, and that if f : E k A → B is a homomorphism, so is f * . The first follows directly from the definition of R E k A for each R in σ. For the second, if R E k A (s 1 , . . . , s n ), then s i ↑s j implies f * (s i )↑f * (s j ), and since f is a homomorphism, R E k A (s 1 , . . . , s n ) implies R B (εf * (s 1 ), . . . , εf * (s n )), so R E k B (f * (s 1 ), . . . , f * (s n )) as required.
Intuitively, an element of A ≤k represents a play in A of length ≤ k. A coKleisli morphism E k A → B represents a Duplicator strategy for the existential Ehrenfeucht-Fraïssé game with k rounds, where Spoiler plays only in A , and b i = f [a 1 , . . . , a i ] represents Duplicator's response in B to the i'th move by Spoiler. The winning condition for Duplicator in this game is that, after k rounds have been played, the induced relation These intuitions are confirmed by the following result.
Theorem 3.2. The following are equivalent: 2. Duplicator has a winning strategy for the existential Ehrenfeucht-Fraïssé game with k rounds, played from A to B.
Proof. Suppose Spoiler plays a 1 , . . . , a k , then for each i ∈ {1, . . . , k}, Duplicator responds with . . , k} for all j ≤ n. Let s i j be the minimal subsequence of s = [a 1 , . . . , a k ] that ends in a i j . Since each s i j is a subsequence of s, each pair of s i j is prefix comparable and by definition, Conversely, suppose Duplicator has a winning strategy in the n-round EF-game (with n ≤ k). For every possible set of Spoiler moves in the nround game, i.e. for every sequence s = [a 1 , . . . , a n ], there exists a sequence Let γ s be the partial homomorphism resulting from Duplicator's responses to Spoiler's play s. We define f : Since γ s is a partial homomorphism for all s ∈ E k A , f is a homomorphism. Namely, suppose s 1 , . . . , s m are such that R E k A (s 1 , . . . , s m ). By the pairwise comparability condition, there exists some ⊑-greatest s = [a 1 , . . . , a l ] with l ≤ n amongst the s i . Since s i ⊑ s, the last move of s i , ǫ A (s i ) must be in {a 1 , . . . , a l }. By the compatiblity condition, we have that

The Pebbling Comonad
We now turn to the case of pebble games. The following construction appeared in [3]. Given a structure A , we define P k A , which will represent plays of the k-pebble game on A . 2 The universe is (k × A) + , the set of finite non-empty sequences of moves (p, a), where p ∈ k is a pebble index, and a ∈ A. We shall use the notation s = [(p 1 , a 1 ), . . . , (p n , a n )] for these sequences, which may be of arbitrary length. Thus the universe of P k A is always infinite, even if A is a finite structure. This is unavoidable, by [3,Theorem 7], which shows that no finite construction is equivalent to P k , even at the level of the preorder collapse of the coKleisli category. We define ε A : P k A → A to send a play [(p 1 , a 1 ), . . . , (p n , a n )] to a n , the A-component of its last move.
Given an n-ary relation R ∈ σ, we define R P k A (s 1 , . . . , s n ) iff (1) the s i are pairwise comparable in the prefix ordering; (2) the pebble index of the last move in each s i does not appear in the suffix of s i in s j for any s j ⊒ s i ; and (3) R A (ε A (s 1 ), . . . , ε A (s n )).
Note that this differs from the definition of R E k A just in condition (2). Intuitively, Spoiler moves by placing one from a fixed set of pebbles on an element of A; Duplicator responds by placing their matching pebble on an element of the other structure. Thus there is a "sliding window" on the structures, of fixed size. It is this size which bounds the resource, not the length of the play. In particular, placing a pebble on an element implies removing it from the element on which it was previously placed. Condition (2) enforces that only the current position of a pebble is taken into account when deciding whether elements are related.
Finally, given a homomorphism f :  1. There is a homomorphism P k A → B.
2 In [3] we used the notation T k for this comonad.
2. There is a winning strategy for Duplicator in the existential k-pebble game from A to B.

The Modal Comonad
For the modal case, we assume that the relational vocabulary σ contains only symbols of arity at most 2. We can thus regard a σ-structure as a Kripke structure for a multi-modal logic, where the universe is thought of as a set of worlds, each binary relation symbol R α gives the accessibility relation for one of the modalities, and each unary relation symbol P give the valuation for a corresponding propositional variable. If there are no unary symbols, such structures are exactly the labelled transition systems widely studied in concurrency [36]. Modal logic localizes its notion of satisfaction in a structure to a world. We shall reflect this by using the category of pointed relational structures R ⋆ (σ). Objects of this category are pairs (A , a) where A is a σ-structure and a ∈ A.
Of course, the same effect could be achieved by expanding the vocabulary σ with a constant, but pointed categories appear in many mathematical contexts.
For each k ≥ 0, we shall define a comonad M k , where M k (A , a) corresponds to unravelling the structure A , starting from a, to depth k. The universe of M k (A , a) comprises the unit sequence [a], which is the distinguished element, together with all sequences of the form [a 0 , α 1 , a 1 , . . . , α j , a j ], where a = a 0 , 1 ≤ j ≤ k, and The map ε A : M k (A, a) → (A, a) sends a sequence to its last element. Unary relation symbols P are interpreted by . This is well-defined since f is a morphism by assumption.
We recall the notion of simulation between Kripke structures [10]. Given The base case a 0 b holds whenever the first condition is satisfied. It is standard that these relations are equivalently formulated in terms of a modified existential Ehrenfeucht-Fraïssé game [10,24].
Theorem 3.6. Let A , B be Kripke structures, with a ∈ A and b ∈ B, and k ≥ 0. The following are equivalent: 3. There is a winning strategy for Duplicator in the k-round simulation game from (A , a) to (B, b). Proof.
(1) ⇒ (2) We prove this by induction on k. For the base case k = 0, by (1), there exists a homomorphism, f : For the inductive step, let k ′ = k + 1 and assume there is a homomor- Applying the inductive hypothesis, we obtain that a ′ k b ′ , verifying condition 2 for a simulation. To verify condition 1, by the definition of M k ′ (A , a) and f being a homomorphism we have: (2) ⇒ (3) This is a standard result, and is detailed in section 2.7 of [10].
. We can take s as the record of the Spoiler's moves in the first k rounds of the simulation game. In this case, , and moreover, for each unary predicate , and for each unary predicate P ,

I-morphisms
Before turning to logical equivalences, there is a technical issue which needs to be addressed.
A coKleisli morphism f : Proof. Suppose f is an I-morphism, and I E k A (s, t). By definition, this means that s↑t and By the I-morphism definition, this implies f (s) = f (t), and by the interpretation of I B as the identity relation, . Hence, f preserves I, and is therefore a σ + -homomorphism. The proof of the converse is similar.
The significance of the I-morphism condition becomes apparent from the following proposition.
Proof. Let s = [a 1 , . . . , a n ] and t = [b 1 , . . . , b n ] with n ≤ k, then the partial function defined by (s, t) is γ : a i → b i . Suppose a j = a l for some j, l ≤ n and let s j , s l be the subsequences of s ending in a j , a l (respectively). Since s j ↑s l and ǫ A (s j ) = a j = a l = ǫ A (s l ), by the I-morphism condition, f (s j ) = f (s l ). By definition of f and γ, b j = b l . Hence, γ is welldefined. Suppose R ∈ σ is an m-ary relation symbol with R A (a i 1 , . . . , a im ) for a i j ∈ s and let s i j denote the prefix of s such that ǫ A (s i j ) = a i j . Since each s i j is a prefix of s, the set of all s i j is pairwise comparable, Hence, γ preserves relations, and therefore is a partial homomorphism. Similarly, define γ −1 : b i → a i , which is also well-defined and a partial homomorphism. By construction, γ and γ −1 are inverses, so (s, t) defines a partial isomorphism from A to B.
In the light of this result, the reader may wonder why we do not simply work with a sub-comonad of E k , in which only non-repeating sequences are allowed. The problem with this is that the functorial action of E k on noninjective maps will produce repeating sequences. The same problem arises with the coKleisli extension.
A similar notion of I-morphism applies to the pebbling comonad [3]. Note that, if I A is the identity relation on A , a)], s and t are comparable in the prefix order, say s ⊑ t, and the placing of p in s is still current in t. If p = p ′ , this means that two different pebbles are placed on the same element of A . We call such a sequence duplicating. Duplicating sequences are to P k what repeating sequences are to E k .
Dan Marsden and Tomáš Jakl have shown that it is possible to define a retract of the E k comonad in a more complicated fashion, which does eliminate repeating sequences. However, it is not clear how this can be extended to the pebbling comonad.
We shall develop an alternative, general approach, based on relative comonads [8]. We shall not in fact need the full generality of relative comonads. We can take advantage of the fact that our comonads are defined uniformly in the relational vocabulary. Given a relational vocabulary σ, there is a full and faithful embedding J : R(σ) → R(σ + ) such that I JA is the identity on A. We define the J-relative comonad E + k on R(σ) to have the following coKleisli category: objects are those of R(σ), morphisms from A to B are R(σ)-morphisms E I k JA → JB, where E I k is our E k construction applied to R(σ + ). The coKleisli extension and identity are defined in the evident fashion. The morphisms in this coKleisli category are exactly the I-morphisms in the coKleisli category for the comonad E k on R(σ).
In general, given a functor J : C → D, and a comonad G on D, we can obtain a relative comonad on C in this fashion [8]. In particular, this construction can be carried out in exactly the same fashion for the pebbling comonad. The coKleisli morphisms in this case are the non-duplicating morphisms.

Logical Equivalences I
We now show how our game comonads can be used to give syntax-free characterizations of a range of logical equivalences, which play a central rôle in finite model theory and modal logic.
Two equivalences can be defined uniformly for any indexed family of comonads C k : Note that there need be no relationship between these morphisms. This is simply the equivalence induced by the preorder collapse of the coKleisli category.
are isomorphic in the coKleisli category Kl(C k ). This means that there are morphisms C k A → B and C k B → A which are inverses of each other in Kl(C k ).
We introduced a number of logic fragments in Section 2.2. Each of these logics L induces an equivalence on structures in R(σ): Our aim is to characterize these equivalences in terms of our game comonads, and more specifically, to use morphisms in the coKleisli categories as witnesses for these equivalences.
We shall use the two equivalences ⇄ C k and ∼ = C k induced by comonads as described above to characterize the logical equivalences induced by the existential-positive and counting versions of these logic fragments, ∃L k and L k (#), respectively. We shall use the relative versions E + k and P + k of the Ehrenfeucht-Fraïssé and pebbling comonads, as described in the previous section. These impose the condition of being I-morphisms, which will be important to get a precise match with the winning conditions of the corresponding logical games.
We shall defer the treatment of back-and-forth equivalences to Section 10, as it will build on material to be developed later.
We now turn to a detailed study of each of our comonads in turn.

The Ehrenfeucht-Fraïssé comonad
We begin by using the I-morphism condition enforced by E + k to sharpen Theorem 3.2 from an equivalence to a bijective correspondence.
Theorem 5.1. There is a bijective correspondence between: 1. E + k coKleisli morphisms from A to B. 2. Winning strategies for Duplicator for the existential Ehrenfeucht-Fraïssé game with k rounds, played from A to B.
Proof. The proof proceeds as for Theorem 3.2, but we now use the fact that the I-morphism condition ensures that if f * (s) = t, the correspondence s i → t i is single-valued, and hence satisfies the partial homomorphism winning condition for the existential game. Conversely, a winning strategy will induce a coKleisli map satisfying the I-morphism condition.
We now recall the bijection game [26]. In this variant of the Ehrenfeucht-Fraïssé game, Spoiler wins if the two structures have different cardinality. Otherwise, at round i, Duplicator chooses a bijection ψ i between A and B, and Spoiler chooses an element a i of A. This determines the choice by Duplicator of b i = ψ i (a i ). Duplicator wins after k rounds if the relation Proposition 5.2. The following are equivalent, for finite structures A and B: 2. There is a winning strategy for Duplicator in the k-round bijection game.
Proof. Assuming (1), we have I-morphisms f : where [] is the empty sequence, and A <k is the set of sequences over A of length strictly less than k, we can define a map ψ s : A → B, by ψ s (a) = f (s[a]). This is a bijection, with inverse defined similarly from g. These bijections provide a strategy for Duplicator. Since each (s, f * (s)) is a partial isomorphism, this is a winning strategy.
Conversely, a winning strategy provides bijections ψ s , which we can use to define f by f (s[a]) = ψ s (a). The winning conditions imply that this is an I-isomorphism in the coKleisli category.
We can now state our main result on logical equivalences for the Ehrenfeucht-Fraïssé comonad.

For all finite structures
(1) In [30], it is shown that A ≡ ∃L k B iff Duplicator has a winning strategy in the k-round existential Ehrenfeucht-Fraïssé game from A to B. Combining this with Theorem 3.2 yields the result.
(2) In [26] (see also the exposition in [32][Theorem 8.13]) it is shown that A ≡ L k (#) B iff Duplicator has a winning strategy in the k-round bijection game. Combining this with Proposition 5.2 yields the result.

The Pebbling Comonad
We now state the following result, characterizing the equivalences induced by finite-variable logics L k .

The Modal Comonad
Corresponding to the graded modal logic described in Section 2.2, a notion of graded bisimulation is given in [17]. This is in turn related to resource bisimulation [14], which has been introduced in the concurrency setting. The two notions are shown to coincide for image-finite Kripke structures in [6], where it is also shown that they can be presented in a simplified form. We recall that a Kripke structure A is image-finite if for all a ∈ A and R α , Adapting the results in [6], we define approximants ∼ g k for graded bisimulation, by induction on k ≥ 0. We define a ∼ g k+1 b to hold iff: The base case, a ∼ g 0 b, holds whenever only the first condition is satisfied. We can also define a corresponding graded bisimulation game between (A , a) and (B, b).
• At round 0, the elements a 0 = a and b 0 = b are chosen. Duplicator wins if for all P , P A (a) iff P B (b), otherwise Spoiler wins.
• At round i + 1, Spoiler chooses some R α , and Duplicator chooses a bijection θ i : If there is no such bijection, Spoiler wins. Otherwise, Spoiler then chooses a i+1 ∈ R A (a i ), and b i+1 := θ i (a i+1 ). Duplicator wins this round if for all P , P A (a i+1 ) iff P B (b i+1 ), otherwise Spoiler wins.
This game is evidently analogous to the bijection game we encountered previously.
Proposition 5.5. The following are equivalent: 1. There is a winning strategy for Duplicator in the k-round graded bisimulation game between (A , a) and (B, b).
Proof. (1) ⇒ (2) We prove the statement by induction on k. For the base case k = 0, by (1), Duplicator has a winning strategy for the 0-round game, so for all P , P A (a) iff P B (b), hence a ∼ g 0 b. Let k ′ = k + 1 and assume that Duplicator has a winning strategy in the k ′ -round graded bisimulation game between (A , a) and (B, b). By the winning condition of this strategy, for all P , P A (a) iff P B (b). Moreover, for all R α , Duplicator responds to Spoiler choosing R α in the first round of the game with a bijection θ 1 : . It follows that for all a ′ ∈ R A α (a), Duplicator has a winning strategy in the k-round game from (A , a ′ ) to (B, θ 1 (a ′ )). This fact together with the inductive hypothesis shows that a ′ ∼ g k θ 1 (a ′ ). Hence, a ∼ g k ′ b.
. Therefore, f and g are inverses in the coKleisli category. Let k ′ = k + 1 and assume that a ∼ g k ′ b. We need to define coextension morphisms f * : from the inductive hypothesis and a ′ ∼ g k b ′ . Hence, there exists a coKleisli isomorphism given by the We must show that f and g are inverses. To show that, g * • f * = id M k ′ (A ,a) , there are three cases: 2. Suppose s = [a, α, a ′ ] for some R α and a ′ ∈ R A α (a): 3. Suppose s = [a, α]s ′ for some R α , a ′ ∈ R A α (a), and θ(a ′ ) = b ′ : . We must show that this determines a winning move for Duplicator, i.e. for all unary P ∈ σ, P A (a i+1 ) ⇔ P B (b i+1 ).
By f being a coKleisli isomorphism and the definition of P M k (A ,a) , we obtain the following chain of equivalences (2) It is shown in [17] and [6,Proposition 4.11] Combining this with Proposition 5.5 yields the result.

Coalgebras and combinatorial parameters
Another fundamental aspect of comonads is that they have an associated notion of coalgebra. A coalgebra for a comonad (G, ε, δ) is a morphism α : A → GA such that the following diagrams commute: Our use of indexed comonads C k opens up a new kind of question for coalgebras. Given a structure A , we can ask: what is the least value of k such that a C k -coalgebra exists on A ? We call this the coalgebra number of A . We shall find that for each of our comonads, the coalgebra number is a significant combinatorial parameter of the structure.

The Ehrenfeucht-Fraïssé comonad and tree-depth
where V is the set of vertices, and ⌢ is the adjacency relation, which is symmetric and irreflexive. A forest cover for G is a forest (F, ≤) such that V ⊆ F , and if v ⌢ v ′ , then v↑v ′ . The tree-depth td(G) is defined to be min F ht(F ), where F ranges over forest covers of G. 3 It is clear that we can restrict to forest covers of the form (V, ≤), since given a forest cover (F, ≤) of G = (V, ⌢), (V, ≤ ∩ V 2 ) is also a forest cover of G, and ht(V ) ≤ ht(F ). Henceforth, by forest covers of G we shall mean those with universe V .
Given a σ-structure A , the [ Gaifman graph] G(A ) is (A, ⌢), where a ⌢ a ′ iff for some relation R ∈ σ, for some (a 1 , . . . , a n ) ∈ R A , a = a i , a ′ = a j , a = a ′ . The tree-depth of A is td(G(A )).
Theorem 6.1. Let A be a finite σ-structure, and k > 0. There is a bijective correspondence between The second states that a j = a. Thus α : A → A ≤k is an injective map whose image is a prefix-closed subset of A ≤k . Defining a ≤ a ′ iff α(a) ⊑ α(a ′ ) yields a forest order on A, of height ≤ k. If a ⌢ a ′ in G(A ), for some a 1 , . . . , a n with a = a i , a ′ = a j , we have R A (a 1 , . . . , a n ). Since α is a homomorphism, we must have R E k A (α(a 1 ), . . . , α(a n )). By the pairwise comparability condition in the definition of R E k A , α(a i )↑α(a j ), and so a i ↑a j . Thus (A, ≤) is a forest cover of A , of height ≤ k.
Conversely, given such a forest cover (A, ≤), for each a ∈ A, its predecessors form a chain a 1 < · · · < a j , with a j = a, and j ≤ k. We define α(a) = [a 1 , . . . , a j ], which yields a map α : A → A ≤k , which evidently satisfies the coalgebra equations. If R A (a 1 , . . . , a n ), then since (A, ≤) is a forest cover, we must have a i ↑a j for all i, j, and hence α(a i )↑α(a j ). Thus α is a homomorphism.
We write κ E (A ) for the coalgebra number of A with respect to the Ehrenfeucht-Fraïssé comonad. Proof. By Theorem 6.1, for all k > 0, td(A ) ≤ k iff κ E (A ) ≤ k.

The pebbling comonad and tree-width
We review the notions of tree decompositions and tree-width. A tree (T, ≤) is a forest with a least element (the root). A tree is easily seen to be a meet-semilattice: every pair of elements x, x ′ has a greatest lower bound x ∧ x ′ (the greatest common ancestor). The path from x to x ′ is the set path(x, x ′ ) := [x∧ x ′ , x]∪ [x∧ x ′ , x ′ ], where we use interval notation: [y, y ′ ] := {z ∈ T | y ≤ z ≤ y ′ }.
A tree-decomposition of a graph G = (V, ⌢) is a tree (T, ≤) together with a labelling function λ : T → P(V ) satisfying the following conditions: The width of a tree decomposition is given by max x∈T |λ(x)| − 1. We define the tree-width tw(G) of a graph G as min T width(T ), where T ranges over tree decompositions of G.
We shall now give an alternative formulation of tree-width which will provide a useful bridge to the coalgebraic characterization. It is also interesting in its own right: it clarifies the relationship between tree-width and tree-depth, and shows how pebbling arises naturally in connection with tree-width.
A k-pebble forest cover for a graph G = (V, ⌢) is a forest cover (V, ≤) together with a pebbling function p : The following result is implicit in [3], but it seems worthwhile to set it out more clearly. Theorem 6.3. Let G be a finite graph. The following are equivalent: 1. G has a tree decomposition of width < k.
2. G has a k-pebble forest cover.
Proof. (1) ⇒ (2). Assume that G = (V, ⌢) has a tree decomposition (T, ≤, λ) of width < k. We say that a tree decomposition is orderly if it has the following property: for all x ∈ T , there is at most one v ∈ λ(x) such that for all x ′ < x, v ∈ λ(x ′ ). By Definition 13.1.11 of [29], nice tree decompositions are orderly. Moreover, by Lemma 13.1.12 of [29], the existence of a tree decomposition implies the existence of a nice tree decomposition of the same width. Hence, the existence of a tree decomposition implies the existence of an orderly one of the same width, and without loss of generality we can assume that the given tree decomposition is orderly.
For any v ∈ V , the set of x ∈ T such that v ∈ λ(x) is non-empty by (TD1), and closed under meets by (TD3). Since T is a tree, this implies that this set has a least element τ (v). This defines a function τ : V → T . The fact that the tree decomposition is orderly implies that τ is injective. We can define an order on V by . This is isomorphic to a sub-poset of T , and hence is a forest order.
We define p : V → k by induction on this order. Assuming p(v ′ ) is defined for all v ′ < v, we consider τ (v). Since the tree decomposition is orderly, this means in particular that p(v ′ ) is defined for all v ′ ∈ S := λ(τ (v)) \ {v}. Since the decomposition is of width < k, we must have |S| < k. We set p(v) To verify that (V, ≤) is a forest cover, suppose that v ⌢ v ′ . By (TD2), for some Finally, we must verify the condition on the pebbling function p. Suppose ). By construction of the pebbling function, this implies p(v) = p(w).
(2) ⇒ (1). Suppose that (V, ≤, p) is a k-pebble forest cover of G. We define a tree T = V ⊥ by adjoining a least element ⊥ to V . We say that v ′ is an active predecessor of v if v ′ ≤ v, and for all w ∈ (v ′ , v], p(v ′ ) = p(w). We define the labelling function by setting λ(v) to be the set of active predecessors of v; λ(⊥) We verify the tree decomposition conditions. (TD1) holds, Then v is an active predecessor of both v 1 and v 2 . This implies that for all w ∈ path(v 1 , v 2 ), v is an active predecessor of w, and hence v ∈ λ(w).
Theorem 6.4. Let A be a finite σ-structure. There is a bijective correspondence between: 1. P k -coalgebras α : A → P k A 2. k-pebble forest covers of G(A ).

Proof. See [3, Theorem 6].
We write κ P (A ) for the coalgebra number of A with respect to the pebbling comonad.

The modal comonad and synchronization tree height
Let A be a Kripke structure. It will be convenient to write labelled transitions a α → a ′ for R α (a, a ′ ). Given a ∈ A, the submodel generated by a, denoted S a , is obtained by restricting the universe to the set S a of a ′ such that there is a path a α 1 → · · · α k → a ′ . This submodel forms a synchronization tree [35] if for all a ′ , there is a unique such path. The height of such a tree is the maximum length of any path from the root a. Proposition 6.6. Let A be a Kripke structure, with a ∈ A. The following are equivalent: 1. There is a coalgebra α : (S a , a) → M k (S a , a).

S a is a synchronization tree of height ≤ k.
Proof. Suppose there is a coalgebra α : (S a , a) → M k (S a , a). For a ′ ∈ S a , let α(a ′ ) = [a 0 , α 1 , a 1 , . . . , α j , a j ] where a 0 = a. The first coalgebra equation states that α(a i ) = [a 0 , α 1 . . . , α i , a i ] for 0 ≤ i ≤ j. The second coalgebra equation states that a j = a ′ . Therefore, α is injective. By injectivity, the path of transitions determined by α(a ′ ), i.e. a α 1 → a 1 · · · α j → a ′ is unique. Hence, every a ′ ∈ S a has a unique path from a, so the submodel generated by a is a synchronization tree. Since j ≤ k, the height of the tree is at most k.
Conversely, suppose S a is a synchronization tree of height ≤ k, then for every a ′ in this submodel, there exists a unique path of transitions a α 1 → · · · α j → a ′ . We can define the morphism α : (S a , a) → M k (S a , a) as α(a ′ ) = [a, α 1 , a 1 , . . . , α j , a ′ ]. Since the path of transitions is unique, the first coalgebra equation is satisfied. Moreover, since the last element of α(a ′ ) is a ′ , the second coalgebra equation is satisfied.
We define the modal depth md(A , a) = k if the submodel S a generated by a is a synchronization tree of height k. Theorem 6.7. Let A be a Kripke structure, and a ∈ A be such that the submodel generated by a is a synchronization tree of finite height. Then md(A , a) = κ M (A , a).
Note the conditional nature of this result, which contrasts with those for the other comonads. The modal comonad is defined in such a way that the universe M k (A, a) reflects information about the possible transitions. Thus having a coalgebra at all, regardless of the value of the resource parameter, is a strong constraint on the structure of the transition system.

Characterization of Rossman-type equivalences
As a simple application of the results of the previous section, we show how they yield characterizations of some approximation preorders on structures, and their associated equivalences.
We begin with a completely general result. Given objects A, B of a category C, we shall use the notation A → B to mean that there exists a morphism from A to B in C.
Proposition 7.1. Let G be a comonad on a category C. For all objects A, B of C, the following are equivalent: Proof. Suppose f : GA → B, α : C → GC is a coalgebra, and g : C → A.
Conversely, suppose that for all coalgebras α : C → GC, C → A implies C → B. Then since δ A : GA → GGA is a coalgebra, and ε A : GA → A, we conclude that GA → B.
Rossman defined the following preorder in [41]: The associated equivalence ⇄ k plays a major role in [41], as a resource-bounded approximation to homomorphism equivalence.
We can similarly define A → P k B in terms of treewidth: As an immediate consequence of Proposition 7.1 and the results of the previous section, we obtain:

Coalgebras and conjunctive queries
We shall now connect coalgebras with logic. We will show that they are closely related to conjunctive queries. We shall focus on boolean conjunctive queries, i.e. closed formulas built from atomic formulae using only conjunction and existential quantification. We allow the empty conjunction ⊤. Given a finite structure A with universe A = {a 1 , . . . , a n }, the canonical conjunctive query for A is a formula Q A := ∃v 1 , . . . , v n . {R( v) | R ∈ σ, a ∈ R A }. Here the correspondence v i ↔ a i uses the linear ordering on the universe implicitly given by the enumeration.
The key property of the canonical conjunctive query is the following [12]: We now consider a number of rewrite rules on formulas: Note that (R1) amounts to taking formulas as a commutative monoid under the binary operation of conjunction, with ⊤ as the identity.
As usual, we can use a rule θ χ to rewrite a formula C[θ] to C[χ]. We write ϕ ։ E ψ if ϕ can be rewritten to ψ in some finite number of steps using rules (R1)-(R3).
Theorem 8.2. Let A be a finite structure, and Q A its canonical conjunctive query. The following are equivalent: Proof. Assuming (2), we can define a forest order on A, with a i < a j if v j occurs in the scope of v i in ϕ. Since the quantifier rank of ϕ is ≤ k, so is the height of this order. Moreover, condition (E) is obviously satisfied by the order induced by Q A , and is preserved by applications of the rules (R1)-(R3). In particular, in applying (R2), the free variable condition implies that no elements which become incomparable in the corresponding order are adjacent in the Gaifman graph. By induction on the length of the rewrite sequence, we conclude that the order induced by ϕ is a forest cover, and hence, by Theorem 6.1, determines an E k -coalgebra on A .
For the converse, we argue by induction on the cardinality of A, or equivalently on the number n of variables in Q A . We prove the following statement Φ(n) by induction on n: For all finite relational vocabularies σ, and for all σ-structures A of cardinality n, if A has a forest cover of height k, then Q A ։ E ϕ, where the quantifier rank of ϕ is ≤ k.
The base case n = 1 is trivial. Now consider We assume that the variables are in an order which linearizes the given forest order on A. In particular, v j+1 , . . . , v n are the leaves (maximal elements) of maximum height k in the forest order. Note that if v and v ′ are leaves, they cannot be adjacent in the Gaifman graph of A , since this would violate the forest cover condition. Hence we can partition I as I = I j+1 ⊔ · · · I n ⊔ L, where I p is the set of indices labelling atomic formulas in which v p occurs, p = j + 1, . . . , n. Using (R1) and (R2), we can rewrite Q A to where χ p := ∃v p . j∈Ip R j ( v j ) and θ := l∈L R l ( v l ). We now define where R p is a new relation symbol, and w p lists all the variables other than v p occurring in χ p . This formula ϕ ′ is the canonical conjunctive query for a new structure A ′ , of cardinality j < n. There are many new adjacencies in the Gaifman graph of A ′ compared with that for A . However, note that, since (the element of A labelled by) each v p was maximal in the given forest cover of A , the set of variables adjacent to v p must be linearly ordered in that forest cover. Hence the restriction of the forest cover on A to {v 1 , . . . , v j } is a forest cover on A ′ , of height k −1. Our induction hypothesis can be applied to this forest cover on A ′ as a σ ′ -structure, where σ ′ = σ ∪ {R p | p = j + 1, . . . , n}, yielding a rewrite ϕ ′ ։ E ψ ′ , where ψ ′ has quantifier rank m < k. We can perform the same rewrite steps to obtain ϕ ։ E ψ, where ψ results from ψ ′ by replacing each R p ( w) by χ p . We have Q A ։ E ϕ ։ E ψ. Moreover, the quantifier rank of ψ is m + 1 ≤ k, as required.
We can think of (R1)-(R3) as encoding a non-deterministic algorithm for computing the minimum quantifier rank for Q A (and hence the tree-depth of A ). We use (R3) to guess an order on the variables, and then apply (R1) and (R2) to the quantifier prefix from the inside out. The above argument shows that this algorithm does, for some choice of order, find the minimum quantifier rank.
We can give a very similar analysis for the pebbling case. We define ϕ ։ P ψ if ϕ can be rewritten to ψ in some finite number of steps using rules (R1), (R2), and (R4). This set of rules is widely used in query optimization [16,44]. Theorem 8.3. Let A be a finite structure, and Q A its canonical conjunctive query. The following are equivalent: Proof. This is the statement of Theorem 27 in [3].
For the modal case, we moved to the category of pointed Kripke structures. Syntactically, this corresponds to modifying the canonical conjunctive query to have one free variable; we write this as Q a (x). Note that we can rearrange the block of existential quantifiers in Q A using rule (R3) so that ∃x is the leftmost existential quantifier. Hence, we could write Q A as ∃xQ a (x), if ϕ can be rewritten to ψ(x) in some finite number of steps using rules (R1)-(R4).
Theorem 8.4. Let A be a finite Kripke structure with distinguished world a ∈ A . The following are equivalent: 1. S a has a coalgebra (S a , a) → M k (S a , a) 2. Q a (x) ։ M ϕ where ϕ is a multi-modal logic sentence of modal-depth ≤ k and · is the standard translation map into first-order logic.
Proof. The proof is similar to the proof of 8.2, but takes into account the labels of the accessibility relations that guard quantifiers in translated modal formulas.
Assuming (2), let φ(x) = ϕ be the image of modal sentence ϕ under the standard translation. Through repeated applications of (R4), we can assume that every variable in φ(x) is distinct. For a ′ ∈ A , we can define α i (a ′ ) by induction on the number of variables i in scope of v ′ where v ′ is the variable assigned to a ′ in the assignment witnessing (A , a) Q a (x). For the base case of 0, we set α 0 (a ′ ) = [a ′ ]. For the inductive step, suppose v i+1 occurs in the scope of v ′ , then there must exist some subformula of φ(x) of the form ∃v i+1 (R β i+1 (v i+1 , v i ) ∧ χ). By the inductive, hypothesis, we have defined α i (a ′ ) = s. Hence, we define α i+1 (a ′ ) = [a i+1 , β i+1 ]s where a i+1 corresponds to v i+1 in the assignment witnessing (A , a) Q a (x). Since ϕ has modal depth at most k, the sequence of transitions in α k (a ′ ) has length at most k (where we count one for each labelled transition). Finally, we define α(a ′ ) = α i (a ′ ) where i is the number of variables in the scope of v ′ . The counit axiom states that the last element of α(a ′ ) is a ′ . By construction, α i (a ′ ) has α j (a ′ ) as a suffix, with 0 ≤ j < i. By the base case, α 0 (a ′ ) = [a ′ ], therefore the last element of α i (a ′ ) is a ′ as desired. The comultiplication axiom states that if α(a ′ ) = [a, β 0 , . . . , β i , a ′ ], then α(a j ) = [a, β 0 , . . . , β j , a j ] for all j ∈ i. By the construction of α i (a ′ ), it follows that the variable v j corresponding to a j is in the scope of v ′ . Therefore, α j (a j ) = α(a j ) = [a, β 0 , . . . , β j , a j ].
For the converse, by proposition 6.6, it suffices to show that: for every a ∈ A , if S a is a synchronization tree of height ≤ k, then Q a (x) ։ M φ(x) where φ(x) = ϕ for some modal sentence ϕ of depth ≤ k. We prove this statement by induction on k. For the base case k = 0, we can conclude that S a is such that R Sa α is empty for every R α ∈ σ. Therefore, Q a (x) is a conjunction of unary atoms P ∈ σ that a satisfies. We can take φ(x) = Q a (x) and ϕ would be a conjunction of the propositional variables corresponding to the satisfied unary relations. For the inductive step, suppose S a is a synchronization tree of height ≤ k + 1, then we can successively apply (R1) and (R2), so that φ(x) is a conjunction of formulas of two forms: 1. ∃y(R β (x, y) ∧ Q b (y)), for some y corresponding to b such that a β → b 2. P (x) for some unary P ∈ σ such that P A (a) Applying the inductive hypothesis to S b and replacing Q b (y) with its rewrite χ(y) yields the desired φ(x). By the inductive hypothesis χ(y) = ρ for some modal sentence ρ of depth ≤ k, then ϕ, such that ϕ = φ , can be seen as a conjunction of sentences of the form ♦ β ρ and propositional variables p (corresponding to each type of conjunct in φ(x)).

Characterization of Eilenberg-Moore categories
Monads and comonads are closely related to adjunctions. We recall that an adjunction are mutually inverse. Each such adjunction gives rise to a monad on C, and a comonad on D. The comonad is (G, ε, δ), where G = LR, and δ B : LRB → LRLRB is given by δ B = L(η RB ).
Conversely, every comonad arises from an adjunction, known as a resolution of the comonad, in this way. In fact, there is a category of such resolutions for a given comonad G. The minimal (initial) resolution is the adjunction associated with the coKleisli category Kl(G), while the maximal (terminal) resolution arises from the category of coalgebras of G, also known as the Eilenberg-Moore category EM(G) [20].
We have already studied the structure of the coalgebras for our game comonads. We shall now complete this analysis, by characterising the Eilenberg-Moore categories in terms independent of the comonads which give rise to them. This will give a new perspective on these constructions, as universal solutions to the problem of building various kinds of resourcebounded tree-structured covers of a given relational structure.

The Ehrenfeucht-Fraïssé adjunction
We define a tree-ordered σ-structure (A , ≤) to be a σ-structure A with a forest order ≤ on A, satisfying the following condition: , the Gaifman graph of A as a σ-structure, then a↑b.
Note that such a structure is the same thing as a forest cover of A with universe A. We write the covering relation of ≤ as ≺. A morphism of treeordered σ-structures f : (A , ≤) → (B, ≤ ′ ) is a σ-homomorphism f : A → B which maps roots to roots, and preserves the covering relation. This determines a category R E (σ). For each k > 0, if we restrict to forest orders of height ≤ k, we get a sub-category R E k (σ).
Theorem 9.1. For each k > 0, the Eilenberg-Moore category EM(E k ) is isomorphic to R E k (σ). Proof. By Theorem 6.1, the objects of the two categories are in bijective correspondence. Thus it remains to show that a σ-homomorphism f : A → B is an E k -coalgebra morphism iff it is an R E k (σ) morphism. From the analysis in Theorem 6.1, if α : A → E k A is a coalgebra, then α(a) = [a 1 , . . . , a k ] iff a 1 ≺ · · · ≺ a k = a is the covering chain of predecessors of a in the forest order. Thus a coalgebra morphism preserves covering chains, and in particular preserves roots and the covering relation. Conversely, if a morphism preserves roots and the covering relation, then it preserves covering chains, and hence is a coalgebra morphism.
As an immediate consequence of this result, we can describe the canonical resolution of E k given by the adjunction between R(σ) and EM(E k ) in terms of R E k (σ). There is an evident forgetful functor U k : R E k (σ) → R(σ), which simply forgets the forest order.
Theorem 9.2. The functor U k has a right adjoint given by G k , where G k (A ) = (E k A , ⊑). The comonad arising from this adjunction is E k .

The pebbling adjunction
We define a k-pebble tree-ordered σ-structure (A , ≤, p) to be a σ-structure A with a forest order ≤ on A, and a pebbling function p : A → k. In addition to condition (E), it must also satisfy the following condition: (P) if a ⌢ b in G σ (A ), and a < b in the forest order, then for all x ∈ (a, b], p(a) = p(x).
Morphisms of these structures are morphisms of tree-ordered structures which additionally preserve the pebbling function. These define a category R P k (σ) (where k bounds the number of pebbles, rather than the height of the forest order), and there is an evident forgetful functor V k : R P k (σ) → R(σ). Theorem 9.3. For each k > 0, the Eilenberg-Moore category EM(P k ) is isomorphic to R P k (σ). Proof. The proof proceeds on similar lines to that of Theorem 9.1. By Theorem 6.4, the objects of the two categories are in bijective correspondence. Thus to complete the argument, we must show that coalgebra morphisms coincide with R P k (σ)-morphisms. Coalgebra morphisms preserve covering chains, and also preserve pebble indices, and this is equivalent to the conditions for R P k (σ)-morphisms. Once again, there is an immediate corollary to this result.  1 , a 1 ), . . . , (p j , a j )]) = p j . Moreover, P k is the comonad arising from this adjunction.

The modal adjunction
Let σ be a modal vocabulary. We define a modal σ-structure (A , a, ≤) to be a σ-structure A with a partial order ≤ on A, such that ↑(a) := {a ′ ∈ A | a ≤ a ′ } is a tree order. This must satisfy the following condition: A morphism of such structures is a σ-homomorphism preserving the root and the covering relation. For each k > 0, there is a category R M k (σ), with k bounding the height of the tree order, and a forgetful functor W k : R M k (σ) → R ⋆ (σ), which sends (A , a, ≤) to (A , a).
Theorem 9.6. For each k > 0, the functor W k has a right adjoint, which sends (A , a) to (M k A , [a], ⊑). Moreover, M k is the comonad arising from this adjunction.
We have stated the result in this fashion for uniformity with the other cases, but it is worth noting that a simpler analysis applies in this case. 5 The modal comonad is idempotent, i.e. the comultiplication is an isomorphism. This means that it encodes a coreflective subcategory. The category of trees R M k (σ) is coreflective in the category of all pointed Kripke structures (see e.g. [48]), and the modal comonad arises from this coreflection.

I-morphisms and relative adjunctions
To fit I-morphisms, as discussed in section 4, into this picture, we shall use relative adjunctions [45]. Recall that given functors J : B → D and L : C → D, we say that L has a J-right adjoint R : B → C if there is a natural isomorphism hom D (L(−), J(−)) ∼ = hom C (−, R(−)).
In particular, if L has a bona fide right adjoint R : D → C, we obtain a J-right adjoint by composing R with J.
In our case, we have the functor J : R(σ) → R(σ + ), and we obtain relative versions of the Ehrenfeucht-Fraïssé and pebbling adjunctions, again using the fact that our constructions are uniform in the relational vocabulary, and hence can be applied to R(σ + ). These relative right adjoints give rise to the relative comonads E + k and P + k .
10 Logical Equivalences II: Open pathwise embeddings and back-and-forth equivalences For each comonad C k , we shall now define a "back-and-forth" equivalence ↔ C k , intermediate between ⇄ C k and ∼ = C k , and use it to characterize the logical equivalences induced by L k . These back-and-forth equivalences will be more specific to "game comonads" defined on R(σ), but they will still be defined and shown to have the appropriate properties in considerable generality. We shall use a variant of the well-known notion of open map bisimulation of Joyal, Nielsen and Winskel [28].
Although it is folklore that Ehrenfeucht-Fraïssé equivalence is "essentially" a form of bisimulation, to our knowledge this is the first time that graded elementary equivalences have been captured in a precise common format with open map bisimulations. The key novel ingredient in our approach is the use of embeddings, and the notion of pathwise embedding. This allows us to capture a general notion of property-preserving bisimulation, which specializes to capture all the notions of interest for model comparison games.
Referring to our study of adjunctions characterizing the game comonads in Section 9, we can extract the following common structure. For each comonad C k (variously E k , P k , or M k ), we have a category R C k , and a commuting diagram of categories and functors: Here Trees is the category of tree orders and maps which preserve the root and the covering relation. The unlabelled arrows are the evident faithful forgetful functors. The faithful functor U k has a right adjoint F k , and C k arises from this adjunction. Note that the Ehrenfeucht-Fraïssé and pebbling comonads produce forests of non-empty sequences rather than trees. However, it is always possible, and often convenient, e.g. for the base case of an inductive proof, to turn the forests into trees by adding the empty sequence. This is justified by the fact that Forests, the category of forest orders and maps which take roots to roots, and preserve the covering relation, is equivalent to Trees.
The above description applies directly to the Ehrenfeucht-Fraïssé and pebbling cases. For the modal case, we should use R ⋆ (σ) rather than R(σ). In this case, the construction produces a tree directly.
We recall the notion of I-morphism from Section 4. We shall build this into the current picture by working with the J-relative versions of the Ehrenfeucht-Fraïssé and pebbling adjunctions, as in section 9.4. This means that objects of R C k carry an interpretation of the I-relation, which morphisms of R C k must preserve. The right adjoint functor F k produces a relation I F k A by the functorial action of F k on the identity relation I A .
A morphism e in R C k is an embedding if U k (e) is an extremal mono in R(σ), i.e. an embedding of relational structures. We write e : A B to indicate that e is an embedding.
We define a subcategory Paths of R C k whose objects have tree orders which are linear, so they comprise a single branch. If P is a path, I P is the identity relation. Morphisms of paths are embeddings. More generally, we say that e : P A is a path embedding if P is a path. A morphism f : A → B in R C k is a pathwise embedding if for any path embedding e : P A , f • e is a path embedding.
We This is often referred to as the path-lifting property. If we think of f as witnessing a simulation of A by B, path-lifting means that if we extend a given behaviour in B (expressed by extending the path P to Q), then we can find a matching behaviour in A to "cover" this extension. Thus it expresses an abstract form of the notion of "p-morphism" from modal logic [10], or of functional bisimulation.
We can now define the back-and-forth equivalence A ↔ C k B between structures in R(σ). This holds if there is a structure R in R C k , and a span of open pathwise embeddings This gives us a general, structural description of back-and-forth equivalence.
At the same level of generality, we shall now define a back-and-forth game G k (A , B) played between the structures A and B, corresponding to the comonad C k . Positions of the game are pairs (s, t) ∈ C k A × C k B.
We define a relation W(A , B) ⊆ C k A × C k B as follows. A pair (s, t) is in W(A , B) iff for some path P , path embeddings e 1 : P A and e 2 : P B, and p ∈ P , s = e 1 (p) and t = e 2 (p). The intention is that W (A , B) picks out the winning positions for Duplicator.
At the start of each round of the game, the position is specified by (s, t) ∈ C k A × C k B. The initial position is (⊥, ⊥). The round proceeds as follows. Either Spoiler chooses some s ′ ≻ s, and Duplicator must respond with t ′ ≻ t, resulting in a new position (s ′ , t ′ ); or Spoiler chooses some t ′′ ≻ t and Duplicator must respond with s ′′ ≻ s, resulting in (s ′′ , t ′′ ). Duplicator wins the round if they are able to respond, and the new position is in W (A , B).
Theorem 10.1. The following are equivalent: There is a winning strategy for Duplicator in the G k (A , B) game.
Proof. (1) ⇒ (2). Firstly, consider an open pathwise embedding q : R → F k B. Since q is a morphism in R C k , any covering chain ⊥ ≺ r 1 ≺ · · · ≺ r i in R is mapped to a covering chain ⊥ ≺ s 1 ≺ · · · ≺ s i in F k B. Since ⊥ ≺ r 1 ≺ · · · ≺ r i is the image of a path embedding P R, and q is a pathwise embedding, for each j with 1 ≤ j ≤ i, (r j , s j ) ∈ W (A , B).
Claim For any s i+1 ≻ s i ∈ F k B, there is r i+1 ≻ r i ∈ R such that q(r i+1 ) = s i+1 .
To prove this, note that there are path embeddings e 1 : P R and e 2 : Q F k B with images ⊥ ≺ r 1 ≺ · · · ≺ r i and ⊥ ≺ s 1 ≺ · · · ≺ s i ≺ s i+1 respectively. Writing Q ≤i for the truncation of Q to the preimage of ⊥ ≺ s 1 ≺ · · · ≺ s i , R i for the image of e 1 , and (F k B) i for the image of e 2 | Q ≤i , we have an embedding e : P ∼ = R i ∼ = (F k B) i ∼ = Q ≤i Q, such that q • e 1 = e 2 • e. Since q is open, there is an embedding Q R such that We define r i+1 to be the image of the greatest element of Q under this embedding. Since Q is a chain, r i+1 ≻ r i . By the commutativity of the above diagram, q(r i+1 ) = s i+1 . Now suppose we have a span of open pathwise embeddings For any path embedding P R with image ⊥ ≺ r 1 ≺ · · · ≺ r i , we have a pair (s, t) = (p(r i ), q(r i )) in C k A × C k B. Since p and q are pathwise embeddings, (s, t) ∈ W (A , B). Moreover, for any t ′ ≻ t, we can find r i+1 ≻ r i and s ′ ≻ s such that (p(r i+1 ), q(r i+1 )) = (s ′ , t ′ ) by the above Claim. A symmetric argument applies to yield an extension for any s ′ ≻ s. Thus the set of such pairs (s, t) yields a winning strategy for Duplicator in the G k (A , B) game.
(2) ⇒ (1). Suppose we have a winning strategy for Duplicator. This determines a set R ⊆ C k A × C k B of the plays following this strategy.
R is a down-closed subset of a tree, and hence forms a tree in the induced order. It determines a substructure of the product relational structure F k A × F k B, and hence an object R in R C k . Restricting the projections to R determines morphisms p : Firstly, we show that p and q are pathwise embeddings. Given a path embedding e : P R, p • e is an injective homomorphism, since it is a morphism in R C k , and preserves the covering relation. It remains to show that p • e, or equivalently the restriction of p to the image of e, is strong. Given (s 1 , t 1 ), . . . , (s n , t n ) in the image of e, let s be the maximum of the s i , which exists since the image of a path forms a chain. If s = s j , then t j is the maximum of the t i . Now since (s, t) ∈ W (A , B), there is a path Q, and embeddings e 1 : Q F k A , e 2 : Q F k B, with s = e 1 (r) and t = e 2 (r) for some r ∈ Q. For each i, there is a unique element r i ∈ Q such that e 1 (r i ) = s i and e 2 (r i ) = t i . For an n-ary relation R in σ, since e 1 and e 2 are embeddings, we have R F k A (s 1 , . . . , s n ) ⇐⇒ R Q (r 1 , . . . , r n ) ⇐⇒ R F k B (t 1 , . . . , t n ).
Finally, we must show that these morphisms are open. Suppose we are given a diagram P Q We consider the case where Q extends P by one element; the general case will then follow by induction. Let the image of the maximum element of P be (s, t), and the image of the maximum element of Q be s ′ ≻ s. Since R encodes the plays of a winning strategy for Duplicator, for some t ′ ≻ t, we have (s ′ , t ′ ) ∈ R, and moreover (s ′ , t ′ ) ∈ W (A , B). This implies that the map which extends the embedding P R by sending the maximum element of Q to (s ′ , t ′ ) determines an embedding Q R, which makes the path-lifting diagram commute.
The fact that q is open is shown by a symmetric argument.
For each of our three comonads, we will show that the game G k specializes to exactly the expected concrete game: Ehrenfeucht-Fraïssé , pebbling, and modal bisimulation respectively. The connections with the corresponding logical equivalences will follow as immediate corollaries.

The Ehrenfeucht-Fraïssé comonad
We now show that the generic game G k , when instantiated to the Ehrenfeucht-Fraïssé adjunction and comonad, yields exactly the standard EF-game.
We begin with two observations we will use. Proof. Since e is an I-morphism, it must reflect the I relation, while at the same time, it is injective. This implies that I F k A must be the identity relation on the image of e, or equivalently, that the image of e must contain only non-repeating sequences. Proof for some a ∈ A, we see from the definition of G k (A , B) for the Ehrenfeucht-Fraïssé comonad that it coincides with the Ehrenfeucht-Fraïssé game, provided we can show, for (s, t) ∈ E k A × E k B, that (s, t) ∈ W(A , B) iff (s, t) satisfies the winning condition for the Ehrenfeucht-Fraïssé game. We recall that this winning condition is that the relation s i → t i is a partial isomorphism between A and B.
Firstly, suppose that (s, t) ∈ W(A , B), via path embeddings e 1 : P E k A , e 2 : P E k B. This implies that the image of e 1 , consisting of the prefixes of s, is isomorphic to the image of e 2 , consisting of the prefixes of t. Applying lemmas 10.2 and 10.3, we conclude that (s, t) determine a partial isomorphism between A and B, as required.
For the converse, note that for any (s, t) following a winning strategy for Duplicator in the Ehrenfeucht-Fraïssé game, the correspondence s i → t i must be a partial isomorphism, and in particular a bijection. Hence Duplicator must always give the same response to repetitions of a given move by Spoiler. It follows that the behaviour of the strategy is determined by its restriction to non-repeating sequences, and without loss of generality, we can restrict the strategy to non-repeating sequences (s, t). The prefixes of s form an induced substructure of E k A which, applying lemma 10.2, is isomorphic to the substructure of E k B induced by the prefixes of t. Hence these substructures are the images of path embeddings with a common domain, and (s, t) ∈ W(A , B). Remark If we drop the I-morphism requirement on embeddings, we obtain a weaker notion of equivalence, in which the winning condition is that we have a partial correspondence rather than a partial isomorphism. This yields a characterization of elementary equivalence for equality-free logic [11].

The pebbling comonad
The analysis for the pebbling comonad is largely similar to that for the Ehrenfeucht-Fraïssé comonad.
Firstly, given s = [(p 1 , a 1 ), . . . , (p i , a i )] ∈ P k A , and p ∈ {p 1 , . . . , p i }, we define last p (s) = a, where s = s 1 [(p, a)]s 2 , and p does not occur in s 2 . We say that s is non-duplicating if for all s ′ ⊑ s, last p (s ′ ) = last p ′ (s ′ ) ⇒ p = p ′ . Thus we never have two pebbles placed on the same element.
Given s = [(p 1 , a 1 ), . . . , (p i , a i )] ∈ P k A and t = [(p 1 , b 1 ), . . . , (p i , b i )] ∈ P k B, we define γ(s, t) := {(last p (s), last p (t)) | p ∈ {p 1 , . . . , p i }} ⊆ A × B. The prefix of s (respectively t) of length j is denoted s j (respectively t j ). The winning condition on plays (s, t) ∈ P k A × P k B for the pebbling game is that for each j, γ(s j , t j ) is a partial isomorphism between A and B.
The following results play the role for the pebbling comonad of Lemmas 10.2 and 10.3 for the Ehrenfeucht-Fraïssé comonad.
Lemma 10.6. If s and t are non-duplicating, then the following are equivalent: 1. For all j, γ(s j , t j ) is a partial isomorphism from A to B.
2. The substructure P s of P k A determined by the prefixes of s is isomorphic to the substructure P t of P k B determined by the prefixes of t.
, and for all 0 ≤ j ≤ i, and unary predicates P , P A (a j ) iff P B (b j ). Note that there is no bijection requirement. This is why I-morphisms are not needed in the modal case. The initial position is ([a], [b]). If we have reached position (s, t) after k rounds, then round k + 1 proceeds as follows: Spoiler either chooses s ′ ≻ s, and Duplicator must respond with t ′ ≻ t, producing the new position (s ′ , t ′ ); or Spoiler chooses t ′′ ≻ t, and Duplicator must respond with s ′′ ≻ s, producing the new position (s ′′ , t ′′ ). Duplicator wins the round if they are able to respond, and the new position satisfies the winning condition.
Note that s ′ ≻ s iff s ′ = s[α, a ′ ] for a transition relation R α and a ′ ∈ A such that R A α (a, a ′ ), where a = ε A (s). The following standard result is essentially immediate from the definitions. −→ r i , s i = [a 0 , α 1 , a 1 , α 2 , a 2 , . . . , α i , a i ], with a = a 0 , and for all unary P , and 0 ≤ j ≤ i, P Q (r i ) ⇐⇒ P A (a i ). Chaining these equivalences for a span of path embeddings shows the equivalence of the winning conditions for G k (A , B) and the modal bisimulation game.

Further Directions
From the categorical perspective, there is considerable additional structure which we have not needed for the results in this paper, but which may be useful for further investigations.
Coequaliser requirements In Moggi's work on computational monads, there is an "equaliser requirement" [37]. The dual version for a comonad (G, ε, δ) is that for every object A, the following diagram is a coequaliser: This says in particular that the counit is a regular epi, and hence GA "covers" A in a strong sense. This coequaliser requirement holds for all our comonads. For E k , this is basically the observation that, given a sequence of sequences [s 1 , . . . , s j ], we have ε[εs 1 , . . . , εs j ] = εs j . The other cases are similar.
Indexed and graded structure Our comonads E k , P k , M k are not merely discretely indexed by the resource parameter. In each case, there is a functor (Z + , ≤) → Comon(R(σ)) from the poset category of the positive integers to the category of comonads on R(σ). Thus if k ≤ l there is a natural transformation with components i k,l A : E k A → E l A , which preserves the counit and comultiplication; and similarly for the other comonads. Concretely, this is just including the plays of up to k rounds in the plays of up to l rounds, k ≤ l.
Another way of parameterizing comonads by resource information is grading [22]. Recall that comonads on C are exactly the comonoids in the strict monoidal category ([C, C], •, I) of endofunctors on C [33]. Generalizing this description, a graded comonad is an oplax monoidal functor G : (M, ·, 1) → ([C, C], •, I) from a monoid of grades into this endofunctor category. This means that for each m ∈ M , there is an endofunctor G m , there is a graded counit natural transformation ε : G 1 ⇒ I, and for all m, m ′ ∈ M , there is a graded comultiplication δ m,m ′ : G m·m ′ ⇒ G m G m ′ .
The two notions can obviously be combined. We can see our comonads as (trivially) graded, by viewing them as oplax monoidal functors (Z + ∞ , ≤, min, ∞) → ([C, C], •, I). Given k ≤ l, we have e.g. E k ⇒ E k E k ⇒ E k E l . The unit is interpreted using the ω-colimit E ω , as described in the following paragraph.
The question is whether there are interesting graded structures which arise naturally in considering richer logical and computational situations in our setting.
Colimits and infinite behaviour In this paper, we have dealt exclusively with finite resource levels. However, there is an elegant means of passing to infinite levels. We shall illustrate this with the modal comonad. Using the inclusion morphisms described in the previous discussion of indexed structure, for each pointed structure (A , a) we have a diagram M 1 (A , a) → M 2 (A , a) → · · · → M k (A , a) → · · · By taking the colimits of these diagrams, we obtain a comonad M ω , which corresponds to the usual unfolding of a Kripke structure to all finite levels.
This will correspond to the bisimulation approximant ∼ ω , which coincides with bisimulation itself on image-finite structures [27]. Transfinite extensions are also possible. Similar constructions can be applied to the other comonads. This provides a basis for lifting the comonadic analysis to the level of infinite models.
Relations between fragments and parameters We can define morphisms between the different comonads we have discussed, which yield proofs about the relationships between the logical fragments they characterize. This categorical perspective avoids the cumbersome syntactic translations in the standard proofs of these results. For illustration, there is a comonad morphism t : E k ⇒ P k with components t A : E k A → P k A given by [a 1 , . . . , a j ] → [ (1, a 1 ), . . . , (j, a j )]. Together with theorems 5.4 and 5.3, this shows that ∃L k ⊆ ∃L k and L k (#) ⊆ L k (#). Moreover, composing t with a coalgebra A → E k A yields a coalgebra A → P k A , demonstrating that tw(A ) + 1 ≤ td(A ).

Concluding remarks
Our comonadic constructions for the three major forms of model comparison games show a striking unity, on the one hand, but also some very interesting differences. For the latter, we note the different forms of logical "deception" associated with each comonad, the finite character of E k and M k and the non-finite character of P k , and the different combinatorial parameters which arise in each case.
One clear direction for future work is to gain a deeper understanding of what makes these constructions work. Another is to understand how widely the comonadic analysis of resources can be applied. We are currently investigating the guarded fragment [9,24]; other natural candidates include existential second-order logic, and branching quantifiers and dependence logic [47].
Since comonads arise naturally in type theory and functional programming [46,39], can we connect the study of finite model theory made here with a suitable type theory? Can this lead, via the Curry-Howard correspondence, to the systematic derivation of some significant meta-algorithms, such as decision procedures for guarded logics based on the tree model property [23], or algorithmic metatheorems such as Courcelle's theorem [15]?
Another intriguing direction is to connect these ideas with the graded quantum monad studied in [2], which provides a basis for the study of quan-tum advantage in R(σ). This may lead to a form of quantum finite model theory.

Current and ongoing work
The first author of the present paper and Anuj Dawar have recently begun a U.K. EPSRC-funded joint project on "Resources and Co-Resources: a junction between categorical semantics and descriptive complexity" to pursue the ideas introduced in [3] and the present paper. Project participants include the second author of the present paper, Tom Paine, Adaḿ O Conghaile, Daniel Marsden, Tomáš Jakl and Luca Reggio. A categorical analysis of Rossman's Equirank HPT Theorem appears in [1], and a significant refinement of this result, involving a combination of the pebbling and Ehrenfeucht-Fraïssé comonads, is presented in [40]. Current work in progress includes comonadic treatments of guarded fragments [4] and of generalized quantifiers [13], and coalgebraic characterizations of further combinatorial invariants such as clique-width.