Selection functions and lenses

Posted on March 30, 2021

I’ve been wondering for several years how selection functions and lenses relate to each other, I felt intuitively that there should be some connection – and not just because they both show up in the foundations of game theory. Last night I came up with an answer, which isn’t a complete answer but looks like the starting point for a complete answer.

A selection function is a function of type π’₯RX=(Xβ†’R)β†’X\mathcal J_R X = (X \to R) \to X. The canonical example is arg⁑max⁑:(X→ℝ)β†’X\arg\max : (X \to \mathbb R) \to X, after choosing a single maximiser for every function (say that XX is a finite set to avoid worrying about existence of a maximiser). π’₯R\mathcal J_R is a strong monad, closely related to the continuation monad, with a highly non-obvious monad structure. Combining argmaxen using the monadic bind makes the backward induction algorithm from game theory fall out of pure category theory – see a string of papers by MartΓ­n EscardΓ³ and Paulo Oliva, especially Sequential games and optimal strategies for a good introduction.

Meanwhile, the category of lenses π‹πžπ§π¬\mathbf{Lens} has as objects pairs of sets (X,R)(X, R), and its morphisms (X,S)β†’(Y,R)(X, S) \to (Y, R) consist of pairs of functions v:Xβ†’Yv : X \to Y and u:XΓ—Rβ†’Su : X \times R \to S. The identity lens on (X,S)(X, S) consists of an identity function and a projection, and the composition of (v1,u1):(X,S)β†’(Y,R)(v_1, u_1) : (X, S) \to (Y, R) and (v2,u2):(Y,R)β†’(Z,Q)(v_2, u_2) : (Y, R) \to (Z, Q) consists of v(x)=v2(v1(x))v (x) = v_2 (v_1 (x)) and u(x,q)=u1(x,u2(v1(x),q))u (x, q) = u_1 (x, u_2 (v_1 (x), q)). Lenses also play a deep role in the foundations of game theory, via open games.

What I noticed is that there is a functor π’₯:π‹πžπ§π¬β†’π’πžπ­\mathcal J : \mathbf{Lens} \to \mathbf{Set}, taking the object (X,R)(X, R) to the set of selection functions π’₯(X,R)=π’₯RX=(Xβ†’R)β†’X\mathcal J (X, R) = \mathcal J_R X = (X \to R) \to X. Given a selection function Ξ΅:π’₯SX\varepsilon : \mathcal J_S X and a lens (v,u):(X,S)β†’(Y,R)(v, u) : (X, S) \to (Y, R), we can β€œpush forward” the selection function along the lens, to obtain a selection function π’₯(v,u)(Ξ΅):π’₯RY\mathcal J (v, u) (\varepsilon) : \mathcal J_R Y using the formula π’₯(v,u)(Ξ΅)(k)=v(Ξ΅(Ξ»x.u(x,k(v(x)))))\mathcal J (v, u) (\varepsilon) (k) = v (\varepsilon (\lambda x . u (x, k (v (x))))). This turns out to be functorial – pushing forward a selection function along the identity lens does nothing, and pushing forward a selection function along two lenses is the same as pushing forward along the composed lens.

The slick way to see this is to notice that there is a natural isomorphism (Xβ†’R)β†’Xβ‰…π‹πžπ§π¬((X,R),(1,1))β†’π‹πžπ§π¬((1,1),(X,R))(X \to R) \to X \cong \mathbf{Lens} ((X, R), (1, 1)) \to \mathbf{Lens} ((1, 1), (X, R)) – in other words, a selection function is a way to turn costates into states in the category of lenses. These two representable functors already play a deep role in open games.

I wanted to write a short blog post just to explain this much; how this connects to the monad structure of π’₯R\mathcal J_R, and what are the implications for game theory, remain to be seen. To me, this functor feels close to the beating heart of game theory.