# A utility-maximizing varient of AIXI

_Response to: [Universal agents and utility functions](/lw/feo/universal_agents_and_utility_functions/)_

_Related approaches: [Hibbard (2012)](http://versita.metapress.com/content/q5523w34gk767041/?genre=article&id=doi%3a10.2478%2fv10229-011-0013-5),  [Hay (2005)](http://www.cs.auckland.ac.nz/~nickjhay/honours.revamped.pdf)  
_

Background
----------

Here is the function implemented by finite-lifetime [AI![\xi](http://www.codecogs.com/png.latex?\xi)](http://www.hutter1.net/ai/aixigentle.pdf):

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sum_{x_{k}\in X}\max_{y_{k+1}\in Y}\sum_{x_{k+1}\in X}...\max_{y_{m}\in Y}\sum_{x_{m}\in X}\left(r\left(x_{k}\right)+...+r\left(x_{m}\right)\right)\cdot\xi\left(\dot{y}\dot{x}_{<k}y\underline{x}_{k:m}\right)}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m}\in%20Y}\sum_{x_{m}\in%20X}\left%28r\left%28x_{k}\right%29+...+r\left%28x_{m}\right%29\right%29\cdot\xi\left%28\dot{y}\dot{x}_{%3Ck}y\underline{x}_{k:m}\right%29}),

where ![m](http://www.codecogs.com/png.latex?m) is the number of steps in the lifetime of the agent, ![k](http://www.codecogs.com/png.latex?k) is the current step being computed, ![X](http://www.codecogs.com/png.latex?X) is the set of possible observations, ![Y](http://www.codecogs.com/png.latex?Y) is the set of possible actions, ![r](http://www.codecogs.com/png.latex?r) is a function that extracts a reward value from an observation, a dot over a variable represents that its value is known to be the true value of the action or observation it represents, underlines represent that the variable is an input to a probability distribution, and ![\xi](http://www.codecogs.com/png.latex?%5Cxi) is a function that returns the probability of a sequence of observations, given a certain known history and sequence of actions, and starting from the Solomonoff prior. More formally,

![{\displaystyle \xi\left(\dot{y}\dot{x}_{<k}y\underline{x}_{k:m}\right)=\left(\sum_{q\in Q:q\left(y_{\leq m}\right)=x_{\leq m}}2^{-\ell\left(q\right)}\right)\diagup\left(\sum_{q\in Q:q\left(\dot{y}_{<k}\right)=\dot{x}_{<k}}2^{-\ell\left(q\right)}\right)}](http://www.codecogs.com/png.latex?{\displaystyle%20\xi\left%28\dot{y}\dot{x}_{%3Ck}y\underline{x}_{k:m}\right%29=\left%28\sum_{q\in%20Q:q\left%28y_{\leq%20m}\right%29=x_{\leq%20m}}2^{-\ell\left%28q\right%29}\right%29\diagup\left%28\sum_{q\in%20Q:q\left%28\dot{y}_{%3Ck}\right%29=\dot{x}_{%3Ck}}2^{-\ell\left%28q\right%29}\right%29}),

where ![Q](http://www.codecogs.com/png.latex?Q) is the set of all programs, ![\ell](http://www.codecogs.com/png.latex?\ell) is a function that returns the length of a program in bits, and a program applied to a sequence of actions returns the resulting sequence of observations. Notice that the denominator is a constant, depending only on the already known ![\dot{y}\dot{x}_{%3Ck}](http://www.codecogs.com/png.latex?\dot{y}\dot{x}_{%3Ck}), and multiplying by a positive constant does not change the argmax, so we can pretend that the denominator doesn't exist. If ![q](http://www.codecogs.com/png.latex?q) is a valid program, then any longer program with ![q](http://www.codecogs.com/png.latex?q) as a prefix is not a valid program, so ![{\displaystyle%20\sum_{q\in%20Q}2^{-\ell\left%28q\right%29}\leq1}](http://www.codecogs.com/png.latex?{\displaystyle%20\sum_{q\in%20Q}2^{-\ell\left%28q\right%29}\leq1}).

Problem
-------

A problem with this is that it can only optimize over the input it receives, not over aspects of the external world that it cannot observe. Given the chance, AI![\xi](http://www.codecogs.com/png.latex?%5Cxi) would hack its input channel so that it would only observe good things, instead of trying to make good things happen (in other words, it would [wirehead](/lw/fkx/a\_definition\_of\_wireheading/) itself). Anja [specified](/lw/feo/universal\_agents\_and\_utility\_functions/) a variant of AI![\xi](http://www.codecogs.com/png.latex?%5Cxi) in which she replaced the sum of rewards with a single utility value and made the domain of the utility function be the entire sequence of actions and observations instead of a single observation, like so:

![{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m}\in%20Y}\sum_{x_{m}\in%20X}U\left%28\dot{y}\dot{x}_{%3Ck}yx_{k:m}\right%29\cdot\xi\left%28\dot{y}\dot{x}_{%3Ck}y\underline{x}_{k:m}\right%29}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m}\in%20Y}\sum_{x_{m}\in%20X}U\left%28\dot{y}\dot{x}_{%3Ck}yx_{k:m}\right%29\cdot\xi\left%28\dot{y}\dot{x}_{%3Ck}y\underline{x}_{k:m}\right%29}).

This doesn't really solve the problem, because the utility function still only takes what the agent can see, rather than what is actually going on outside the agent. The situation is a little better because the utility function also takes into account the agent's actions, so it could punish actions that look like the agent is trying to wirehead itself, but if there was a flaw in the instructions not to wirehead, the agent would exploit it, so the incentive not to wirehead would have to be perfect, and this formulation is not very enlightening about how to do that.

_\[Edit: Hibbard (2012) also presents a solution to this problem. I haven't read all of it yet, but it appears to be fairly different from what I suggest in the next section.\]_

Solution
--------

Here's what I suggest instead: everything that happens is determined by the program that the world is running on and the agent's actions, so the domain of the utility function should be ![Q\times%20Y^{m}](http://www.codecogs.com/png.latex?Q\times%20Y^{m}). The apparent problem with that is that the formula for AI![\xi](http://www.codecogs.com/png.latex?\xi) does not contain any mention of elements of ![Q](http://www.codecogs.com/png.latex?Q). If we just take the original formula and replace ![r\left(x_{k}\right)+...+r\left(x_{m}\right)](http://www.codecogs.com/png.latex?r\left%28x_{k}\right%29+...+r\left%28x_{m}\right%29)

with ![U\left(q,\dot{y}_{<k}y_{k:m}\right)](http://www.codecogs.com/png.latex?U\left%28q,\dot{y}_{%3Ck}y_{k:m}\right%29), it wouldn't make any sense. However, if we expand out ![\xi](http://www.codecogs.com/png.latex?%5Cxi) in the original formula (excluding the unnecessary denominator), we can move the sum of rewards inside the sum over programs, like this:

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sum_{x_{k}\in X}\max_{y_{k+1}\in Y}\sum_{x_{k+1}\in X}...\max_{y_{m}\in Y}\sum_{x_{m}\in X}\sum_{q\in Q:q\left(y_{\leq m}\right)=x_{\leq m}}\left(r\left(x_{k}\right)+...+r\left(x_{m}\right)\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m}\in%20Y}\sum_{x_{m}\in%20X}\sum_{q\in%20Q:q\left%28y_{\leq%20m}\right%29=x_{\leq%20m}}\left%28r\left%28x_{k}\right%29+...+r\left%28x_{m}\right%29\right%292^{-\ell\left%28q\right%29}}).

Now it is easy to replace the sum of rewards with the desired utility function.

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sum_{x_{k}\in X}\max_{y_{k+1}\in Y}\sum_{x_{k+1}\in X}...\max_{y_{m}\in Y}\sum_{x_{m}\in X}\sum_{q\in Q:q\left(y_{\leq m}\right)=x_{\leq m}}U\left(q,\dot{y}_{<k}y_{k:m}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m}\in%20Y}\sum_{x_{m}\in%20X}\sum_{q\in%20Q:q\left%28y_{\leq%20m}\right%29=x_{\leq%20m}}U\left%28q,\dot{y}_{%3Ck}y_{k:m}\right%292^{-\ell\left%28q\right%29}}).

With this formulation, there is no danger of the agent wireheading, and all ![U](http://www.codecogs.com/png.latex?U) has to do is compute everything that happens when the agent performs a given sequence of actions in a given program, and decide how desirable it is. If the range of ![U](http://www.codecogs.com/png.latex?U) is unbounded, then this might not converge. Let's assume throughout this post that the range of ![U](http://www.codecogs.com/png.latex?U) is bounded.

_\[Edit: Hay (2005) presents a similar formulation to this.\]_

Extension to infinite lifetimes
-------------------------------

The previous discussion assumed that the agent would only have the opportunity to perform a finite number of actions. The situation gets a little tricky when the agent is allowed to perform an unbounded number of actions. Hutter uses a finite look-ahead approach for AI![\xi](http://www.codecogs.com/png.latex?%5Cxi), where on each step ![k](http://www.codecogs.com/png.latex?k), it pretends that it will only be performing ![m_{k}](http://www.codecogs.com/png.latex?m_{k}) actions, where ![\forall%20k\,%20m_{k}\gg%20k](http://www.codecogs.com/png.latex?\forall%20k\,%20m_{k}\gg%20k).

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sum_{x_{k}\in X}\max_{y_{k+1}\in Y}\sum_{x_{k+1}\in X}...\max_{y_{m_{k}}\in Y}\sum_{x_{m_{k}}\in X}\left(r\left(x_{k}\right)+...+r\left(x_{m_{k}}\right)\right)\cdot\xi\left(\dot{y}\dot{x}_{<k}y\underline{x}_{k:m_{k}}\right)}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m_{k}}\in%20Y}\sum_{x_{m_{k}}\in%20X}\left%28r\left%28x_{k}\right%29+...+r\left%28x_{m_{k}}\right%29\right%29\cdot\xi\left%28\dot{y}\dot{x}_{%3Ck}y\underline{x}_{k:m_{k}}\right%29}).

If we make the same modification to the utility-based variant, we get

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sum_{x_{k}\in X}\max_{y_{k+1}\in Y}\sum_{x_{k+1}\in X}...\max_{y_{m_{k}}\in Y}\sum_{x_{m_{k}}\in X}\sum_{q\in Q:q\left(y_{\leq m_{k}}\right)=x_{\leq m_{k}}}U\left(q,\dot{y}_{<k}y_{k:m_{k}}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sum_{x_{k}\in%20X}\max_{y_{k+1}\in%20Y}\sum_{x_{k+1}\in%20X}...\max_{y_{m_{k}}\in%20Y}\sum_{x_{m_{k}}\in%20X}\sum_{q\in%20Q:q\left%28y_{\leq%20m_{k}}\right%29=x_{\leq%20m_{k}}}U\left%28q,\dot{y}_{%3Ck}y_{k:m_{k}}\right%292^{-\ell\left%28q\right%29}}).

This is unsatisfactory because the domain of ![U](http://www.codecogs.com/png.latex?U) was supposed to consist of all the information necessary to determine everything that happens, but here, it is missing all the actions after step ![m_{k}](http://www.codecogs.com/png.latex?m_%7Bk%7D). One obvious thing to try is to set ![m_{k}:=\infty](http://www.codecogs.com/png.latex?m_{k}:=\infty). This will be easier to do using a compacted expression for AI![\xi](http://www.codecogs.com/png.latex?%5Cxi):

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\max_{p\in P:p\left(\dot{x}_{<k}\right)=\dot{y}_{<k}y_{k}}\sum_{q\in Q:q\left(\dot{y}_{<k}\right)=\dot{x}_{<k}}\left(r\left(x_{k}^{pq}\right)+...+r\left(x_{m_{k}}^{pq}\right)\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\max_{p\in%20P:p\left%28\dot{x}_{%3Ck}\right%29=\dot{y}_{%3Ck}y_{k}}\sum_{q\in%20Q:q\left%28\dot{y}_{%3Ck}\right%29=\dot{x}_{%3Ck}}\left%28r\left%28x_{k}^{pq}\right%29+...+r\left%28x_{m_{k}}^{pq}\right%29\right%292^{-\ell\left%28q\right%29}}),

where ![P](http://www.codecogs.com/png.latex?P) is the set of policies that map sequences of observations to sequences of actions and ![x_{i}^{pq}](http://www.codecogs.com/png.latex?x_{i}^{pq}) is shorthand for the last observation in the sequence returned by ![q\left(p\left(\dot{x}_{<k}x_{k:i-1}^{pq}\right)\right)](http://www.codecogs.com/png.latex?q\left%28p\left%28\dot{x}_{%3Ck}x_{k:i-1}^{pq}\right%29\right%29). If we take this compacted formulation, modify it to accommodate the new utility function, set ![m_{k}:=\infty](http://www.codecogs.com/png.latex?m_%7Bk%7D:=%5Cinfty), and replace the maximum with a supremum (since there's an infinite number of possible policies), we get

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sup_{p\in P:p\left(\dot{x}_{<k}\right)=\dot{y}_{<k}y_{k}}\sum_{q\in Q:q\left(\dot{y}_{<k}\right)=\dot{x}_{<k}}U\left(q,\dot{y}_{<k}y_{k}y_{k+1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sup_{p\in%20P:p\left%28\dot{x}_{%3Ck}\right%29=\dot{y}_{%3Ck}y_{k}}\sum_{q\in%20Q:q\left%28\dot{y}_{%3Ck}\right%29=\dot{x}_{%3Ck}}U\left%28q,\dot{y}_{%3Ck}y_{k}y_{k+1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}),

where ![y_{i}^{pq}](http://www.codecogs.com/png.latex?y_{i}^{pq}) is shorthand for the last action in the sequence returned by ![p\left(q\left(\dot{y}_{<k}y_{k}y_{k+1:i-1}^{pq}\right)\right)](http://www.codecogs.com/png.latex?p\left%28q\left%28\dot{y}_{%3Ck}y_{k}y_{k+1:i-1}^{pq}\right%29\right%29).

But there is a problem with this, which I will illustrate with a toy example. Suppose ![Y:=\left\{ a,b\right\} ](http://www.codecogs.com/png.latex?Y:=\left\{%20a,b\right\}), and ![U\left(q,y_{1:\infty}\right)=0](http://www.codecogs.com/png.latex?U\left%28q,y_{1:\infty}\right%29=0) when ![\forall k\in\mathbb{N}\, y_{k}=a](http://www.codecogs.com/png.latex?\forall%20k\in\mathbb{N}\,%20y_{k}=a), and for any ![n\in\mathbb{N}](http://www.codecogs.com/png.latex?n\in\mathbb{N}), ![U\left(q,y_{1:\infty}\right)=1-\frac{1}{n}](http://www.codecogs.com/png.latex?U\left%28q,y_{1:\infty}\right%29=1-\frac{1}{n}) when ![y_{n}=b](http://www.codecogs.com/png.latex?y_{n}=b) and ![\forall k<n\, y_{k}=a](http://www.codecogs.com/png.latex?\forall%20k%3Cn\,%20y_{k}=a). (![U](http://www.codecogs.com/png.latex?U) does not depend on the program ![q](http://www.codecogs.com/png.latex?q) in this example). An agent following the above formula would output ![a](http://www.codecogs.com/png.latex?a) on every step, and end up with a utility of ![0](http://www.codecogs.com/png.latex?0), when it could have gotten arbitrarily close to ![1](http://www.codecogs.com/png.latex?1) by eventually outputting ![b](http://www.codecogs.com/png.latex?b).

To avoid problems like that, we could assume the reasonable-seeming condition that if ![y_{1:\infty}](http://www.codecogs.com/png.latex?y_{1:\infty}) is an action sequence and ![\left\{ y_{1:\infty}^{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?\left\{%20y_{1:\infty}^{n}\right\}%20_{n=1}^{\infty}) is a sequence of action sequences that converges to ![y_{1:\infty}](http://www.codecogs.com/png.latex?y_{1:\infty}) (by which I mean ![\forall k\in\mathbb{N}\,\exists N\in\mathbb{N}\,\forall n>N\, y_{k}^{n}=y_{k}](http://www.codecogs.com/png.latex?\forall%20k\in\mathbb{N}\,\exists%20N\in\mathbb{N}\,\forall%20n%3EN\,%20y_{k}^{n}=y_{k})), then ![{\displaystyle \lim_{n\rightarrow\infty}U\left(q,y_{1:\infty}^{n}\right)=U\left(q,y_{1:\infty}\right)}](http://www.codecogs.com/png.latex?{\displaystyle%20\lim_{n\rightarrow\infty}U\left%28q,y_{1:\infty}^{n}\right%29=U\left%28q,y_{1:\infty}\right%29}).

Under that assumption, the supremum is in fact a maximum, and the formula gives you an action sequence that will reach that maximum (proof below).

If you don't like the condition I imposed on ![U](http://www.codecogs.com/png.latex?U), you might not be satisfied by this. But without it, there is not necessarily a best policy. One thing you can do is, on step 1, pick some extremely small ![\varepsilon>0](http://www.codecogs.com/png.latex?\varepsilon%3E0), pick any element from

![{\displaystyle \left\{ p^{*}\in P:\sum_{q\in Q}U\left(q,y_{1:\infty}^{p^{*}q}\right)2^{-\ell\left(q\right)}>\left(\sup_{p\in P}\sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}\right)-\varepsilon\right\} }](http://www.codecogs.com/png.latex?{\displaystyle%20\left\{%20p^{*}\in%20P:\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p^{*}q}\right%292^{-\ell\left%28q\right%29}%3E\left%28\sup_{p\in%20P}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}\right%29-\varepsilon\right\}%20}), and then follow that policy for the rest of eternity, which will guarantee that you do not miss out on more than ![\varepsilon](http://www.codecogs.com/png.latex?\varepsilon) of expected utility.

Proof of criterion for supremum-chasing working
-----------------------------------------------

definition: If ![y_{1:\infty}](http://www.codecogs.com/png.latex?y_{1:\infty}) is an action sequence and ![\left\{ y_{1:\infty}^{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?\left\{%20y_{1:\infty}^{n}\right\}%20_{n=1}^{\infty}) is an infinite sequence of action sequences, and ![\forall k\in\mathbb{N}\,\exists N\in\mathbb{N}\,\forall n>N\, y_{k}^{n}=y_{k}](http://www.codecogs.com/png.latex?\forall%20k\in\mathbb{N}\,\exists%20N\in\mathbb{N}\,\forall%20n%3EN\,%20y_{k}^{n}=y_{k}), then we say ![\left\{ y_{1:\infty}^{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?\left\{%20y_{1:\infty}^{n}\right\}%20_{n=1}^{\infty}) converges to ![y_{1:\infty}](http://www.codecogs.com/png.latex?y_%7B1:%5Cinfty%7D). If ![p](http://www.codecogs.com/png.latex?p) is a policy and ![\left\{ p_{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?\left\{%20p_{n}\right\}%20_{n=1}^{\infty}) is a sequence of policies, and ![\forall k\in\mathbb{N}\,\forall x_{<k}\in X^{k}\,\exists N\in\mathbb{N}\,\forall n>N\, p\left(x_{<k}\right)=p_{n}\left(x_{<k}\right)](http://www.codecogs.com/png.latex?\forall%20k\in\mathbb{N}\,\forall%20x_{%3Ck}\in%20X^{k}\,\exists%20N\in\mathbb{N}\,\forall%20n%3EN\,%20p\left%28x_{%3Ck}\right%29=p_{n}\left%28x_{%3Ck}\right%29), then we say ![\left\{ p_{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?%5Cleft%5C%7B%20p_%7Bn%7D%5Cright%5C%7D%20_%7Bn=1%7D%5E%7B%5Cinfty%7D) converges to ![p](http://www.codecogs.com/png.latex?p).

assumption (for lemma 2 and theorem): If ![\left\{ y_{1:\infty}^{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?%5Cleft%5C%7B%20y_%7B1:%5Cinfty%7D%5E%7Bn%7D%5Cright%5C%7D%20_%7Bn=1%7D%5E%7B%5Cinfty%7D) converges to ![y_{1:\infty}](http://www.codecogs.com/png.latex?y_%7B1:%5Cinfty%7D), then ![{\displaystyle \lim_{n\rightarrow\infty}U\left(q,y_{1:\infty}^{n}\right)=U\left(q,y_{1:\infty}\right)}](http://www.codecogs.com/png.latex?{\displaystyle%20\lim_{n\rightarrow\infty}U\left%28q,y_{1:\infty}^{n}\right%29=U\left%28q,y_{1:\infty}\right%29}).

lemma 1: The agent described by

![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sup_{p\in P:p\left(\dot{x}_{<k}\right)=\dot{y}_{<k}y_{k}}\sum_{q\in Q:q\left(\dot{y}_{<k}\right)=\dot{x}_{<k}}U\left(q,\dot{y}_{<k}y_{k}y_{k+1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sup_{p\in%20P:p\left%28\dot{x}_{%3Ck}\right%29=\dot{y}_{%3Ck}y_{k}}\sum_{q\in%20Q:q\left%28\dot{y}_{%3Ck}\right%29=\dot{x}_{%3Ck}}U\left%28q,\dot{y}_{%3Ck}y_{k}y_{k+1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}) follows a policy that is the limit of a sequence of policies ![\left\{ p_{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?%5Cleft%5C%7B%20p_%7Bn%7D%5Cright%5C%7D%20_%7Bn=1%7D%5E%7B%5Cinfty%7D) such that

![{\displaystyle \lim_{n\rightarrow\infty}\sum_{q\in Q}U\left(q,y_{1:\infty}^{p_{n}q}\right)2^{-\ell\left(q\right)}=\sup_{p\in P}\sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\lim_{n\rightarrow\infty}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p_{n}q}\right%292^{-\ell\left%28q\right%29}=\sup_{p\in%20P}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}).

proof of lemma 1: Any policy can be completely described by the last action it outputs for every finite observation sequence. Observations are returned by a program, so the set of possible finite observation sequences is countable. It is possible to fix the last action returned on any particular finite observation sequence to be the argmax, and still get arbitrarily close to the supremum with suitable choices for the last action returned on the other finite observation sequences. By induction, it is possible to get arbitrarily close to the supremum while fixing the last action returned to be the argmax for any finite set of finite observation sequences. Thus, there exists a sequence of policies approaching the policy that the agent implements whose expected utilities approach the supremum.

lemma 2: If ![p](http://www.codecogs.com/png.latex?p) is a policy and ![\left\{ p_{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?%5Cleft%5C%7B%20p_%7Bn%7D%5Cright%5C%7D%20_%7Bn=1%7D%5E%7B%5Cinfty%7D) is a sequence of policies converging to ![p](http://www.codecogs.com/png.latex?p), then

![{\displaystyle \sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}=\lim_{n\rightarrow\infty}\sum_{q\in Q}U\left(q,y_{1:\infty}^{p_{n}q}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}=\lim_{n\rightarrow\infty}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p_{n}q}\right%292^{-\ell\left%28q\right%29}}).

proof of lemma 2: Let ![\varepsilon>0](http://www.codecogs.com/png.latex?%5Cvarepsilon%3E0). On any given sequence of inputs ![x_{1:\infty}\in X^{\infty}](http://www.codecogs.com/png.latex?x_{1:\infty}\in%20X^{\infty}), ![\left\{ p_{n}\left(x_{1:\infty}\right)\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?\left\{%20p_{n}\left%28x_{1:\infty}\right%29\right\}%20_{n=1}^{\infty}) converges to ![p\left(x_{1:\infty}\right)](http://www.codecogs.com/png.latex?p\left%28x_{1:\infty}\right%29), so, by assumption, ![\forall q\in Q\,\exists N\in\mathbb{N}\,\forall n\geq N\,\left|U\left(q,y_{1:\infty}^{pq}\right)-U\left(q,y_{1:\infty}^{p_{n}q}\right)\right|<\frac{\varepsilon}{2}](http://www.codecogs.com/png.latex?\forall%20q\in%20Q\,\exists%20N\in\mathbb{N}\,\forall%20n\geq%20N\,\left|U\left%28q,y_{1:\infty}^{pq}\right%29-U\left%28q,y_{1:\infty}^{p_{n}q}\right%29\right|%3C\frac{\varepsilon}{2}).

For each ![N\in\mathbb{N}](http://www.codecogs.com/png.latex?N\in\mathbb{N}), let ![Q_{N}:=\left\{ q\in Q:\forall n\geq N\,\left|U\left(q,y_{1:\infty}^{pq}\right)-U\left(q,y_{1:\infty}^{p_{n}q}\right)\right|<\frac{\varepsilon}{2}\right\} ](http://www.codecogs.com/png.latex?Q_{N}:=\left\{%20q\in%20Q:\forall%20n\geq%20N\,\left|U\left%28q,y_{1:\infty}^{pq}\right%29-U\left%28q,y_{1:\infty}^{p_{n}q}\right%29\right|%3C\frac{\varepsilon}{2}\right\}). The previous statement implies that ![{\displaystyle \bigcup_{N\in\mathbb{N}}Q_{N}=Q}](http://www.codecogs.com/png.latex?{\displaystyle%20\bigcup_{N\in\mathbb{N}}Q_{N}=Q}), and each element of ![\left\{ Q_{N}\right\} _{N\in\mathbb{N}}](http://www.codecogs.com/png.latex?\left\{%20Q_{N}\right\}%20_{N\in\mathbb{N}}) is a subset of the next, so

![{\displaystyle \exists N\in\mathbb{N}\,\sum_{q\in Q\setminus Q_{N}}2^{-\ell\left(q\right)}<\frac{\varepsilon}{2\left(\sup U-\inf U\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\exists%20N\in\mathbb{N}\,\sum_{q\in%20Q\setminus%20Q_{N}}2^{-\ell\left%28q\right%29}%3C\frac{\varepsilon}{2\left%28\sup%20U-\inf%20U\right%29}}). The range of ![U](http://www.codecogs.com/png.latex?U) is bounded, so ![\sup U](http://www.codecogs.com/png.latex?\sup%20U) and ![\inf U](http://www.codecogs.com/png.latex?\inf%20U) are defined. This also implies that the difference in expected utility, given any information, of any two policies, is bounded. More formally:![{\displaystyle \forall Q'\subset Q\,\forall p',p''\in P\,\left|\left(\left(\sum_{q\in Q'}U\left(q,y_{1:\infty}^{p'q}\right)2^{-\ell\left(q\right)}\right)\diagup\left(\sum_{q\in Q'}2^{-\ell\left(q\right)}\right)\right)-\left(\left(\sum_{q\in Q'}U\left(q,y_{1:\infty}^{p''q}\right)2^{-\ell\left(q\right)}\right)\diagup\left(\sum_{q\in Q'}2^{-\ell\left(q\right)}\right)\right)\right|\leq\sup U-\inf U}](http://www.codecogs.com/png.latex?{\displaystyle%20\forall%20Q%27\subset%20Q\,\forall%20p%27,p%27%27\in%20P\,\left|\left%28\left%28\sum_{q\in%20Q%27}U\left%28q,y_{1:\infty}^{p%27q}\right%292^{-\ell\left%28q\right%29}\right%29\diagup\left%28\sum_{q\in%20Q%27}2^{-\ell\left%28q\right%29}\right%29\right%29-\left%28\left%28\sum_{q\in%20Q%27}U\left%28q,y_{1:\infty}^{p%27%27q}\right%292^{-\ell\left%28q\right%29}\right%29\diagup\left%28\sum_{q\in%20Q%27}2^{-\ell\left%28q\right%29}\right%29\right%29\right|\leq\sup%20U-\inf%20U}),

so in particular,

![{\displaystyle \left|\left(\sum_{q\in Q\setminus Q_{N}}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}\right)-\left(\sum_{q\in Q\setminus Q_{N}}U\left(q,y_{1:\infty}^{p_{N}q}\right)2^{-\ell\left(q\right)}\right)\right|\leq\left(\sup U-\inf U\right)\sum_{q\in Q\setminus Q_{N}}2^{-\ell\left(q\right)}<\frac{\varepsilon}{2}}](http://www.codecogs.com/png.latex?{\displaystyle%20\left|\left%28\sum_{q\in%20Q\setminus%20Q_{N}}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}\right%29-\left%28\sum_{q\in%20Q\setminus%20Q_{N}}U\left%28q,y_{1:\infty}^{p_{N}q}\right%292^{-\ell\left%28q\right%29}\right%29\right|\leq\left%28\sup%20U-\inf%20U\right%29\sum_{q\in%20Q\setminus%20Q_{N}}2^{-\ell\left%28q\right%29}%3C\frac{\varepsilon}{2}}).

![{\displaystyle \left|\left(\sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}\right)-\left(\sum_{q\in Q}U\left(q,y_{1:\infty}^{p_{N}q}\right)2^{-\ell\left(q\right)}\right)\right|\leq\left|\left(\sum_{q\in Q_{N}}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}\right)-\left(\sum_{q\in Q_{N}}U\left(q,y_{1:\infty}^{p_{N}q}\right)2^{-\ell\left(q\right)}\right)\right|+\left|\left(\sum_{q\in Q\setminus Q_{N}}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}\right)-\left(\sum_{q\in Q}U\left(q,y_{1:\infty}^{p_{N}q}\right)2^{-\ell\left(q\right)}\right)\right|<\frac{\varepsilon}{2}+\frac{\varepsilon}{2}=\varepsilon}](http://www.codecogs.com/png.latex?{\displaystyle%20\left|\left%28\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}\right%29-\left%28\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p_{N}q}\right%292^{-\ell\left%28q\right%29}\right%29\right|\leq\left|\left%28\sum_{q\in%20Q_{N}}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}\right%29-\left%28\sum_{q\in%20Q_{N}}U\left%28q,y_{1:\infty}^{p_{N}q}\right%292^{-\ell\left%28q\right%29}\right%29\right|+\left|\left%28\sum_{q\in%20Q\setminus%20Q_{N}}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}\right%29-\left%28\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p_{N}q}\right%292^{-\ell\left%28q\right%29}\right%29\right|%3C\frac{\varepsilon}{2}+\frac{\varepsilon}{2}=\varepsilon}).

theorem:

![{\displaystyle \sum_{\dot{q}\in Q}U\left(\dot{q},\dot{y}_{1:\infty}\right)2^{-\ell\left(\dot{q}\right)}=\sup_{p\in P}\sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\sum_{\dot{q}\in%20Q}U\left%28\dot{q},\dot{y}_{1:\infty}\right%292^{-\ell\left%28\dot{q}\right%29}=\sup_{p\in%20P}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}),

where ![{\displaystyle \dot{y}_{k}:=\arg\max_{y_{k}\in Y}\sup_{p\in P:p\left(\dot{x}_{<k}\right)=\dot{y}_{<k}y_{k}}\sum_{q\in Q:q\left(\dot{y}_{<k}\right)=\dot{x}_{<k}}U\left(q,\dot{y}_{<k}y_{k}y_{k+1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\dot{y}_{k}:=\arg\max_{y_{k}\in%20Y}\sup_{p\in%20P:p\left%28\dot{x}_{%3Ck}\right%29=\dot{y}_{%3Ck}y_{k}}\sum_{q\in%20Q:q\left%28\dot{y}_{%3Ck}\right%29=\dot{x}_{%3Ck}}U\left%28q,\dot{y}_{%3Ck}y_{k}y_{k+1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}).

proof of theorem: Let's call the policy implemented by the agent ![p^{*}](http://www.codecogs.com/png.latex?p^{*}).

By lemma 1, there is a sequence of policies ![\left\{ p_{n}\right\} _{n=1}^{\infty}](http://www.codecogs.com/png.latex?\left\{%20p_{n}\right\}%20_{n=1}^{\infty})

converging to ![p^{*}](http://www.codecogs.com/png.latex?p%5E%7B*%7D) such that

![{\displaystyle \lim_{n\rightarrow\infty}\sum_{q\in Q}U\left(q,y_{1:\infty}^{p_{n}q}\right)2^{-\ell\left(q\right)}=\sup_{p\in P}\sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\lim_{n\rightarrow\infty}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p_{n}q}\right%292^{-\ell\left%28q\right%29}=\sup_{p\in%20P}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}).

By lemma 2,

![{\displaystyle \sum_{q\in Q}U\left(q,y_{1:\infty}^{p^{*}q}\right)2^{-\ell\left(q\right)}=\sup_{p\in P}\sum_{q\in Q}U\left(q,y_{1:\infty}^{pq}\right)2^{-\ell\left(q\right)}}](http://www.codecogs.com/png.latex?{\displaystyle%20\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{p^{*}q}\right%292^{-\ell\left%28q\right%29}=\sup_{p\in%20P}\sum_{q\in%20Q}U\left%28q,y_{1:\infty}^{pq}\right%292^{-\ell\left%28q\right%29}}).

###