{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "03a948b3b34a",
   "metadata": {},
   "source": [
    "# Chapter 14: Building a World Inside\n",
    "\n",
    "A planner evaluates tomorrow through an approximate transition model. Small one-step errors can matter more when the controller looks farther ahead. Yet a large worst-case bound does not mean the actual planning error reached it. Both quantities deserve separate places in the report.\n",
    "\n",
    "This notebook compares two finite kernels under one fixed policy and one common immediate reward vector. It computes their transition mismatch, propagates finite-horizon values, and plots actual value error beside the chapter's conditional horizon bound. The changed case lengthens the horizon without changing the model. The transfer case makes the kernels identical, giving an exact zero-error check before any more complicated interpretation.\n",
    "\n",
    "**Outcome:** Calculate uniform transition error, actual fixed-policy finite values, and conditional bounds.\n",
    "\n",
    "- Inspect the declared input contract\n",
    "- Predict the hand-checkable case\n",
    "- Run the shared computation\n",
    "- Change the critical assumption\n",
    "- Apply the method to the transfer data\n",
    "\n",
    "**Guided route:** Run the worked calculation, inspect its figure, change the stated assumption, and try the transfer case. Read the explanations beside each result before opening the answers.\n",
    "\n",
    "**Deeper route:** First read the mathematics and canonical equation reference. Audit the input contract, predict the changed result, then inspect the shared chapter implementation and solve the questions independently. Both routes use the same calculations and preserve the equations."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7781f3ee7dc",
   "metadata": {},
   "source": [
    "## Technical Requirements\n",
    "\n",
    "Python 3.11 or later, the complete laboratory folder, and the notebook dependencies listed in `requirements-notebooks.txt` (the launcher's **Install notebook tools** choice installs them; see START-HERE). Standard-library chapter commands also support Python 3.10. No API key, model account or network call is used by this experiment.\n",
    "\n",
    "Prior knowledge:\n",
    "\n",
    "- Python lists and dictionaries\n",
    "- The mapped chapter and its notation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5c3e4d9b3f6",
   "metadata": {},
   "source": [
    "## The question and its mathematics\n",
    "\n",
    "For each state, total variation between the true and modeled transition rows is half the sum of absolute probability differences. Uniform error epsilon is the maximum of those row distances. An average row error cannot replace that maximum in a uniform bound.\n",
    "\n",
    "With common expected immediate rewards in [0,R], one fixed policy, and discount gamma<1, the chapter's discounted value bound is gamma epsilon R/(1-gamma)^2. This quantity applies under those prerequisites; it is not an estimate fitted to the finite error curve. Reward-model mismatch would need another term.\n",
    "\n",
    "For H rewards and zero terminal continuation, the undiscounted finite-horizon bound is R epsilon H(H-1)/2. It also bounds the discounted finite calculation because discounting can only reduce these nonnegative error contributions. The implementation computes V_h=r+gamma P V_(h-1) and modeled W_h=r+gamma Q W_(h-1), starting both at zero, then records max_s |V_h(s)-W_h(s)|.\n",
    "\n",
    "The kernels already absorb a fixed policy. A state-value bound alone does not provide the uniform action-value error and action gap needed to certify a choice ranking. Keep that missing prerequisite explicit."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7d0db24f36c",
   "metadata": {},
   "source": [
    "## A calculation you can run\n",
    "\n",
    "Provide two aligned square probability matrices and one nonnegative reward vector. Every row must sum to one. Declare discount and horizon. The function computes the uniform total-variation error, maximum reward, both finite value recurrences, the actual maximum error at each horizon, and the two conditional bounds.\n",
    "\n",
    "Figures use reward horizon on the horizontal axis and reward units on the vertical axis. Plotting bound and actual error separately avoids disguising a small error beneath a large envelope. In the changed case increase horizon from five to twenty and predict how the quadratic envelope changes. Inspect the actual curve independently; it need not grow at the same rate. Export common-reward and fixed-policy assumptions with the numerical result.\n",
    "\n",
    "The next cell finds the bundle and imports the same computation used by the chapter skill. It does not change your system Python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "42ebefc0e5c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "import sys, json\n",
    "LAB_ROOT = next((p for p in [Path.cwd(), *Path.cwd().parents] if (p / \"lab-manifest.json\").is_file()), None)\n",
    "if LAB_ROOT is None:\n",
    "    raise RuntimeError(\"Open this notebook from the complete extracted laboratory folder.\")\n",
    "sys.path.insert(0, str(LAB_ROOT / \"src\"))\n",
    "from math_ai_agents.core import analyze, report_text\n",
    "from math_ai_agents.plotting import figure_svg\n",
    "from IPython.display import SVG, display\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fffde8c0edb",
   "metadata": {},
   "source": [
    "Set the declared inputs below. These are constructed teaching values, not measurements from a production agent. Change a value only after predicting what it should change."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a09bdc7645c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chapter 14: transition-model-bound\n",
      "How much value error can this approximate world model introduce?\n",
      "Evidence: constructed teaching example\n",
      "\n",
      "Calculated quantities:\n",
      "{\n",
      "  \"uniform_tv_error\": 0.02,\n",
      "  \"true_values\": [\n",
      "    0.55354113,\n",
      "    2.98801774\n",
      "  ],\n",
      "  \"model_values\": [\n",
      "    0.6403010023,\n",
      "    2.921214829\n",
      "  ],\n",
      "  \"max_finite_value_error\": 0.08675987227,\n",
      "  \"discounted_infinite_bound\": 1.8,\n",
      "  \"finite_horizon_bound\": 0.2\n",
      "}\n",
      "\n",
      "Interpretation:\n",
      "Both kernels share the same immediate reward vector under one fixed policy. The uniform total-variation error controls the conditional bound; the actual finite error can be much smaller.\n",
      "\n",
      "Assumptions:\n",
      "- Fixed policy absorbed into each transition matrix.\n",
      "- Common expected immediate reward in [0,R].\n",
      "- Finite calculation has zero terminal continuation; discounted bound assumes gamma below one.\n",
      "\n",
      "Limitations:\n",
      "- A bound is not a measured planning error.\n",
      "- This state-value bound alone does not certify an action ranking.\n",
      "- Reward-model error would require an additional term.\n",
      "\n",
      "Execution: completed locally; constructed inputs are not deployment measurements.\n"
     ]
    }
   ],
   "source": [
    "chapter = 14\n",
    "inputs = {'true_transition': [[0.9, 0.1], [0.2, 0.8]],\n",
    " 'model_transition': [[0.88, 0.12], [0.22, 0.78]],\n",
    " 'rewards': [0, 1],\n",
    " 'discount': 0.9,\n",
    " 'horizon': 5}\n",
    "report = analyze(chapter, inputs)\n",
    "# This input was explicitly taken from the teaching fixture.\n",
    "report['evidence_kind'] = 'constructed teaching example'\n",
    "print(report_text(report))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fbf4dcdb600",
   "metadata": {},
   "source": [
    "Both default row distances are 0.02, so epsilon=0.02. With R=1 and gamma=0.9, the discounted infinite bound is 1.8. At horizon 5 the finite bound is 0.02(5)(4)/2=0.2. The actual finite error is calculated from the two recurrences and must remain below the finite envelope.\n",
    "\n",
    "At horizon 20 the finite bound grows to 3.8, even though each transition row changed by the same amount. That growth is a sensitivity statement under a worst-case construction. It does not say that the actual error became 3.8, and it does not establish that any particular action ranking reversed.\n",
    "\n",
    "Two bounds are reported and both are valid. At horizon 20 the finite-horizon bound (3.8) is the looser one and the discounted infinite-horizon bound (1.8) the tighter, so the tightest valid statement is their minimum. The finite bound is not a stronger warning.\n",
    "\n",
    "The plot below uses the calculated quantities. Read each panel's units before comparing its values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "590f57e74048",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Matplotlib is building the font cache; this may take a moment.\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\" width=\"576pt\" height=\"417.6pt\" viewBox=\"0 0 576 417.6\" version=\"1.1\"><title>Calculated chapter experiment</title><desc>Labeled plot of the explicitly supplied chapter inputs. See the adjacent explanation for assumptions.</desc>\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Mathematics of AI Agents Laboratory</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 417.6  L 576 417.6  L 576 0  L 0 0  z \" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 54.442344 194.039062  L 565.2 194.039062  L 565.2 69.080234  L 54.442344 69.080234  z \" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"m7b97a3d564\" d=\"M 0 0  L 0 3.5  \" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"77.658601\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"77.658601\" y=\"208.636719\" transform=\"rotate(-0 77.658601 208.636719)\">1</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"193.739886\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"193.739886\" y=\"208.636719\" transform=\"rotate(-0 193.739886 208.636719)\">2</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"309.821172\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"309.821172\" y=\"208.636719\" transform=\"rotate(-0 309.821172 208.636719)\">3</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"425.902457\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"425.902457\" y=\"208.636719\" transform=\"rotate(-0 425.902457 208.636719)\">4</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"541.983743\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"541.983743\" y=\"208.636719\" transform=\"rotate(-0 541.983743 208.636719)\">5</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_6\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"309.821172\" y=\"222.6375\" transform=\"rotate(-0 309.821172 222.6375)\">reward horizon</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <path d=\"M 54.442344 188.359116  L 565.2 188.359116  \" clip-path=\"url(#p443349eec7)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_7\">\n",
       "      <defs>\n",
       "       <path id=\"m83d8ff9c5f\" d=\"M 0 0  L -3.5 0  \" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"188.359116\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"192.157944\" transform=\"rotate(-0 47.442344 192.157944)\">0.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <path d=\"M 54.442344 162.17214  L 565.2 162.17214  \" clip-path=\"url(#p443349eec7)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_9\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"162.17214\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"165.970968\" transform=\"rotate(-0 47.442344 165.970968)\">0.02</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <path d=\"M 54.442344 135.985164  L 565.2 135.985164  \" clip-path=\"url(#p443349eec7)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"135.985164\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"139.783992\" transform=\"rotate(-0 47.442344 139.783992)\">0.04</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <path d=\"M 54.442344 109.798188  L 565.2 109.798188  \" clip-path=\"url(#p443349eec7)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_13\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"109.798188\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"113.597016\" transform=\"rotate(-0 47.442344 113.597016)\">0.06</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <path d=\"M 54.442344 83.611212  L 565.2 83.611212  \" clip-path=\"url(#p443349eec7)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_15\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"83.611212\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"87.41004\" transform=\"rotate(-0 47.442344 87.41004)\">0.08</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_12\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"18.774375\" y=\"131.559648\" transform=\"rotate(-90 18.774375 131.559648)\">reward units</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_16\">\n",
       "    <path d=\"M 77.658601 188.359116  L 193.739886 164.790837  L 309.821172 133.82212  L 425.902457 102.8271  L 541.983743 74.760181  \" clip-path=\"url(#p443349eec7)\" style=\"fill: none; stroke: #31586b; stroke-width: 1.8; stroke-linecap: square\"/>\n",
       "    <defs>\n",
       "     <path id=\"m5f44242a68\" d=\"M 0 2  C 0.530406 2 1.03916 1.789267 1.414214 1.414214  C 1.789267 1.03916 2 0.530406 2 0  C 2 -0.530406 1.789267 -1.03916 1.414214 -1.414214  C 1.03916 -1.789267 0.530406 -2 0 -2  C -0.530406 -2 -1.03916 -1.789267 -1.414214 -1.414214  C -1.789267 -1.03916 -2 -0.530406 -2 0  C -2 0.530406 -1.789267 1.03916 -1.414214 1.414214  C -1.03916 1.789267 -0.530406 2 0 2  z \" style=\"stroke: #31586b\"/>\n",
       "    </defs>\n",
       "    <g clip-path=\"url(#p443349eec7)\">\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"77.658601\" y=\"188.359116\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"193.739886\" y=\"164.790837\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"309.821172\" y=\"133.82212\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"425.902457\" y=\"102.8271\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"541.983743\" y=\"74.760181\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 54.442344 194.039062  L 54.442344 69.080234  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 54.442344 194.039062  L 565.2 194.039062  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_13\">\n",
       "    <text style=\"font-size: 11px; font-family: 'DejaVu Sans'; text-anchor: start\" x=\"54.442344\" y=\"63.080234\" transform=\"rotate(-0 54.442344 63.080234)\">actual finite-horizon value error</text>\n",
       "   </g>\n",
       "  </g>\n",
       "  <g id=\"axes_2\">\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 54.442344 375.477656  L 565.2 375.477656  L 565.2 250.518828  L 54.442344 250.518828  z \" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_3\">\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"77.658601\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"77.658601\" y=\"390.075312\" transform=\"rotate(-0 77.658601 390.075312)\">1</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_18\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"193.739886\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_15\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"193.739886\" y=\"390.075312\" transform=\"rotate(-0 193.739886 390.075312)\">2</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_8\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"309.821172\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_16\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"309.821172\" y=\"390.075312\" transform=\"rotate(-0 309.821172 390.075312)\">3</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_9\">\n",
       "     <g id=\"line2d_20\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"425.902457\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_17\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"425.902457\" y=\"390.075312\" transform=\"rotate(-0 425.902457 390.075312)\">4</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_10\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m7b97a3d564\" x=\"541.983743\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_18\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"541.983743\" y=\"390.075312\" transform=\"rotate(-0 541.983743 390.075312)\">5</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_19\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"309.821172\" y=\"404.076094\" transform=\"rotate(-0 309.821172 404.076094)\">reward horizon</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_4\">\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_22\">\n",
       "      <path d=\"M 54.442344 369.79771  L 565.2 369.79771  \" clip-path=\"url(#pd9403035b3)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_23\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"369.79771\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_20\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"373.596538\" transform=\"rotate(-0 47.442344 373.596538)\">0.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_24\">\n",
       "      <path d=\"M 54.442344 341.397976  L 565.2 341.397976  \" clip-path=\"url(#pd9403035b3)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_25\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"341.397976\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_21\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"345.196804\" transform=\"rotate(-0 47.442344 345.196804)\">0.05</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_26\">\n",
       "      <path d=\"M 54.442344 312.998242  L 565.2 312.998242  \" clip-path=\"url(#pd9403035b3)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_27\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"312.998242\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_22\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"316.79707\" transform=\"rotate(-0 47.442344 316.79707)\">0.10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_9\">\n",
       "     <g id=\"line2d_28\">\n",
       "      <path d=\"M 54.442344 284.598509  L 565.2 284.598509  \" clip-path=\"url(#pd9403035b3)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_29\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"284.598509\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_23\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"288.397337\" transform=\"rotate(-0 47.442344 288.397337)\">0.15</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_10\">\n",
       "     <g id=\"line2d_30\">\n",
       "      <path d=\"M 54.442344 256.198775  L 565.2 256.198775  \" clip-path=\"url(#pd9403035b3)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_31\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m83d8ff9c5f\" x=\"54.442344\" y=\"256.198775\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_24\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"259.997603\" transform=\"rotate(-0 47.442344 259.997603)\">0.20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_25\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"18.774375\" y=\"312.998242\" transform=\"rotate(-90 18.774375 312.998242)\">reward units</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_32\">\n",
       "    <path d=\"M 77.658601 369.79771  L 193.739886 358.437816  L 309.821172 335.718029  L 425.902457 301.638349  L 541.983743 256.198775  \" clip-path=\"url(#pd9403035b3)\" style=\"fill: none; stroke: #31586b; stroke-width: 1.8; stroke-linecap: square\"/>\n",
       "    <g clip-path=\"url(#pd9403035b3)\">\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"77.658601\" y=\"369.79771\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"193.739886\" y=\"358.437816\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"309.821172\" y=\"335.718029\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"425.902457\" y=\"301.638349\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m5f44242a68\" x=\"541.983743\" y=\"256.198775\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 54.442344 375.477656  L 54.442344 250.518828  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path d=\"M 54.442344 375.477656  L 565.2 375.477656  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_26\">\n",
       "    <text style=\"font-size: 11px; font-family: 'DejaVu Sans'; text-anchor: start\" x=\"54.442344\" y=\"244.518828\" transform=\"rotate(-0 54.442344 244.518828)\">finite-horizon bound</text>\n",
       "   </g>\n",
       "  </g>\n",
       "  <g id=\"text_27\">\n",
       "   <text style=\"font-size: 12px; font-family: 'DejaVu Sans'; text-anchor: start\" x=\"46.08\" y=\"17.470125\" transform=\"rotate(-0 46.08 17.470125)\">Chapter 14: transition model bound</text>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p443349eec7\">\n",
       "   <rect x=\"54.442344\" y=\"69.080234\" width=\"510.757656\" height=\"124.958828\"/>\n",
       "  </clipPath>\n",
       "  <clipPath id=\"pd9403035b3\">\n",
       "   <rect x=\"54.442344\" y=\"250.518828\" width=\"510.757656\" height=\"124.958828\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(SVG(figure_svg(report)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1169a1f69a1e",
   "metadata": {},
   "source": [
    "**Figure 14.L1:** Calculated chapter experiment. Each panel labels its input and output units; interpret it under the assumptions printed in the report."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b3b8fdec2ca",
   "metadata": {},
   "source": [
    "## Change the assumption\n",
    "\n",
    "A common misuse inserts average model error into a uniform bound. A model may be accurate on frequently observed states and badly wrong at the one state that changes the plan. The maximum row distance protects the stated domain, while an average describes a different estimand.\n",
    "\n",
    "Another misuse compares reward functions that differ and then attributes all value error to transition mismatch. This input contract intentionally supplies only one common reward vector. If the model invents immediate reward, the implementation's bound assumptions no longer apply.\n",
    "\n",
    "Finally, an error bound is not a decision certificate. Even a small value bound can overwhelm a smaller action gap, and this fixed-policy state calculation does not inspect alternative actions. Use it to audit model sensitivity, then state the extra action-value and gap information required for ranking guarantees."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d2f981055e16",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chapter 14: transition-model-bound\n",
      "How much value error can this approximate world model introduce?\n",
      "Evidence: constructed changed-assumption example\n",
      "\n",
      "Calculated quantities:\n",
      "{\n",
      "  \"uniform_tv_error\": 0.02,\n",
      "  \"true_values\": [\n",
      "    2.027264312,\n",
      "    4.729704829\n",
      "  ],\n",
      "  \"model_values\": [\n",
      "    2.231030443,\n",
      "    4.694010975\n",
      "  ],\n",
      "  \"max_finite_value_error\": 0.2037661306,\n",
      "  \"discounted_infinite_bound\": 1.8,\n",
      "  \"finite_horizon_bound\": 3.8\n",
      "}\n",
      "\n",
      "Interpretation:\n",
      "Both kernels share the same immediate reward vector under one fixed policy. The uniform total-variation error controls the conditional bound; the actual finite error can be much smaller.\n",
      "\n",
      "Assumptions:\n",
      "- Fixed policy absorbed into each transition matrix.\n",
      "- Common expected immediate reward in [0,R].\n",
      "- Finite calculation has zero terminal continuation; discounted bound assumes gamma below one.\n",
      "\n",
      "Limitations:\n",
      "- A bound is not a measured planning error.\n",
      "- This state-value bound alone does not certify an action ranking.\n",
      "- Reward-model error would require an additional term.\n",
      "\n",
      "Execution: completed locally; constructed inputs are not deployment measurements.\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\" width=\"576pt\" height=\"417.6pt\" viewBox=\"0 0 576 417.6\" version=\"1.1\"><title>Calculated chapter experiment</title><desc>Labeled plot of the explicitly supplied chapter inputs. See the adjacent explanation for assumptions.</desc>\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Mathematics of AI Agents Laboratory</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 417.6  L 576 417.6  L 576 0  L 0 0  z \" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 54.442344 194.039062  L 565.2 194.039062  L 565.2 69.080234  L 54.442344 69.080234  z \" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"mba26063cd8\" d=\"M 0 0  L 0 3.5  \" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"77.658601\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"77.658601\" y=\"208.636719\" transform=\"rotate(-0 77.658601 208.636719)\">1</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"102.096766\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"102.096766\" y=\"208.636719\" transform=\"rotate(-0 102.096766 208.636719)\">2</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"126.534932\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"126.534932\" y=\"208.636719\" transform=\"rotate(-0 126.534932 208.636719)\">3</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"150.973097\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"150.973097\" y=\"208.636719\" transform=\"rotate(-0 150.973097 208.636719)\">4</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"175.411262\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"175.411262\" y=\"208.636719\" transform=\"rotate(-0 175.411262 208.636719)\">5</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"199.849428\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"199.849428\" y=\"208.636719\" transform=\"rotate(-0 199.849428 208.636719)\">6</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"224.287593\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"224.287593\" y=\"208.636719\" transform=\"rotate(-0 224.287593 208.636719)\">7</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_8\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"248.725758\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"248.725758\" y=\"208.636719\" transform=\"rotate(-0 248.725758 208.636719)\">8</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_9\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"273.163924\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"273.163924\" y=\"208.636719\" transform=\"rotate(-0 273.163924 208.636719)\">9</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_10\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"297.602089\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"297.602089\" y=\"208.636719\" transform=\"rotate(-0 297.602089 208.636719)\">10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_11\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"322.040255\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"322.040255\" y=\"208.636719\" transform=\"rotate(-0 322.040255 208.636719)\">11</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_12\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"346.47842\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"346.47842\" y=\"208.636719\" transform=\"rotate(-0 346.47842 208.636719)\">12</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_13\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"370.916585\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"370.916585\" y=\"208.636719\" transform=\"rotate(-0 370.916585 208.636719)\">13</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_14\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"395.354751\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"395.354751\" y=\"208.636719\" transform=\"rotate(-0 395.354751 208.636719)\">14</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_15\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"419.792916\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_15\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"419.792916\" y=\"208.636719\" transform=\"rotate(-0 419.792916 208.636719)\">15</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_16\">\n",
       "     <g id=\"line2d_16\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"444.231081\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_16\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"444.231081\" y=\"208.636719\" transform=\"rotate(-0 444.231081 208.636719)\">16</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_17\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"468.669247\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_17\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"468.669247\" y=\"208.636719\" transform=\"rotate(-0 468.669247 208.636719)\">17</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_18\">\n",
       "     <g id=\"line2d_18\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"493.107412\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_18\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"493.107412\" y=\"208.636719\" transform=\"rotate(-0 493.107412 208.636719)\">18</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_19\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"517.545578\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_19\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"517.545578\" y=\"208.636719\" transform=\"rotate(-0 517.545578 208.636719)\">19</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_20\">\n",
       "     <g id=\"line2d_20\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"541.983743\" y=\"194.039062\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_20\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"541.983743\" y=\"208.636719\" transform=\"rotate(-0 541.983743 208.636719)\">20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_21\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"309.821172\" y=\"222.6375\" transform=\"rotate(-0 309.821172 222.6375)\">reward horizon</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <path d=\"M 54.442344 188.359116  L 565.2 188.359116  \" clip-path=\"url(#pb38196150c)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_22\">\n",
       "      <defs>\n",
       "       <path id=\"m23b044fe28\" d=\"M 0 0  L -3.5 0  \" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"188.359116\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_22\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"192.157944\" transform=\"rotate(-0 47.442344 192.157944)\">0.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <path d=\"M 54.442344 160.484283  L 565.2 160.484283  \" clip-path=\"url(#pb38196150c)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_24\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"160.484283\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_23\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"164.283112\" transform=\"rotate(-0 47.442344 164.283112)\">0.05</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_25\">\n",
       "      <path d=\"M 54.442344 132.609451  L 565.2 132.609451  \" clip-path=\"url(#pb38196150c)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_26\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"132.609451\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_24\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"136.408279\" transform=\"rotate(-0 47.442344 136.408279)\">0.10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_27\">\n",
       "      <path d=\"M 54.442344 104.734619  L 565.2 104.734619  \" clip-path=\"url(#pb38196150c)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_28\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"104.734619\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_25\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"108.533447\" transform=\"rotate(-0 47.442344 108.533447)\">0.15</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_29\">\n",
       "      <path d=\"M 54.442344 76.859786  L 565.2 76.859786  \" clip-path=\"url(#pb38196150c)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_30\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"76.859786\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_26\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"80.658614\" transform=\"rotate(-0 47.442344 80.658614)\">0.20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_27\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"18.774375\" y=\"131.559648\" transform=\"rotate(-90 18.774375 131.559648)\">reward units</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_31\">\n",
       "    <path d=\"M 77.658601 188.359116  L 102.096766 178.324176  L 126.534932 165.138265  L 150.973097 151.941156  L 175.411262 139.990778  L 199.849428 129.643745  L 224.287593 120.858495  L 248.725758 113.444117  L 273.163924 107.176567  L 297.602089 101.847722  L 322.040255 97.281886  L 346.47842 93.337565  L 370.916585 89.903436  L 395.354751 86.892691  L 419.792916 84.237583  L 444.231081 81.884845  L 468.669247 79.792077  L 493.107412 77.925022  L 517.545578 76.255548  L 541.983743 74.760181  \" clip-path=\"url(#pb38196150c)\" style=\"fill: none; stroke: #31586b; stroke-width: 1.8; stroke-linecap: square\"/>\n",
       "    <defs>\n",
       "     <path id=\"m326de20165\" d=\"M 0 2  C 0.530406 2 1.03916 1.789267 1.414214 1.414214  C 1.789267 1.03916 2 0.530406 2 0  C 2 -0.530406 1.789267 -1.03916 1.414214 -1.414214  C 1.03916 -1.789267 0.530406 -2 0 -2  C -0.530406 -2 -1.03916 -1.789267 -1.414214 -1.414214  C -1.789267 -1.03916 -2 -0.530406 -2 0  C -2 0.530406 -1.789267 1.03916 -1.414214 1.414214  C -1.03916 1.789267 -0.530406 2 0 2  z \" style=\"stroke: #31586b\"/>\n",
       "    </defs>\n",
       "    <g clip-path=\"url(#pb38196150c)\">\n",
       "     <use xlink:href=\"#m326de20165\" x=\"77.658601\" y=\"188.359116\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"102.096766\" y=\"178.324176\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"126.534932\" y=\"165.138265\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"150.973097\" y=\"151.941156\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"175.411262\" y=\"139.990778\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"199.849428\" y=\"129.643745\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"224.287593\" y=\"120.858495\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"248.725758\" y=\"113.444117\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"273.163924\" y=\"107.176567\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"297.602089\" y=\"101.847722\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"322.040255\" y=\"97.281886\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"346.47842\" y=\"93.337565\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"370.916585\" y=\"89.903436\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"395.354751\" y=\"86.892691\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"419.792916\" y=\"84.237583\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"444.231081\" y=\"81.884845\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"468.669247\" y=\"79.792077\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"493.107412\" y=\"77.925022\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"517.545578\" y=\"76.255548\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"541.983743\" y=\"74.760181\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 54.442344 194.039062  L 54.442344 69.080234  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 54.442344 194.039062  L 565.2 194.039062  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_28\">\n",
       "    <text style=\"font-size: 11px; font-family: 'DejaVu Sans'; text-anchor: start\" x=\"54.442344\" y=\"63.080234\" transform=\"rotate(-0 54.442344 63.080234)\">actual finite-horizon value error</text>\n",
       "   </g>\n",
       "  </g>\n",
       "  <g id=\"axes_2\">\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 54.442344 375.477656  L 565.2 375.477656  L 565.2 250.518828  L 54.442344 250.518828  z \" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_3\">\n",
       "    <g id=\"xtick_21\">\n",
       "     <g id=\"line2d_32\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"77.658601\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_29\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"77.658601\" y=\"390.075312\" transform=\"rotate(-0 77.658601 390.075312)\">1</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_22\">\n",
       "     <g id=\"line2d_33\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"102.096766\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_30\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"102.096766\" y=\"390.075312\" transform=\"rotate(-0 102.096766 390.075312)\">2</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_23\">\n",
       "     <g id=\"line2d_34\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"126.534932\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_31\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"126.534932\" y=\"390.075312\" transform=\"rotate(-0 126.534932 390.075312)\">3</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_24\">\n",
       "     <g id=\"line2d_35\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"150.973097\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_32\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"150.973097\" y=\"390.075312\" transform=\"rotate(-0 150.973097 390.075312)\">4</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_25\">\n",
       "     <g id=\"line2d_36\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"175.411262\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_33\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"175.411262\" y=\"390.075312\" transform=\"rotate(-0 175.411262 390.075312)\">5</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_26\">\n",
       "     <g id=\"line2d_37\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"199.849428\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_34\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"199.849428\" y=\"390.075312\" transform=\"rotate(-0 199.849428 390.075312)\">6</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_27\">\n",
       "     <g id=\"line2d_38\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"224.287593\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_35\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"224.287593\" y=\"390.075312\" transform=\"rotate(-0 224.287593 390.075312)\">7</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_28\">\n",
       "     <g id=\"line2d_39\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"248.725758\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_36\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"248.725758\" y=\"390.075312\" transform=\"rotate(-0 248.725758 390.075312)\">8</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_29\">\n",
       "     <g id=\"line2d_40\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"273.163924\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_37\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"273.163924\" y=\"390.075312\" transform=\"rotate(-0 273.163924 390.075312)\">9</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_30\">\n",
       "     <g id=\"line2d_41\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"297.602089\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_38\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"297.602089\" y=\"390.075312\" transform=\"rotate(-0 297.602089 390.075312)\">10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_31\">\n",
       "     <g id=\"line2d_42\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"322.040255\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_39\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"322.040255\" y=\"390.075312\" transform=\"rotate(-0 322.040255 390.075312)\">11</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_32\">\n",
       "     <g id=\"line2d_43\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"346.47842\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_40\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"346.47842\" y=\"390.075312\" transform=\"rotate(-0 346.47842 390.075312)\">12</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_33\">\n",
       "     <g id=\"line2d_44\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"370.916585\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_41\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"370.916585\" y=\"390.075312\" transform=\"rotate(-0 370.916585 390.075312)\">13</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_34\">\n",
       "     <g id=\"line2d_45\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"395.354751\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_42\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"395.354751\" y=\"390.075312\" transform=\"rotate(-0 395.354751 390.075312)\">14</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_35\">\n",
       "     <g id=\"line2d_46\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"419.792916\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_43\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"419.792916\" y=\"390.075312\" transform=\"rotate(-0 419.792916 390.075312)\">15</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_36\">\n",
       "     <g id=\"line2d_47\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"444.231081\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_44\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"444.231081\" y=\"390.075312\" transform=\"rotate(-0 444.231081 390.075312)\">16</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_37\">\n",
       "     <g id=\"line2d_48\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"468.669247\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_45\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"468.669247\" y=\"390.075312\" transform=\"rotate(-0 468.669247 390.075312)\">17</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_38\">\n",
       "     <g id=\"line2d_49\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"493.107412\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_46\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"493.107412\" y=\"390.075312\" transform=\"rotate(-0 493.107412 390.075312)\">18</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_39\">\n",
       "     <g id=\"line2d_50\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"517.545578\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_47\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"517.545578\" y=\"390.075312\" transform=\"rotate(-0 517.545578 390.075312)\">19</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_40\">\n",
       "     <g id=\"line2d_51\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mba26063cd8\" x=\"541.983743\" y=\"375.477656\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_48\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"541.983743\" y=\"390.075312\" transform=\"rotate(-0 541.983743 390.075312)\">20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_49\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"309.821172\" y=\"404.076094\" transform=\"rotate(-0 309.821172 404.076094)\">reward horizon</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_4\">\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_52\">\n",
       "      <path d=\"M 54.442344 369.79771  L 565.2 369.79771  \" clip-path=\"url(#p951c555265)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_53\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"369.79771\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_50\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"373.596538\" transform=\"rotate(-0 47.442344 373.596538)\">0</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_54\">\n",
       "      <path d=\"M 54.442344 339.903253  L 565.2 339.903253  \" clip-path=\"url(#p951c555265)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_55\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"339.903253\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_51\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"343.702081\" transform=\"rotate(-0 47.442344 343.702081)\">1</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_56\">\n",
       "      <path d=\"M 54.442344 310.008797  L 565.2 310.008797  \" clip-path=\"url(#p951c555265)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_57\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"310.008797\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_52\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"313.807625\" transform=\"rotate(-0 47.442344 313.807625)\">2</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_9\">\n",
       "     <g id=\"line2d_58\">\n",
       "      <path d=\"M 54.442344 280.11434  L 565.2 280.11434  \" clip-path=\"url(#p951c555265)\" style=\"fill: none; stroke: #d4d8da; stroke-width: 0.6; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_59\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m23b044fe28\" x=\"54.442344\" y=\"280.11434\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_53\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: end\" x=\"47.442344\" y=\"283.913168\" transform=\"rotate(-0 47.442344 283.913168)\">3</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_54\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans'; text-anchor: middle\" x=\"34.6775\" y=\"312.998242\" transform=\"rotate(-90 34.6775 312.998242)\">reward units</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_60\">\n",
       "    <path d=\"M 77.658601 369.79771  L 102.096766 369.19982  L 126.534932 368.004042  L 150.973097 366.210375  L 175.411262 363.818818  L 199.849428 360.829373  L 224.287593 357.242038  L 248.725758 353.056814  L 273.163924 348.273701  L 297.602089 342.892699  L 322.040255 336.913807  L 346.47842 330.337027  L 370.916585 323.162357  L 395.354751 315.389799  L 419.792916 307.019351  L 444.231081 298.051014  L 468.669247 288.484788  L 493.107412 278.320673  L 517.545578 267.558668  L 541.983743 256.198775  \" clip-path=\"url(#p951c555265)\" style=\"fill: none; stroke: #31586b; stroke-width: 1.8; stroke-linecap: square\"/>\n",
       "    <g clip-path=\"url(#p951c555265)\">\n",
       "     <use xlink:href=\"#m326de20165\" x=\"77.658601\" y=\"369.79771\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"102.096766\" y=\"369.19982\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"126.534932\" y=\"368.004042\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"150.973097\" y=\"366.210375\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"175.411262\" y=\"363.818818\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"199.849428\" y=\"360.829373\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"224.287593\" y=\"357.242038\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"248.725758\" y=\"353.056814\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"273.163924\" y=\"348.273701\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"297.602089\" y=\"342.892699\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"322.040255\" y=\"336.913807\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"346.47842\" y=\"330.337027\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"370.916585\" y=\"323.162357\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"395.354751\" y=\"315.389799\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"419.792916\" y=\"307.019351\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"444.231081\" y=\"298.051014\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"468.669247\" y=\"288.484788\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"493.107412\" y=\"278.320673\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"517.545578\" y=\"267.558668\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "     <use xlink:href=\"#m326de20165\" x=\"541.983743\" y=\"256.198775\" style=\"fill: #31586b; stroke: #31586b\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 54.442344 375.477656  L 54.442344 250.518828  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path d=\"M 54.442344 375.477656  L 565.2 375.477656  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_55\">\n",
       "    <text style=\"font-size: 11px; font-family: 'DejaVu Sans'; text-anchor: start\" x=\"54.442344\" y=\"244.518828\" transform=\"rotate(-0 54.442344 244.518828)\">finite-horizon bound</text>\n",
       "   </g>\n",
       "  </g>\n",
       "  <g id=\"text_56\">\n",
       "   <text style=\"font-size: 12px; font-family: 'DejaVu Sans'; text-anchor: start\" x=\"46.08\" y=\"17.470125\" transform=\"rotate(-0 46.08 17.470125)\">Chapter 14: transition model bound</text>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pb38196150c\">\n",
       "   <rect x=\"54.442344\" y=\"69.080234\" width=\"510.757656\" height=\"124.958828\"/>\n",
       "  </clipPath>\n",
       "  <clipPath id=\"p951c555265\">\n",
       "   <rect x=\"54.442344\" y=\"250.518828\" width=\"510.757656\" height=\"124.958828\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "changed_inputs = {'true_transition': [[0.9, 0.1], [0.2, 0.8]],\n",
    " 'model_transition': [[0.88, 0.12], [0.22, 0.78]],\n",
    " 'rewards': [0, 1],\n",
    " 'discount': 0.9,\n",
    " 'horizon': 20}\n",
    "changed = analyze(chapter, changed_inputs)\n",
    "changed['evidence_kind'] = 'constructed changed-assumption example'\n",
    "print(report_text(changed))\n",
    "display(SVG(figure_svg(changed)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e65b81fc527",
   "metadata": {},
   "source": [
    "**Figure 14.L2:** The changed-assumption result. Compare the printed quantities and the stated assumptions with the first run. A different input need not imply a causal effect in a deployed agent."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a875d7a8d653",
   "metadata": {},
   "source": [
    "## Try a new case\n",
    "\n",
    "The transfer kernels are identical. Epsilon is zero, finite values agree at every stage, and both bounds are zero. This identity is a useful check of matrix alignment and recurrence behavior. If an implementation returned nonzero error here, investigate the computation before interpreting a more realistic model.\n",
    "\n",
    "For reader data, explain how the true kernel was measured or constructed. Usually a deployed world does not provide exact transition probabilities. In that case the calculated epsilon is conditional on estimates and their support, not a known universal error. Preserve uncertainty or specify the measurements needed to bound it on the relevant policy domain."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9581f4057d65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chapter 14: transition-model-bound\n",
      "How much value error can this approximate world model introduce?\n",
      "Evidence: constructed transfer example\n",
      "\n",
      "Calculated quantities:\n",
      "{\n",
      "  \"uniform_tv_error\": 0.0,\n",
      "  \"true_values\": [\n",
      "    1.875,\n",
      "    3.75\n",
      "  ],\n",
      "  \"model_values\": [\n",
      "    1.875,\n",
      "    3.75\n",
      "  ],\n",
      "  \"max_finite_value_error\": 0.0,\n",
      "  \"discounted_infinite_bound\": 0.0,\n",
      "  \"finite_horizon_bound\": 0.0\n",
      "}\n",
      "\n",
      "Interpretation:\n",
      "Both kernels share the same immediate reward vector under one fixed policy. The uniform total-variation error controls the conditional bound; the actual finite error can be much smaller.\n",
      "\n",
      "Assumptions:\n",
      "- Fixed policy absorbed into each transition matrix.\n",
      "- Common expected immediate reward in [0,R].\n",
      "- Finite calculation has zero terminal continuation; discounted bound assumes gamma below one.\n",
      "\n",
      "Limitations:\n",
      "- A bound is not a measured planning error.\n",
      "- This state-value bound alone does not certify an action ranking.\n",
      "- Reward-model error would require an additional term.\n",
      "\n",
      "Execution: completed locally; constructed inputs are not deployment measurements.\n"
     ]
    }
   ],
   "source": [
    "transfer_inputs = {'true_transition': [[1, 0], [0, 1]],\n",
    " 'model_transition': [[1, 0], [0, 1]],\n",
    " 'rewards': [1, 2],\n",
    " 'discount': 0.5,\n",
    " 'horizon': 4}\n",
    "transfer = analyze(chapter, transfer_inputs)\n",
    "transfer['evidence_kind'] = 'constructed transfer example'\n",
    "print(report_text(transfer))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f73c717a106e",
   "metadata": {},
   "source": [
    "## Apply the method to your inputs\n",
    "\n",
    "The example file below has the exact input shape the method accepts. Copy it to a new file, replace its values, then point `reader_file` at your copy. Run the cell again. Supplied inputs retain their stated provenance; the program cannot establish that they are representative observations.\n",
    "\n",
    "- **true_transition:** Square row-stochastic true kernel after fixing a policy.\n",
    "- **model_transition:** Same-size approximate row-stochastic kernel for that policy.\n",
    "- **rewards:** Common immediate state reward vector, finite and nonnegative.\n",
    "- **discount:** Gamma in [0,0.9999].\n",
    "- **horizon:** Integer reward horizon 1..1000 with zero terminal continuation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5e78438044b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chapter 14: transition-model-bound\n",
      "How much value error can this approximate world model introduce?\n",
      "Evidence: supplied local inputs; provenance not independently verified\n",
      "\n",
      "Calculated quantities:\n",
      "{\n",
      "  \"uniform_tv_error\": 0.0,\n",
      "  \"true_values\": [\n",
      "    1.875,\n",
      "    3.75\n",
      "  ],\n",
      "  \"model_values\": [\n",
      "    1.875,\n",
      "    3.75\n",
      "  ],\n",
      "  \"max_finite_value_error\": 0.0,\n",
      "  \"discounted_infinite_bound\": 0.0,\n",
      "  \"finite_horizon_bound\": 0.0\n",
      "}\n",
      "\n",
      "Interpretation:\n",
      "Both kernels share the same immediate reward vector under one fixed policy. The uniform total-variation error controls the conditional bound; the actual finite error can be much smaller.\n",
      "\n",
      "Assumptions:\n",
      "- Fixed policy absorbed into each transition matrix.\n",
      "- Common expected immediate reward in [0,R].\n",
      "- Finite calculation has zero terminal continuation; discounted bound assumes gamma below one.\n",
      "\n",
      "Limitations:\n",
      "- A bound is not a measured planning error.\n",
      "- This state-value bound alone does not certify an action ranking.\n",
      "- Reward-model error would require an additional term.\n",
      "\n",
      "Execution: completed locally; constructed inputs are not deployment measurements.\n"
     ]
    }
   ],
   "source": [
    "reader_file = LAB_ROOT / 'data/examples/ch14.json'\n",
    "reader_inputs = json.loads(reader_file.read_text())\n",
    "reader_report = analyze(chapter, reader_inputs)\n",
    "print(report_text(reader_report))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51f32353714b",
   "metadata": {},
   "source": [
    "## Questions\n",
    "\n",
    "1. Compute default epsilon.\n",
    "\n",
    "2. Compute horizon 20 finite bound.\n",
    "\n",
    "3. What if the reward model also differs?\n",
    "\n",
    "Answers: [separate solutions](../solutions/ch14.md). Try the calculation before opening them."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9629bab42f4e",
   "metadata": {},
   "source": [
    "## Summary\n",
    "\n",
    "Transition models accumulate errors through future value. Uniform total variation, common immediate rewards, and a fixed policy are essential to the implemented bounds. The notebook separates actual finite error from conditional envelopes and checks the identical-kernel case. Extending horizon changes sensitivity without changing one-step mismatch. A bound is neither a measured planning error nor an action-ranking certificate; report its prerequisites and the evidence supporting the supplied kernels.\n",
    "\n",
    "Limits of this experiment:\n",
    "\n",
    "- This is a local calculation under declared inputs, not an empirical claim about a deployed agent.\n",
    "- Read the returned assumptions and limitations before applying the numerical result.\n",
    "\n",
    "The assistant skill is [`maa-14-transition-model-bound`](../skills/maa-14-transition-model-bound/SKILL.md). It uses this notebook's tested computation and input contract."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9cc9f25ba898",
   "metadata": {},
   "source": [
    "## Equations from the chapter\n",
    "\n",
    "These are the unchanged display equations and their explanations from the canonical chapter. They are a reference for the experiment, not a claim that every equation is numerically implemented by this one method."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf22b8c0dc5d",
   "metadata": {},
   "source": [
    "### Equation 14.1\n",
    "\n",
    "![Equation 14.1](../assets/math/52b47c925ae699342ab3.svg)\n",
    "\n",
    "Equation (14.1) measures how wrong the model is about a single step, at its worst state and action.\n",
    "\n",
    "For each state and action, add up how much the two distributions disagree, halve it, and take the largest such disagreement anywhere.\n",
    "\n",
    "LaTeX source, preserved for inspection:\n",
    "\n",
    "```latex\n",
    "\\epsilon \\;=\\; \\max_{x,a}\\; \\tfrac{1}{2}\\sum_{x'}\\big|\\hat P(x'\\mid x,a) - P(x'\\mid x,a)\\big|.\n",
    "\\tag{14.1}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62317d9cb72c",
   "metadata": {},
   "source": [
    "### Equation 14.2\n",
    "\n",
    "![Equation 14.2](../assets/math/b20fc29975e836ddc4c8.svg)\n",
    "\n",
    "Equation (14.2) bounds how far the value computed inside the model can sit from the value in the world.\n",
    "\n",
    "Multiply the one-step error by the discount factor and largest reward, then divide by the square of one minus the discount factor.\n",
    "\n",
    "LaTeX source, preserved for inspection:\n",
    "\n",
    "```latex\n",
    "\\big|\\hat V^{\\pi}(x) - V^{\\pi}(x)\\big| \\;\\le\\; \\frac{\\gamma\\,\\epsilon\\,R}{(1-\\gamma)^2}.\n",
    "\\tag{14.2}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c8284c7758c",
   "metadata": {},
   "source": [
    "### Equation 14.3\n",
    "\n",
    "![Equation 14.3](../assets/math/02d58a83dac048591dea.svg)\n",
    "\n",
    "Equation (14.3) measures how much better the best action at a state is than the runner-up.\n",
    "\n",
    "Subtract the value of the second best action from the value of the best one.\n",
    "\n",
    "LaTeX source, preserved for inspection:\n",
    "\n",
    "```latex\n",
    "\\Delta(x) \\;=\\; \\max_{a}Q^{\\pi}(x,a) \\;-\\; \\max_{a \\neq a^{*}}Q^{\\pi}(x,a).\n",
    "\\tag{14.3}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6dca0c956dfe",
   "metadata": {},
   "source": [
    "### Equation 14.4\n",
    "\n",
    "![Equation 14.4](../assets/math/b90bd3f384ebe300fc72.svg)\n",
    "\n",
    "Equation (14.4) gives the largest positive integer horizon certified to preserve a unique action ranking under the stated finite-model assumptions.\n",
    "\n",
    "Within the declared planning cap `H_{\\max}`, find the largest positive integer horizon at which twice the finite-horizon action-value error still fits inside the action gap.\n",
    "\n",
    "LaTeX source, preserved for inspection:\n",
    "\n",
    "```latex\n",
    "H^{*} \\;=\\; \\max\\Big\\{ H \\in \\mathbb{Z}_{>0} \\;:\\; H \\leq H_{\\max},\\;\n",
    "R\\,\\epsilon\\,H(H-1) \\;<\\; \\Delta \\Big\\}.\n",
    "\\tag{14.4}\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Mathematics of AI Agents",
   "language": "python",
   "name": "maa-lab"
  },
  "lab_chapter": 14,
  "lab_execution": {
   "code_cells": 6,
   "created_utc": "2026-10-02T05:15:00.798566+00:00",
   "elapsed_seconds": 8.909545915899798,
   "method": "fresh process; new ipykernel InProcessKernelManager; cells submitted as Jupyter execute requests",
   "network_transport_tested": false,
   "python": "3.11.15",
   "source_sha256": "16ca0c2ea1bd24b7abbb889350e2d2d7ef93ba8b26b233be0cd813942b067cfe"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
