Bayesian open games

This paper generalises the treatment of compositional game theory as introduced by Ghani et al. in 2018, where games are modelled as morphisms of a symmetric monoidal category. From an economic modelling perspective, the notion of a game in the work by Ghani et al. is not expressive enough for many applications. This includes stochastic environments, stochastic choices by players, as well as incomplete information regarding the game being played. The current paper addresses these three issues all at once.


Introduction
In [13] the first compositional treatment of economic game theory was introduced.Following the literature on categorical open systems [7], open games are modelled as morphisms of a symmetric monoidal category.
A distinctive and non-obvious feature of this approach is that the Nash equilibrium condition [30], one of the central concepts in classical game theory to analyse rational behaviour of agents (cf.[12,Chapter 1.2] and [33,Chapter 2]), is itself compositional.
While an important first step, the treatment in [13] has two severe limitations: 1. Games are deterministic and as a consequence, there are no chance elements in the games and players have to choose deterministically.
2. Players have complete information about all relevant data of the game such as payoffs, number of players etc.
Many interesting strategic situations feature chance elements.Poker is one example -already discussed in the ground-breaking work of von Neumann and Morgenstern [31].In an economic context, the environment also often is non-deterministic.Two competing companies face uncertain demand, exchange rates, lawsuits etc.
More subtle but also important is that players may need and may want to randomise their actions.There are well known situations like Matching Pennies (see, for instance, [12, p. 16]) where playing deterministically means being 'beaten' all the time.Conceptually, from a game theory perspective, this means that there are games where equilibria do not exist when players are limited to deterministic strategies (known as 'pure strategies') whereas they do exist when players can choose stochastically (known as 'mixed strategies').
Lastly, it is a crude approximation to assume that players have complete information.Examples abound.A used-car dealer knows how good the car is that he is trying to sell to you.You may not know.Banks sitting on toxic assets know how little value they actually have.The government trying to buy these assets in order to save the financial system from collapse may not know.An agent bidding in an auction may not know how many other bidders he competes with.In most situations incomplete information is the norm and not the exception.
Jules Hedges: jules.hedges@strath.ac.ukPhilipp Zahn: philipp@20squares.xyz The above limitations restrict the applicability of compositional game theory to economic phenomena.And it restricts its usefulness for economists.After all, classical game theory already deals with these complications.
In this paper we provide a generalisation of open games which solves the three problems above in one go.We adapt the core definition of compositional game theory such that the environment can be stochastic and players can also choose in a non-deterministic fashion.Doing so, we also introduce a way to deal with incomplete information.Essentially we are lifting the same 'trick', which has been introduced in classical game theory to deal with games of incomplete information by John Harsanyi [17][18][19], to compositional game theory.
Harsanyi argued that instead of dealing with games of incomplete information directly, which poses formidable conceptual problems, we can transform such games into games of imperfect information by introducing the notion of (game) types.Players have access to probability distributions characterising these games as well as partial access to this information.For instance, in an auction a player may know how much he values the good to be auctioned.However, he may not know how other agents value the good.Assuming that players update information according to Bayes' rule and adapting the equilibrium notion of Nash, to what is called Bayesian Nash equilibrium, game theorists can work with such interactions no differently to how they deal with chance elements in Poker.Thus by transforming the problem, Harsanyi essentially opened the path to using tools that were more or less already introduced by von Neumann and Morgenstern [31].
We are applying the same strategy.By introducing stochastic environments and adapting the equilibrium notion from Nash to Bayesian Nash we show that our compositional framework captures exactly Bayesian Games and thus allows to deal with stochastic environments as well as with situations of incomplete information.This distinguishes our work also from [15] which addresses the issue of deterministic players in isolation.

Technical introduction
Contrary at least to our own initial beliefs, addressing these issues requires some significant adaptions of open games as defined in [13].
The recent understanding of open games has been based on lenses, which consist of a pair of functions X → Y and X × R → S packaged into a single morphism (X, S) → (Y, R) of a category.Here, the function X → Y is the play function, which plays out a given strategy by taking an initial state to a final state of the open game.The function X × R → S, known as the coplay function or coutility function, is more subtle: It 'backpropagates' payoffs into the past, given an initial state.This operation is 'counterfactual', and the composition of lenses (which is not trivial to define, nor is obvious to see is associative) intertwines ordinary forward and counterfactual (or 'teleological') information flow.
An open game can then be viewed as a family of lenses indexed by a set of strategy profiles, together with another component describing which strategy profiles are Nash equilibria in a given context.A context for an open game consists of an initial state (X) and a function from final states to payoffs (Y → R).Contexts turn out also to be intimately connected to lenses, and indeed this was the initial hint that viewing open games in terms of lenses is a deep idea rather than a coincidence.
To someone trained in thinking about processes with side effects, it is entirely natural to begin by inserting a (finite support) probability monad D, and take the components of the lenses to be Kleisli morphisms X → D(Y ) and X ×R → D(S), or equivalently to use lenses over the category of sets and (finite support) stochastic functions.This allows the strategies of an open game to describe probabilistic behaviours, which are known as behavioural strategies in game theory.Unfortunately this doesn't work: In order to prove that lenses form a category (i.e. are associative and unital) it is necessary that the forwards maps X → Y are homomorphisms of copying, and in the category of stochastic processes this characterises those processes that are actually deterministic.
Fortunately this problem has already been solved in the theory of lenses, although the solution is far from obvious.We use the existential lenses or coend lenses as developed by Riley [36].This means we replace the pair or functions X → D(Y ) and X × R → D(S) with three things: A choice of set A, a function X → D(A × Y ) and a function A × R → D(S).Moreover a certain equivalence relation needs to be imposed, and this is precisely given by the following coend [27] (one of the universal constructions of category theory): The proofs in this paper make heavy use of a diagrammatic language for existential lenses developed in [36].
The second question is what should be considered a context of a Bayesian open game, i.e. a replacement for the pair X × (Y → R).There is an existing characterisation of these contexts in terms of deterministic lenses, namely as a 'state' lens (1, 1) → (X, S) and a 'costate' lens (Y, R) → (1,1).However this turns out to be a red herring: in Section 3.4 we show that generalising from this causes the category of open games to fail to be monoidal in an unexpected way.
It turns out that the appropriate notion of context consists of three things: a set Θ of unobservable states, a joint distribution on Θ × X (i.e. an element of D(Θ × X)) and a function Θ × Y → D(R).Again we need to impose a certain equivalence relation, which again turns out to be precisely a coend.Remarkably this is equivalent to a state in the category of double lenses, i.e. lenses over the category of lenses.This brings an unexpected theoretical unity to Bayesian open games, and means that the graphical language of [36] can be used throughout.

Concrete open games
We begin with a self-contained introduction to deterministic open games.In essence, we will introduce the necessary machinery so that we can represent simple classical games with diagrams as depicted below.
This diagram displays an interaction between two agents, A and B. Player A moves first; player B observes the choice by A and then moves afterwards.Both moves are consumed by an environment c k which provides the payoff for both players.
To get to a full understanding of this diagram (and deterministic open games), in this section we introduce several building blocks.Roughly, they can be classified in two kinds.
First, we need a way to architecture the information flow.As we will see in Sections 2.1 to 2.3, lenses play a crucial role by providing us with a categorical structure on which to build open games.
Second, we need to flesh out the internals of the boxes in the diagram.Specifically, how does strategic reasoning actually take place?Central here is the notion of an agent who makes observations and chooses a course of action.As we will see in Section 2.5 and Section 2.6, the key insight is to model an agent as choosing against a context which comprises how the environment reacts to an agent's choices.The context is also the glue that keeps the outside information flow and the internal reasoning together.
Once we have introduced all the relevant parts, we will come back to the example above.Note: The exposition in this section slightly deviates from previous work.We believe this eases the way for the generalisations to come in Section 3 and thereafter.

Lenses
The history of mathematical lenses is complicated, involving many independent discoveries and fresh starts across numerous areas of mathematics and computer science [2,5,9,26,32,34].An in-depth description of this history can be found at [25].We use lenses to describe the flow of information through a game.A lens for a given game describes which players have access to what information when making a strategic decision, and also how information about players' strategic decisions is ultimately fed into the outcome function for the game.For example, it may specify an order of play, or whether two players are playing in parallel, or even whether some players are privy to certain information in the environment that other players are not.
In general, lenses can be thought of as processes that perform some computation and then propagate some resulting feedback from the environment backwards through a system of which they are a part.In particular, this means that lenses have both covariant and contravariant components.The covariant component carries out the initial computation and the contravariant component propagates the resulting feedback back through the system.Crucially, lenses are also compositional in the sense that they admit both sequential and parallel composition and, consequently, form a symmetric monoidal category.
The lenses used in this paper are direct descendants of the lenses of database theory.Given some data x of type X we may want to view some part of it y of type Y .This is encapsulated by a view function v : X → Y .From this 'close-up' view of the database we may want to edit the database by updating y.Given an update of the view y we then need to know how this update propagates to an update of the original data x.That is, given initial data x and an updated view y ′ : Y , we should specify some updated x ′ : X given by some update function u : X × Y → X.The pair (v, u) is a lens with type X → Y .The connection to our previous abstract definition of lenses is as follows: • The covariant computation associated with the lens is the view function v : X → Y , • the resulting feedback from the environment is the update made to the subdatabase returned by the view function, and • this feedback is propagated back to the whole database via the update function u : X × Y → X.
Abstracting away from databases, there is no reason to demand that the feedback generated by the environment will have the same type as the output of the lens computation.Similarly, we may be interested in cases where the update function is not-so-literally an 'update' function, but merely a function that propagates some kind of feedback back through the system.As such, the lenses we will be using will have types of the form (X, S) → (Y, R) where the covariant component of the lens is of type X → Y and the contravariant component is of type In game theory, we can regard players as 'lenses that care about the feedback they receive from the environment'.In a game with sequential play, players make some play (computation), receive some utility (feedback) from the outcome function, and then pass some feedback to earlier players in the game (their outcome function given the moves that the later players chose).Moreover, given that lenses admit parallel composition as well as sequential composition, we obtain a nuanced notion of information flow in a game.
In the next subsections we describe a symmetric monoidal category of concrete lenses.'Concrete' here refers to the fact that the view and update functions are functions in Set.We then come to the core of this section, the definition of a concrete open game.

The category of concrete lenses
As a trivial first example, there is an obvious mapping that takes a morphism of Set × Set op and returns a concrete lens.
As a string diagram (t • l) u is given by 2.4 (Sequential composition of concrete lenses is associative).Suppose we have concrete lenses

Theorem 2.2.5 (Concrete lenses form a category).
There is a category CL with pairs of sets as objects and concrete lenses as morphisms.

The monoidal structure of concrete lenses
Definition 2.3.1 (Tensor composition of concrete lenses).Let and (l 1 ⊗ l 2 ) u is given by ⊗ is a functor.

Theorem 2.3.3.
There is a symmetric monoidal category CL where the objects are pairs of sets and the morphisms are concrete lenses.Sequential composition and the monoidal tensor are as in the above definitions.The monoidal unit is I = ({ * }, { * }).
The following observations about states and effects in CL will be useful in the remainder of this section.Lemma 2.3.4.CL I, (X, S) ∼ = X.
Proof.This is easily seen, as a state l ∈ CL I, (X, S) is given by a pair s : {⋆} → X, e : {⋆} × S → {⋆} .Proof.An effect l ∈ CL (Y, R), I is given by a pair Here Rel(Σ) = P(Σ × Σ) is the set of binary relations on Σ.In this paper we will usually specify a relation in terms of its forward images Σ → P(Σ).

Concrete open games
The type X is the type of observations made by the game; the type Y is the type of actions that can be chosen; the type R is the type of outcomes; and the type S is the type of co-outcomes.Of the four types associated with a concrete open game, the type S is the most mysterious.Succinctly, its purpose is to relay information about outcomes to games acting earlier.In a sequential composite H • G of open games (we will define sequential composition of concrete open games shortly), the co-outcome type of H is also the outcome type of G.We think of H as receiving some outcome which is then acted upon by the contravariant component of a concrete lens given by H's play function before being passed back to G as G's outcome.
The best-response function of an open game is an abstraction from the utility functions of classical game theory.Recall that a Nash equilibrium for a normal-form game is a strategy profile in which no player has incentive to unilaterally deviate.We can instead think of a relation on the set of strategy profiles for a normal-form game where strategy profiles σ and τ are related if τ is the result of players unilaterally deviating from σ to their most profitable unilateral deviation.Nash equilibria are then the fixed points of this relation.We are now in a position to justify the type of the best-response function.The best response functions takes a context as argument, and a context is precisely the information required for resolving the 'openness' of a concrete open game.Given a context, the best response function then returns the set of best deviations from a strategy profile σ.
We represent a concrete open game G : (X, S) → (Y, R) using the diagram This diagrammatic notation emphasises the point that information flows both covariantly through G from observations to actions, and contravariantly through G from outcomes to cooutcomes.These diagrams constitute a bona fide diagrammatic calculus for the category of concrete open games defined in the remainder, as detailed in [21].
We sometimes refer to an atomic concrete open game simply as an atom.
Note that an atom a : (X, S) → (Y, R) is fully determined by a subset Σ a ⊆ CL (X, S), (Y, R) and a selection function Given f : X → Y and g : R → S, as in CL, the pair (f, g) ∈ Set × Set op can be represented as a concrete open game.We refer to such games as computations, as no strategic choice is being made.
Y ⟩ where the Set functions on the right-hand side of the equalities are the obvious Set isomorphisms.We are being slightly relaxed with notation here as the update function for c f has type X × {⋆} → S while f has type X → S. We represent c f as follows.Recall that a concrete lens l : CL (X, {⋆}), (Y, R) is a pair (v : X → Y, u : X × R → {⋆}) and, hence, is uniquely determined by a function of type X → Y .Consequently, a strategy for an agent specifies how an agent map chooses an action of type Y given an observation of type X.Given a context c : X × (Y → R), B A (c) picks out the set of strategies A considers acceptable in the context c.Agents are represented diagrammatically by We can specialise the definition above to model the utility-maximising agents of traditional game theory.

Example 2.5.2 (Utility maximising agent). The utility maximising agent
There are other decision criteria one could use.For instance, MinMax and regret minimisation would be candidates.We could also consider models from behavioural game theory such as prospect theory.The only (very weak) requirement is that the decision criterion can be described by a selection function [23,24].In this paper we focus on utility-maximising agents as a simplification and in order to match traditional game theory.

Best-response with concrete lenses
Recall from 2.3.4 and 2.3.5 that CL I, (X, S) ∼ = X and that CL I, (Y, R) ∼ = Y → R. Using these facts we can rephrase the type of best response for a concrete open game G : This formulation allows for a concise and natural definition of sequential composition for concrete open games where it would otherwise seem ad hoc.To make matters clear, we write x when talking about elements of X and x ⋆ when talking about concrete lenses with type CL I, (X, S) .Similarly, we write k : Y → R when talking about functions in Set and we write k ⋆ when talking about effects in CL (Y, R), I .

Sequential composition of concrete open games
In this section we specify how to define the sequential composite H We imagine that this composition really is sequential in a straightforward way.G is 'played out' according to some strategy σ ∈ Σ G and then H is 'played out' according to some τ ∈ Σ H .A choice of (σ, τ ) ∈ Σ G × Σ H therefore determines an open play of G and H played in sequence, and so we take Σ G × Σ H to be the set of strategy profiles of H • G.
The play function of the sequential composite is defined straightforwardly using the sequential composition of concrete lenses defined in 2.2.3.
Defining best response for a sequential composite is a bit more delicate and, for explanatory purposes, we make use of the informal notion of a local context for a subgame.Given a context c = (x : X, k : Z → Q) and a strategy (σ, τ ) for H • G, the best-response relation of H • G is specified by calling the best-response function of G with a modified context corresponding to how c 'appears' to G when H plays according to τ and, similarly, calling the best-response function of H with a modified context corresponding to how c 'appears' to H when G plays according to σ.In practice we define these 'local contexts' in the obvious way that type checks, but this is because the work has already been done in carefully choosing the correct definitions.

The tensor composition of open games represents simultaneous play. Given concrete open games
we make use of the tensor composition in CL in defining the play function; and the best-response function is given by modifying the context c to give local contexts for G and H.

Definition 2.8.1 (Local contexts for tensor composition). Define the left local tensor context operator
As a diagram, L(x ′ , p ′ , l) is the function Similarly, define the right local tensor context operator Consider the left context operator L acting on some triple (x ′ , p ′ , k).If k is an outcome function for the game G ⊗ H and H observes x ′ and plays according to the function p ′ , then L(x ′ , p ′ , k) is the 'apparent' outcome function for G. Similarly, R(x, p, k) is the 'apparent' outcome function for H when G observes x and plays according to p.With this in mind, we define tensor composition for concrete open games as follows.

Equivalence of open games
One subtlety remains before we can define the category of concrete open games.We aim to define a category with pairs of sets as objects and morphisms given by concrete open games.If carried out naïvely, this runs into the problem that strategy sets which should be identical are merely isomorphic.For instance, the strategy set of K In order for concrete open games to form a category, we must first take an appropriate quotient.
There are several different reasonable choices of quotient.Since this is an orthogonal consideration to this paper's topic, we choose the most straightforward, which is to identify open games that have a compatible isomorphism between their sets of strategies.Other choices that can be made are bisimulations [3] and surjections [8].Alternatively, instead of taking a quotient, open games can be considered as the 1-cells of a bicategory [22].
as in the previous lemma.

The category of concrete open games
We are now finally in a position to show that concrete open games form a symmetric monoidal category.
Notation 2.10.1.In string diagrams we refer to a play function applied to a strategy simply by the strategy.For example, σ may refer to P G (σ).In practice this does not lead to ambiguity because proofs and definitions proceed by assigning fixed strategies to particular open games.This notational convention allows for less cluttered string diagrams.

Lemma 2.10.2. Sequential composition of concrete open games is associative up to equivalence.
The identity morphism (X, S) → (X, S) is given by the computation ⟨id X , id S ⟩.
Lemma 2.10.3.We include the proof of this lemma specifically because it will be important later.
As CL is symmetric monoidal, we have that ).We will show that the local contexts for G 1 , G 2 , and G 3 are the same in both The above lemma relies on the fact that the monoidal tensor in Set is cartesian.In particular we needed that bipartite states s : I → S 1 ⊗ S 2 in Set (i.e.elements of S 1 × S 2 ) correspond to pairs of states (s 1 : I → S 1 , s 2 : I → S 2 ).In an arbitrary monoidal category, it need not be the case that for all states s : I → S 1 ⊗ S 2 there exist states s 1 : I → S 1 and s 2 : This poses a significant barrier to generalising concrete open games to monoidal categories where the monoidal tensor is not cartesian, and Section 3 addresses this problem.

Encoding functions as games
Recall that, given functions f : X → Y and g : R → S, there is a computation of concrete open games ⟨f, g⟩ : (X, S) → (Y, R).In fact, this operation is functorial.

Lemma 2.11.1 ([20]). Define
We also incorporate computations directly into the diagrammatic calculus for concrete open games, representing the computation ⟨f, g⟩ : (X, S) Two particularly useful examples of this notation are the covariant and contravariant copying computations ⟨∆ X , id 1 ⟩ : (X, 1) → (X × X, 1) and respectively.

Game theory with concrete open games
In this section we give some examples of games modelled using concrete open games.We will be light on details, aiming to simply demonstrate some of the expressive power of concrete open games.We direct the reader to [20] for more details.

Bimatrix games
Bimatrix games are simply two-player normal-form games, the most well-known example of which is likely the prisoner's dilemma.We assume the set of actions available to each player is finite for simplicity.

Two-player sequential game
A two-player sequential game is defined by the same data as a bimatrix game (sets A and B and a function k ), but we allow the second player to observe the first player's move before making a choice, so strategies for the second player are functions A → B. This is represented by the concrete open game where A and B are utility maximising agents and c k is the counit game associated with k.
Crucially, the fixed points of the concrete open game are not subgame perfect Nash equilibria, but rather plain old Nash equilibria.It is also possible to define a concrete open game that captures subgame perfect equilibria, but this requires an additional operator defined in [14].

Normal-form games
be a normal-form game for N players.S i denotes the set of strategies available to player i.The function u i maps a strategy tuple for all players,

General open games
The notion of open game we introduced in the section before can emulate some standard games such as the prisoner's dilemma.On the other hand, classical game theory has a much wider reach.It can model situations with which a concrete open game cannot deal.This involves stochastic environments, probabilistic choices by players, and incomplete information.
In this section, we will significantly generalise the notion of an open game, to make room for these three extensions (and beyond).The first order of business, to make progress in this direction, is to generalise concrete lenses.

Generalising concrete lenses
In the proof of Lemma 2.2.4 we made use of the fact that every Set function is a comonoid homomorphism for the copy/delete comonoid.Recall that a morphism is a comonoid homomorphism if it can be 'moved through' the comonoid structure.
If Set is replaced with some arbitrary symmetric monoidal category C and the copy/delete comonoid is replaced with some arbitrary comonoid in C, sequential composition of lenses, as defined in Definition 2.2.3, may not be associative.This presents a substantive problem -there exist categories relevant to game theory in which sequential composition of concrete lenses is not associative.Of particular interest is the Kleisli category of the finitary distribution monad, Kl(D), which we will need in order to model Bayesian games (discussed in Section 4).Kl(D) inherits a copy/delete comonoid from Set, but its comonoid homomorphisms are the deterministic maps (i.e.precisely the non-probabilistic maps).
In the next section we introduce coends, a piece of categorical machinery that allows for an elegant generalisation of concrete lenses to arbitrary symmetric monoidal categories.We call these generalised lenses coend lenses or, simply, lenses.We will first introduce the technical notion before magicking it away with a diagrammatic calculus that represents what is 'really' going on.

Co-wedges and Coends
Co-wedges are a variant of co-cones of natural transformations applying to functors that act both covariantly and contravariantly on an argument.In Section 2.1 we noted that lenses have both covariant and contravariant components.We will see that this behaviour can be described by coends, which are initial co-wedges.For extra motivation, discussion, and examples, we refer the reader to [27].
We adopt the integral notation for coends, writing for coend(F ).We will make use of the fact that coends can be characterised by the following coequaliser.a) is given by the coequaliser of the pair of arrows where the f : a ′ → a components of F 1 and F 2 are F (f, a ′ ) and F (a, f ) respectively.
When C is not small (as it usually is not), we need to show directly that coends exist.

Coend lenses
Much of the material in this section is worked out in much greater detail in [36], which serves as a good standard reference for coend lenses.We first give an abstract definition of coend lenses, then provide some justification.Definition 3.3.1 (Coend lens).Let X, S, Y, and R be objects in a symmetric monoidal category We think of the coend in the above definition as acting as a kind of existential quantifier over the type variable A, followed by a quotient (to be described) over the resulting structure.That is, a coend lens l : (X, S) → (Y, R) consists of an equivalence relation over triples comprised of a choice of type A, a morphism v : X → A ⊗ Y , and another morphism u : A ⊗ R → S.
By Lemma 3.2.3we can characterise coend lenses (X, S) → (Y, R) as the elements of a particular coequaliser.Moreover, coequalisers in Set are given by quotients.Unpacking the coequaliser explicitly, coend lenses (X, S) → (Y, R) are given by the set of triples of the form described above, quotiented by the equivalence relation generated by (i.e. the smallest equivalence relation containing) for all A, B : C and f : We refer to the types A and B as bound types (B is bound in the first diagram, A in the second).
In Section 4, we will see that this bound type keeps track of correlations between random variables in the Kleisli category of the distribution monad.
In vague terms, two pairs of morphisms are related if one can get from one to the other by 'sliding' a morphism off the bound type of one morphism on to the bound type of the other.Given a pair of morphisms (v : X → A ⊗ Y, u : A ⊗ R → S), we write [v, u] for their equivalence class.When we need to talk explicitly about the bound type of [v, u] we write [A, v, u] to specify that the pair (v, u) has bound type A. We also adopt the convention that l = [A l , l v , l u ] where, as with concrete lenses, we say that l v is the view morphism and l u is the update morphism.We follow [36], taking the hint from the diagrammatic representation of the equivalence relation by representing We usually omit the bound type in diagrams for clarity.The equivalence relation is then simply The equivalence relation permits the cancelling of isomorphisms: Many proofs in this section proceed by allowing symmetric monoidal structure to interact with coend structure as, for example, in the following diagram.
The formal foundations of this class of diagrams are investigated in [37].
Theorem 3.3.5 (Coend lenses form a category).Suppose C is a monoidal category such that, for all objects X, S, Y, R ∈ C, exists.Then there is a category Lens C whose objects are pairs of objects in C and where When C is small, the existence of sets of coend lenses of each type is guaranteed by the cocompleteness of Set.When C is not small, and the lens types correspond to coends indexed by a large category, we must verify that these sets exist by some other means (by, for example, giving a Set isomorphism).Fortunately, this is not difficult for the categories of interest in this work.Call such generalised open games interim open games (for they will not live long).Sequential composition and tensor composition of interim open games could be defined much as we did for concrete open games.The problems begin to arise when one attempts to prove that this definition results in a symmetric monoidal category.

Definition 3.3.6 (Tensor composition of coend lenses
In proving that the associator was natural in CL, we used the fact that the monoidal tensor in Set is cartesian.If the tensor of In general, these morphisms are not the same.In the case where C is the Kleisli category of the distribution monad, the first morphism contains information about correlations between the types X 2 and X 3 whilst the second morphism does not.Consequently, the distinction between these two local contexts for G is substantive.Fortunately, coend lenses also provide a solution to this problem.
The high-level approach for defining a category of generalised open games is to use as few 'deleting' maps as possible.We do this by 'hiding' information in the bound variable of a coend lens whenever we would otherwise delete it.A consequence of this approach is that the correct definition of a 'context' for generalised open games is quite abstract, but we will see that this abstractness allows for more elegant proofs and, in any case, disappears when dealing with the categories we are actually interested in.

States, continuations, and contexts
In this section we define a generalised notion of context for open games.Observe that a state [s, s ′ ] ∈ Lens C (I, (X, S)) has the form This result captures the idea that 'effects in Lens C are outcome functions in C'.
We can now define (generalised) contexts which consist of a coend over a state in Lens C (a history/cohistory pair) and an effect in Lens C (an outcome function).Contexts are therefore members of a double coend.This double coend turns out to be a state in the double lens category Lens Lens C .From a purely technical standpoint, using double lenses allows for elegant proofs.From a heuristic perspective, we will see that the extra bound variable the double lens affords us enables us, in the case C = Kl(D), to store information about correlations between variables where we would otherwise have to take marginals.

Composing open games
The heuristic for sequential composition of general open games is much the same as for concrete open games in Subsection 2.7.The only difference is that we are now using coend lenses rather than concrete lenses, and contexts also are slightly different.Best response of a sequential composite H • G is still defined by forming local contexts for G and H.

Definition 3.7.1 (Sequential composition of open games). Let
We will usually suppress the subscripts of L and R as the types can be inferred from context.

Equivalence of open games
As in Section 2.9, we need to quotient open games in order to obtain a category.
Demonstrating equivalence in the cases of interest will always be trivial, and so we simply specify the witnessing bijection between strategy sets.Proof.All that remains to be checked is that the identity computation defined in Example 3.6.3 is an identity morphism, and this follows from easy checks.

The equivalence between (K • H) • G and K • (H • G) will be witnessed by the isomorphism
Volume 5, Issue 9. ISSN 2631-4444

The symmetric monoidal structure of open games
We now prove that ⊗ is functorial.The proof is a good demonstration of the utility of coend diagrams.In the commutative squares in the following lemma, the top path describes how local contexts are formed in, say, (H ⊗ H ′ ) • (G ⊗ G ′ ) and the bottom path describes how local contexts are formed in (H•G)⊗(H ′ •G ′ ).That the squares commute follows by inspection of the appropriate coend diagrams.Lemma 3.11.1.Suppose we have coend lenses The following diagrams commute: 1.
Functoriality of the tensor in Game C then follows easily.

Corollary 3.11.2. ⊗ : Game
Lens C is symmetric monoidal and, hence, Using Lemma 3.11.1, Definition 3.11.3.The structural isomorphisms in Game C are given by Proof.We show that the associator is natural.Naturality of the other stuctural maps follow by similar arguments.Let We note that the local context for G 1 given this data is the same for both games.The local context of G 1 is given by This two morphisms are evidently equal.Similar diagrams demonstrate that the local contexts for G 2 and G 3 are the same in both games also.
Proof.All that remains to be shown is that the Mac Lane pentagon and triangle axioms are satisfied, but this follows easily as the underlying category C is symmetric monoidal.

Nice categories of open games
In this section we show how the notion of 'cohistory' collapses when the monoidal unit I of the underlying monoidal category C is terminal.With cohistories gone, we will see that Game C has a very natural game-theoretic interpretation.
The following fact appears as [27, exercise 1.13]; thanks to Guillaume Boisseau and Amar Hadzihasanovic for the discussion at [39].Proof.Let F : C → Lens C be the embedding F (X) = (X, I).When the monoidal unit of C is terminal, this functor has a right adjoint U : Lens C → C that is given on objects by U (X, S) = X.
On morphisms U is defined by the universal maps In the previous lemma we take G : with the three isomorphisms respectively using Lemmas 3.12.1,3.12.2and 3.5.1.
In the case where the monoidal unit of C is terminal, the type of best response for an open game G : (X, S) → (Y, R) is equivalently We have seen that expressing contexts as states in the double lens category is a good level of abstraction for categories of open games, allowing for elegant diagrammatic proofs.From a gametheoretic perspective, however, it will make more sense to express contexts as equivalence classes [p, k, Θ] : Lens C ((I, R), (X, Y )).This is because a state p : and the local context for H is given by , and a strategy µ ∈ Σ H , the local contexts for G and H in G ⊗ H are given by p

Bayesian open games
In this section we will zero in on open games with a specific lens structure.As we will show this class of open games will address the shortcomings of concrete open games.

Commutative monads
Recall that a monad T over a monoidal category C is strong if it comes with a strength natural transformation t A,B : A ⊗ T B → T (A ⊗ B) satisfying various coherence conditions.
We have the following result guaranteeing the existence of a large class of coend lens categories.We refer the reader to [36] for a much more in-depth discussion of the following result, and many more examples of when lens categories exist.Theorem 4.1.1([36]).If T is a strong monad, then Lens Kl(T ) exists 2 .Definition 4.1.2(Commutative monad).Let T be a strong monad with strength t over a monoidal category C. Define the costrength natural transformation t ′ A,B : T A ⊗ B → T (A ⊗ B) to be the composite commutes for all objects A and B in C.
If a monad is commutative then we get that its Kleisli category is symmetric monoidal for free with the monoidal tensor ⊗ (on objects) and unit being the same as in the underlying category C .Lemma 4.1.3([35]).If T is a commutative monad over a symmetric monoidal category C, then Kl(T ) is symmetric monoidal.
Commutative monads over Set also come with canonical copy/delete comonoid structures for every object.Copying c X : and deleting d X : X → I is given by From this comonoid structure we obtain canonical projections Crucially, it is not guaranteed that the monoidal tensor of Kl(T ) is cartesian.

The category of sets and random functions
We now turn to the category of interest for this section.
The finitary distribution monad D : Set → Set maps a set X to the set of finitary probability distributions on X (finitary in the sense that only finitely many elements are assigned non-zero probability).

Definition 4.2.1 (Finitary distribution monad). Define
where supp(α) is x ∈ X α(x) ̸ = 0 , the support of α.D acts on morphisms by The monad structure of D is given as follows.The unit is given by The monoidal unit of Kl(D) is terminal, and hence the deleting map d X : X → D({⋆}) must be given by d(x)(⋆) = 1.As this map is unique, we refer to it as !.
Whenever we are working in Kl(D) we denote c X and !X by respectively.
An important operation on probability distributions is Bayesian updating where an agent has some prior distribution (initial belief), makes an observation, and then updates their prior to a new, posterior distribution.Definition 4.2.6 (Update operator).Let X and Θ be sets.We think of Θ as a type which an agent has a probabilistic belief about, and X as a type that will be observed by an agent.Define the update operator .
The top of the square is given by The bottom of the square is given by The result follows, noting that the denominators of (⋆) and (⋆⋆) are equal.We unpack the definition of the play function to emphasise that, when we wish to actually specify a Bayesian open game, it is usually easier to specify P(σ) as the equivalence class of a pair of morphisms.

Bayesian agents
We will now define Bayesian agents which, as with concrete open games, have constant bestresponse functions.Bayesian agents capture the notion of rational agents that 1. Have a correct prior about the various types in a game; It is worth explaining this last formula in words.A (X,Y ) represents an agent choosing an element of Y after observing an element of X.The context of the decision consists of a set Θ of unobservable states, a prior joint distribution p : D(Θ × X) on unobservable and observable states, and a utility function k : Θ × Y → D(R) that depends on the unobservable state and the agent's choice.The optimality condition says that for all observations x that the agent could make with nonzero probability, the strategy σ(x) maximises the expected value of k(ϑ ′ , −), where ϑ ′ = U Θ (p)(x) is the posterior distribution on the unobservable state given the observation of x.Lemma 4.4.2.The selection function of a Bayesian agent is well-defined.That is, it is independent of the choice of representative of the coend equivalence relation.
Proof.This result follows from the fact that Bayesian updating is natural in the bound type of a coend lens (4.2.7).
In the next definition we formalise the idea that a player in a game might be assigned a (gametheoretic) type on which their utility function depends.We can do this simply using a Bayesian agent and a copying computation.→ Lens Kl(D) (X, I), (X × Y, R) is given by and applying the inductive hypothesis, where [p, k] −1 is the context

Decisions under risk
In this section we introduce another type of situation involving a Bayesian agent that can be modelled using Bayesian open games.
A decision problem under risk is a decision problem for which one can sensibly assign probabilities to possible outcomes.A good example is roulette.When making a bet in roulette, you can calculate the likelihood of success and also your expected return on any bet.We now give a fully worked out example of a Bayesian open game in which an agent has a prior, makes an observation, updates their prior as a consequence of that observation, and then makes a prediction based on their posterior.
Example 4.5.1 (Biased coin).Suppose we give an agent A a biased coin which lands on one side 75% of the time and the other side 25% of the time.It is not known which side the coin is biased towards, but it is known that it is equally likely to be biased towards heads as towards tails.A flips the coin whilst another identical coin (i.e. another coin biased the same way) is flipped in secret.A observes her coin flip and is then asked to predict which side up the secret coin landed.If she is correct she receives an outcome of 1 with probability 1.If she is wrong she receives an outcome of 0 with probability 1.The optimal strategy for A is to guess that the coin flipped in secret will land the same way up as the coin she flipped.If, for instance, A's coin comes up heads, then there is a 75% chance that both coins are biased towards heads.Consequently the coin flipped in secret is more likely to show heads.A symmetric argument applies if A's coin shows tails. We Explicitly, the game is given by Also note that there is precisely one context for G since its type is I → I (that is, (1, 1) → (1, 1)) and, moreover, as the best-response functions for u, id {H,T } , and p are trivial, the best-response function for G is isomorphic to the constant relation ) is a singleton set containing the strategy σ where σ(H) = δ H and σ(T ) = δ T , as expected.

Relating Bayesian Open Games to Bayesian Games
The example given in the previous section illustrates two important improvements over the version of open games as introduced in [13].There, everything is deterministic -the environment, the players moves etc.Here, the environment as well as the players' moves can be probabilistic.Still, we only consider a single player.We could consider examples with more players and with probabilistic behaviour induced by nature or games where probabilistic behaviour is key, such as matching pennies.In [15] a definition of open games is given that can handle mixed strategies.
Instead, we want to focus on another aspect of Bayesian open games, which we believe is much less obvious, particularly to readers with no game theory background: From a game-theoretic perspective, we introduced a new solution concept.For random environments and probabilistic moves, there is no real difference to standard Nash equilibria.However, there are important classes of games for which the new equilibrium notion brings material change.
Reconsider Example 4.5.1.Here, the agent has some prior information about the nature of the coin.Given observations from the coin and the prior information, the agent updates beliefs about the true nature of the coin and maximises accordingly.Thus, we maintain not only an assumption that the agent maximises but also how she deals with information.
The example is very simple.After all, there is only one agent.Our interest lies of course in the interaction of such Bayesian agents.While the strategic reasoning is more complicated in such situations the overall structure is the same as in Example 4.5.1:Each agent has access to some prior information, some (partial) information is revealed, and the agent makes a decision.
In the game-theory literature such a game is called a 'Bayesian game' or also 'game in Bayesian form' and the solution concept we sketched is called 'Bayesian Nash Equilibrium'.Next, we introduce the standard economic notion of such games, then provide a simple example, an auction, and followed by a general construction that allows us to translate an arbitrary Bayesian game into a Bayesian open game.

Denote with Γ
a Bayesian game.Before we explain the components we add some useful notation: we write Θ −i = j∈N,j̸ =i Θ j for the possible combinations of Θ j other than i.
• N denotes the number of players.
• A i defines a set of actions available to the players. 3 Θ i defines the a set of (player) types each player i can have.
• π : D N i=1 Θ i is a joint prior distribution on the types that is common knowledge.
defines a utility for any profile of player types and any profile of actions.This definition is rather cryptic at first.So let us try to dissect its components.Then we will compare it to the definition of a normal form which we introduced in 2.12.4.This hopefully further helps to make sense of it.
Let us begin with Θ i , the player type, which is probably most obscure and most central at the same time.One way to think of types is imagining player i having different realisations or versions, one of which ends up playing the game.Each realisation, or type, summarises information relevant for the game.Often, this information will concern the payoffs. 4For example, player i may consider to bid in an auction.His type determines his evaluation for the good, that is, how much he values owning the good.It is easily conceivable that i may have different evaluations before the auction really takes place.
This example also illustrates another aspect of this structure.While player i may have different types, before he has to choose his action, he typically will know his type.So, once the bidding starts, he knows how much he values the good.But crucially, he does not know the types of the other players, only a probability distribution -conditional on his own observed type.The last aspect also already alludes to the role of Bayesian updating: Given his own observed type, a player may refine his belief about the other players' types.
The payoff function u i , as with a normal form, maps choices of players into a payoff.Here, however, player i's type may affect the payoff.Think again about an auction, naturally the bidding behaviour will affect i's payoff.But so does his type, the evaluation for the good.Note that the definition above includes the possibility that the whole realisation of types affects i's payoff.In the case of bidding for a private good, only i's type will typically be relevant.
Lastly, A i represents the set of actions player i can take in the game.Note, that we intentionally refer to this as actions and not as strategies.To understand this it is best to compare the above definition to a normal-form game.
Recall its notation: Γ = N, (S i ) N i=1 , (u i ) N i=1 .Here, S i refers to a strategy which is a complete contingent plan for all possible occasions where i can make a move.Note that S i can be a shorthand for some complicated dynamic structure where i moves several times.
Analogously, A i in the Bayesian game refers to a complete contingent plan once the game 'begins', i.e. after i has learned his type.This could involve a complicated dynamic structure.Crucially, however, this is not the same as a strategy for the Bayesian game.Why?A strategy of the Bayesian game must include a contingent plan also for each realisation of i's type!Formally, a pure strategy for a game in Bayesian form is a mapping s i : Θ i → A i for all Θ i .A behavioural strategy σ i for player i is a mapping σ i : Θ i → D(A i ), i.e for each type of player i a behavioural strategy assigns a probability distribution over the available actions. 5or each player we can now define the (conditional) expected utility for player i given behavioural strategy profile σ with Note, that p π (•|•) updates the prior information π for player i given Bayes' rule.Equipped with all that we can finally define a Bayesian Nash equilibrium.Definition 4.6.2(Bayesian equilibrium).A (behavioural) strategy profile σ * = (σ * 1 , σ * 2 , ..., σ * N ) is a Bayesian Nash equilibrium if for each player i ∈ N , each type ϑ i ∈ Θ i , and each possible action a i ∈ A i it holds that:

An auction example
Suppose two agents are bidding for a good that is being sold in a first-price sealed-bid auction.
Here 'first-price' means that whichever agent bids higher receives the good and pays her/his own bid, with the other agent neither gaining nor losing anything.'Sealed-bid' means neither player can observe the other's bid, meaning the bidding is effectively simultaneous.Both players have a private valuation for the good, which are drawn from a joint random distribution π : D(Θ × Θ), where Θ ⊆ [0, ∞) is the range of possible values.As usual, we assume this prior is common knowledge.One consequence thereof is that a player knowing their own valuation can update their beliefs about the other's valuation.Obviously, whether there is something to learn from one's own valuation about others' valuations depends on the type of good being auctioned.For instance, if we are bidding on a construction contract, then the value that contract has for me will be correlated with your evaluation.If, however, we are bidding on a painting by some obscure painter, it is less clear that I can learn something about others' valuations.
The winning bidder's utility is given by their valuation of the good minus the bid that they must pay.(This can be negative if the bid is higher than the valuation.)We must also choose a way to resolve a tie if the bids are equal: we assume that the winner is determined by a fair coin flip.Thus the expected utilities, for private valuations ϑ i ∈ Θ and bids b i ∈ Θ, are given by In order to formalise this situation as a Bayesian game as defined in the previous section, we take N = 2, A • Σ Gi ∼ = Σ A (X i /∼ i ,A i ) = X i /∼ i → D(A i ) • For σ i : X i /∼ i → D(A i ), P Gi (σ i ) is the optic (X i , R n ) → (X i+1 , R n ) given by the coend diagram • For a context c = (Θ, p, k) : (I, R N ) → (X i , X i+1 ), B Gi (c) is the constant relation where E[π Pi (k(p 1 , q(p 2 , a i ))) | p 2 = x i ] is the conditional expectation of given that the right marginal of p is x i .
In order to characterise G = G L+1 • • • • • G 0 inductively we have a choice to either work forwards from G 0 or backwards from G L+1 , corresponding roughly to forward induction and backward induction in game theory.We choose the former.The inductive hypothesis is encapsulated in the following lemma.Lemma 4.7.3.For 1 ≤ i ≤ L, consider the extensive form game G i without specified payoffs given by truncating the original extensive form game G to the first i + 1 levels (i proper levels plus the root node).Note that the set of leaves of G i is (labelled by) X i+1 .Then the open game G i • • • • • G 0 : (1, 1) → (X i+1 , R N ) is given by the following: is the optic (1, a, !), where a : 1 → D(X i+1 ) is the probability distribution on the leaf nodes of G i resulting from playing the behavioural strategy profile σ  In this last section we will discuss the wider context of this work, as well as some work in progress and future work.
Computer support.Due to the complexity of the definition of Bayesian open games, in practice computer support is necessary to work with real models in the framework.We have created such a software tool in the form of a Haskell library (available at https://github.com/jules-hedges/open-games-hs), consisting of a 'core' implementation of the monoidal category of Bayesian open games, together with a domain-specific embedded programming language that provides a higher level of description roughly equivalent to string diagrams.We have found this to be a practical tool for modelling, especially for rapid prototyping of models, in a variety of applied domains including auction design, governance modelling and blockchain protocol modelling.The implementation of this tool, and these applied case studies, will be described in a series of future papers.
Non-finitary probability.In Section 3 we gave a general theory of open games over a monoidal category.And then, in Section 4 specialised it to the Kleisli category of the finite support probability monad.This restriction to finite support distributions was done for simplicity, but the general machinery we have introduced is applicable to any category of probabilistic functions.Examples include the Kleisli categories of the Giry monads on measurable and Polish spaces [16], the Radon monad on compact Hausdorff spaces [38], and the Kantorovich monad on complete metric spaces [11].In fact, we believe that Bayesian open games can be formulated over any Markov category [10], which encompasses all of these examples.
Other solution concepts.In this paper we have focused on the solution concept of Bayesian Nash equilibrium.It is one of the central solution concepts in applied economic modelling as it allows us to model situations of asymmetric information.It is probably no exaggeration that for most economic situations information is asymmetric and thus the default.Hence, this paper is an important step in making the theory of open games practically useful for a wide range of situations.As a side effect, both ordinary mixed strategy Nash equilibria and correlated equilibria are obtained as special cases of Bayesian Nash equilibrium.However, for dynamic games it is common to use equilibrium refinements such as perfect Bayesian equilibrium or sequential equilibrium, in which individual players' beliefs are represented explicitly. 9It is an open question whether it is possible to extend compositional game theory with these stronger solution concepts.
Behavioural aspects.A currently-unexplored benefit of Bayesian open games is that neither maximisation of real numbers nor Bayes' law is involved in the definition of the categorical structure, and instead both enter when decisions are defined.This means that the same framework can equally well accommodate agents who neither perfectly maximise, nor update their beliefs strictly according to Bayes' law.This could make our framework useful for behavioural game theory, where such alternatives are considered (see, e.g.[4]).

Definition 2 . 2 . 1 (
Concrete lens).Let X, S, Y and R be sets.A concrete lens l

Definition 2 . 4 . 1 (
Now we have the necessary prerequisites in place to introduce the notion of a concrete open game.A concrete open game consists of a set of strategy profiles; a family of concrete lenses indexed by the set of strategy profiles; and a best-response function.Concrete open game).Let X, S, Y, and R be sets.A concrete open game G : (X, S) → (Y, R) is given by 1.A set of strategy profiles Σ; 2. A play function P : Σ → CL (X, S), (Y, R) ; and 3. A best-response function B : X × (Y → R) → Rel(Σ).

Definition 2 . 4 . 2 .
For convenience, in the definition of a concrete open game we work directly with a best-response relation rather than preference relations.The play function takes a strategy as argument and returns a concrete lens that describes an open play of the game G ('open' here means 'lacking a particular observation and outcome function' and is explained in the next paragraph).To justify this interpretation, recall that a concrete lens l : (X, S) → (Y, R) consists of v : X → Y and u : X × R → S. The view function v describes how a game decides on an action given an observation (similar to how strategies for sequential games work).The update function u describes precisely how games relay information about outcomes to other games acting earlier.As the name suggests, concrete open games are open to their environment.The appropriate notion of a context for a concrete open game is given in the following definition.A concrete open game together with a context can be thought of as a full description of a game.Let G : (X, S) → (Y, R).A history for G is an element x of X, an outcome function for G is a function k : Y → R, and a context for G is a pair (x, k) : X × (Y → R).

Definition 2 . 5 . 1 (
So far we have only seen open games for which the set of strategies is a singleton, describing games with no strategic decisions.Our first examples of a concrete open game with non-trivial strategy set are agents.These can be used to represent the utility maximising agents of traditional game theory or, more generally, to represent players trying to influence the outcome of a game.Agent).An agent A : (X, {⋆}) → (Y, R) is an atom whose set of strategies is Σ = CL (X, {⋆}), (Y, R) .
R) be concrete open games.G and H are equivalent, written G ∼ H, if there exists an isomorphism α : G → H.We write [G] for the equivalence class of G under this relation.We also say that the isomorphism α witnesses the equivalence between G and H and write G α ∼ H.The following results demonstrate that sequential and tensor composition of concrete open respects equivalence of concrete open games.

Corollary 2 . 10 . 4 .
There is a category ConGame with pairs of sets as object and equivalence classes of concrete open games as morphisms.
We can model this normal-form game using the concrete open gamec k • N i=1 A iwhere A i : I → (S i , R) is the utility maximising agent.The fixed points of this game's best-response relation are then the pure-strategy Nash equilibria of the normal-form game.

Definition 3 . 2 . 1 (Definition 3 . 2 . 2 (
Co-wedge).Let F : C op × C → D be a functor.A co-wedge c : F → α is an object α : D together with maps c a : F (a, a) → α a : C such that, for any morphism f :a ′ → a, the diagram α F (a, a) F (a ′ , a ′ ) F (a ′ , a) ca c a ′ F (a ′ , f ) F (f, a)commutes.Coend).A coend is a couniversal co-wedge.Diagrammatically, the coend of a functor F : C op × C → D is a co-wedge c a : F (a, a) → coend(F ) a : C such that for any other co-wedge d a : F (a, a) → α a : C and morphism f : a ′ → a the diagram coend(F ) F (a, a)

Theorem 3 . 3 . 7 (
Lens C is symmetric monoidal).The category Lens C is symmetric monoidal with the tensor given in Definition 3.3.6,monoidal unit I = (I C , I C ), and with structural morphisms inherited from C given by

Lemma 3 . 3 . 8 .
Lens Set is isomorphic to CL. (More generally, when ⊗ is cartesian, Lens C is isomorphic to an appropriately generalised definition of CL C .) Volume 5, Issue 9. ISSN 2631-4444 3.4 Towards generalising open games We could, at this point, attempt to define a (generalised) open game G : (X, S) → (Y, R) over a symmetric monoidal category C as 1.A set Σ of strategies; 2. A play function P : Σ → Lens C (X, S), (Y, R) ; and 3. A best-response function B : C(I, X) × C(Y, R) → Rel(Σ).

SRLemma 3 . 5 . 1 .
More verbosely, a state s ∈ Lens C (I, (X, S)) is the equivalence class of a choice of type A : C together with a state s : C(I, A ⊗ X) in C and an effect s ′ : C(A ⊗ S, I) in C. A useful interpretation of states in Lens C is as a history/cohistory pair.(Cohistories are not yet well understood.They make proofs easier, but vanish in categories which make game-theoretic sense.)An effect [e, e ′ ] ∈ Lens C ((Y, R), I) has the form e Concerning effects, we have the following result.C(Y, R) ∼ = Lens C ((Y, R), I)

Definition 3 . 5 . 2 (Definition 3 . 6 . 1 (Definition 3 . 6 . 2 .Example 3 . 6 . 3 .Example 3 . 6 . 4 (
Context functor).The context functor C : Lens C × Lens op C → Set is given by C(Φ, Ψ) = Θ:Lens C Lens C (I, Θ ⊗ Φ) × Lens C (Θ ⊗ Ψ, I) = Lens Lens C (I, (Φ, Ψ)) Elements of C(Φ, Ψ) are called contexts.(We use the letters Φ, Ψ to refer to objects of Lens C , which are pairs of objects of C.) As a context [p, k] ∈ C(Φ, Ψ) is just a state in Lens Lens C , so it admits a graphical representation as p Φ k Ψ .This is neat, and means many of the results in the rest of this section can be carried out graphically.Volume 5, Issue 9. ISSN 2631-4444 3.6 General open games We have now arrived at a level of generality where we can define generalised open games in a way that is obviously analogous to concrete open games.Given Φ, Ψ ∈ Lens C , an open game consists of a set of strategy profiles, a family of lenses indexed by the set of strategy profiles, and a best-response function which takes a context as input and returns a relation on strategy profiles.Open game).Let Φ, Ψ ∈ Lens C .An open game G : Φ → Ψ consists of 1.A set of strategy profiles Σ; 2. A play function P : Σ → Lens C (Φ, Ψ); and 3. A best-response function B : C(Φ, Ψ) → Rel(Σ).The rationale here is much the same as it is with concrete open games.The play function takes a strategy profile as input and returns a lens describing an open play of the game.Best response takes a context as argument that provides the information necessary for the game to make informed strategic decisions, and returns a relation on strategies.As with concrete open games, we define a notion of atomic open game: An atomic open game a : Φ → Ψ is an open game such that 1. Σ a ⊆ Lens C (Φ, Ψ); 2. For all l ∈ Σ a , P a (l) = l; and 3.For all contexts c ∈ C(Φ, Ψ), B a (c) is constant.Atomic open games are uniquely specified by a subset Σ ⊆ Lens C (Φ, Ψ) and a selection function B : C(Φ, Ψ) → P(Σ), and we will sometimes specify atomic open games via this data.We refer to atomic open games simply as atoms.The identity atom id Φ : Φ → Φ is given by Σ = {id Φ }, B(c) = {id Φ } for all c ∈ C(Φ, Φ).Computation).Let f : C(X, Y ) and g : C(R, S) be morphisms in C. Define the atom ⟨f, g⟩ : (X, S) → (Y, R) by 1. Σ ⟨f,g⟩ = {[f, g]}; and 2. B ⟨f,g⟩ (c) = {[f, g]} for all c ∈ C (X, S), (Y, R) .

Ξ 3 . 8 Definition 3 . 8 . 1 (
Given a context [p, k] ∈ C(Φ, Ξ) represented by the diagram p Φ k Ψ the local context for G given a strategy τ ∈ Σ H is given by p strategy σ ∈ Σ G the local context for H is given by p In this representation the process of taking a local context is non-arbitrary, and obviously associative.The tensor of open games Again, the heuristic for defining the tensor of open games is much as it was for concrete open games.We will first formalise the notion of 'local context' for tensored general open games.Local contexts for tensor composition).Define the left local context function

Lemma 3 . 10 . 1 .
That equivalence classes of open games form a category follows easily from the fact that coend lenses form a category.Sequential composition of equivalence classes of open games is associative.Proof.Suppose we have open games Φ

Theorem 3 . 10 . 2 .
If Lens C exists, there exists a category Game C with pairs of objects in C as objects and equivalence classes of open games as morphisms.

Lemma 3 . 11 . 4 .
The structural isomorphisms are natural in Game C .
is easily seen to correspond to a history for an open game and the function k : Θ ⊗ Y → R acts like an outcome function.In this way, we can specify a context for an open game in much the same way as we did for concrete open games in section 2[p, k] ∈ Lens C ((I, R), (X, Y )) neatly illustrates that a context is a game state with a 'hole' in it.If we think of a game G : (X, S) → (Y, R) as a player in a larger game, then p corresponds to the things that have happened in the game before G gets to act; k corresponds to what will happen in the game after G acts; and the gap in the diagram corresponds to the part of the game where G gets to influence the outcome.Alternatively, a context is that which becomes a game once G has decided which strategy to play, whereby playing that strategy will fill in the gap in the context.Given open games G

Definition 4 . 2 . 5 (
in Kl(D) correspond to taking marginals.Marginals).Let p : D(X × Y ) be a joint distribution.The left marginal p X : D(X) is given by p X (x) = y∈supp(p(x,−)) p(x, y).The right marginal p Y : D(Y ) is given similarly by p Y (y) = x∈supp(p(−,y)) p(x, y).As diagrams, these are given by p

Lemma 4 . 2 . 7 .
The update operator is natural in Θ.That is, the following diagram commutes for any

2 .Definition 4 . 4 . 1 ( 3 .
Update this prior based on an observation to a new posterior; 3. Attempt to maximise their expected utility given their posterior.Bayesian agent).Let X, Y be sets.The Bayesian agent A (X,Y ) : (X, I) → (Y, R) is the Bayesian atom given by 1. Σ A = X → D(Y ), The selection function ε : Lens Kl(D) ((I, R), (X, Y )) → P(X → D(Y )) is given by

Definition 4 . 4 . 3 .X
Let A (X,Y ) : (X, I) → (Y, R) be a Bayesian agent.Define A ∆ (X,Y ) : (X, I) → (X × Y, R) to be the Bayesian open game (id (X,1) ⊗ A (X,Y ) ) • ∆ X ,or as a string diagram, Lemma 4.4.4.A ∆ (X,Y ) is explicitly given, up to isomorphism, by 1. Σ A ∆ (X,Y ) = X → D(Y ); 2. P A ∆ (X,Y ) : Σ A ∆ (X,Y ) Decision problems under risk are generally represented by Bayesian open games constructed from computations and precisely one Bayesian agent.A simple subclass of decision problems under risk are represented by Bayesian open games of the form p agent A attempts to maximise their outcome which is, in part, dependent on the type Z which A does not observe.

1 =
A 2 = Θ, and π.The Bayesian open game describing this situation is given by the string diagram A (Θ,Θ) G : I → I in the category of Bayesian open games, this has Σ G = (Θ → D(Θ)) × (Θ → D(Θ)), the set of behavioural strategy profiles for the auction, and B G ( * ) the best-response relation for behavioural strategy profiles.4.6.4General construction for games in Bayesian form Generalising the previous example, we can give a construction for converting any game in Bayesian form into a Bayesian open game of type I → I that has the same best-response relation.
and thus is equivalent to one of the form (1, * , k) where * is the unique distribution on one point and k : X i → D(R N ), by taking k to be the partial application of k′ : Θ×X i+1 → D(R N ) to p : D(Θ).Then B Gi•••••G0 ([ * , k])(σ)is the set of best responses to σ in the extensive form game given by G i together with payoffs, where the ith player's payoff from the leaf node x ∈ X i is E[k(x) i ] (where k(x) i is the ith marginal of the joint distribution k(x) : D(R N )).By taking i = L in the previous lemma and then post-composing with G L+1 , we obtain the final result.

Theorem 4 . 7 . 4 .
G = G L+1 • • • • • G 0 : (1, 1) → (1,1) is given by the following: • The set of strategy profiles of G is the set of behavioural strategy profiles of the original extensive form game G • Every context is equivalent to one of the form (1, * , * ), and for a behavioural strategy profile σ, B G (1, * , * )(σ) is the set of best responses to σ in G 5 Conclusion

Notation 2.4.3. String
diagrams in the category of open games will always be drawn with arrowheads on wires, whilst string diagrams in the ambient category will always be drawn without arrowheads.Atomic concrete open games are an important class of concrete open games, and are the basic components out of which more complex games are constructed.Whilst concrete open games can, in general, represent aggregates of agents responding to each other (in a way that will be made precise in 2.7 and 2.8), atomic concrete open games describe games in which there is no strategic interaction.Examples are simple computations in which no decisions are made whatsoever, and single agents that are sensitive only to a given context.

Definition 2.4.4 (Atomic
concrete open game).A concrete open game a Volume 5, Issue 9. ISSN 2631-4444We now move on to proving that ConGame is symmetric monoidal.
and B are utility maximising agents and c k is the counit game associated with k.In diagrammatic form, the structure of the game is made clear.Players A and B make independent choices from A and B respectively which are then used to generate two real numbers as outcomes.
2. A bimatrix game consists of Accepted in Compositionality on 2021-11-27.1.Finite set of actions A and B; and 2.An outcome function k : A × B → R 2 .A bimatrix game G = (A, B, k) is represented by the concrete open game Bimatrix games may not have a Nash equilibrium in pure strategies, but in cases that do have Nash equilibria, they appear as fixed points of the best-response function B : A × B → P(A × B) of the above concrete open game, i.e. strategy profiles (a, b) satisfying (a, b) ∈ B(a, b). y).
The monoidal tensor in Kl(D), which represents joint distributions, is not cartesian.Definition 4.2.4 (Copy/delete comonoid for Kl(D)).The copying map in Kl(D) is given explicitly by c X . ) follow easily from definitions.As for (3), we need to prove that the local context for eachA (Xi,Yi) is [p σ−i , k σ−i ].Note that the previous Lemma 4.4.4serves as the base case (n = 1) for an induction argument.The result then follows easily by considering that can represent this game using the open game