Skip to content

Vol. II, Ch. 8

DCT Laboratory — Volume II, Chapter 8

Hamilton–Jacobi–Bellman Enterprise Framework

Seed 26208 · Companion to Chapter 8 and AXIOM Lab 2.8 (module AXIOM-08) · Mirrored in DCT_V2_Ch08_Lab.xlsx

This laboratory reproduces Worked Example 8.1, How Fast Should Meridian Close Its Engineering Gap?, with the book's declarations, and works the five steps of AXIOM Lab 2.8: assemble the equation, read the Hamiltonian, generate and simulate rules, compare prices, and solve on a grid. Its second model is Chapter 6's capability problem, solved here with the Hamilton–Jacobi–Bellman equation. Every Meridian number below is the book's (Table 8.3, Figures 8.1–8.3, Online Appendix 8.B.1–8.B.2); the final cell checks them. Nothing in the chapter is random, so no draws are made. Money is in $ million.

The declarations (Worked Example 8.1, Step 1)

Volume I's quarterly hiring loop (Volume I, Worked Example 7.1), read continuously, in years. The gap dd is the bench of software engineers minus its target: 100 short today, with nothing in the pipeline. Retraining and internal moves close it on their own at a=4ln⁡(10/9)=0.42a = 4\ln(10/9) = 0.42 a year, so that 90 percent of a gap carries over a quarter; approvals vv, in engineers a year, add a share b=0.6b = 0.6 of themselves to the bench a quarter later: d˙(t)=−a d(t)+b v(t−14)\dot d(t) = -a\,d(t) + b\,v(t - \tfrac14). The program office declares that a gap costs the digital build qd2qd^2 a year, q=0.0032q = 0.0032: 100 short costs $32 million a year, as much as stopping the build. Human resources declares that approving at a pace costs a premium of rv2rv^2 a year beyond planned salaries, r=0.000125r = 0.000125: $20 million a year at 400 a year, about $50,000 a hire. Approvals may turn negative (releases, through redeployment and severance), priced and timed like approvals. The board discounts at 10 percent a year, ρ=ln⁡1.1\rho = \ln 1.1, over an open horizon. A rule's cost is the present value of the gap's cost and the premium; the value of a position is minus the least cost.

Python Code
import numpy as np
import scipy.sparse as sp
import scipy.sparse.linalg as spla
from scipy.optimize import brentq, minimize_scalar
import matplotlib.pyplot as plt
plt.rcParams.update({"figure.dpi": 110, "axes.spines.top": False, "axes.spines.right": False})
SEED = 26208                 # the lab's seed; every number in this chapter is deterministic, so nothing is drawn

A = 4 * np.log(10 / 9)       # the gap closes on its own: 90 percent of it carries over a quarter
B = 0.6                      # share of approved hires that become productive engineers
TAU = 0.25                   # approvals become engineers a quarter later (years)
Q = 32 / 100**2              # program office: a gap of d engineers costs Q d^2 a year
R = 20 / 400**2              # human resources: approving v a year costs a premium of R v^2 a year
RHO = np.log(1.1)            # the board's hurdle rate, 10 percent a year, as a continuous rate
D0 = -100.0                  # bench minus target today; nothing in the pipeline
CAUTIOUS, DEADBEAT = 4 * 0.5, 4 * 1.5   # Volume I's gains, half and one and a half times the gap a quarter, a year

def riccati(q=Q, r=R, a=A, b=B, rho=RHO):
    # Theorem 8.3(i) with one stock: the roots of (b^2/r) p^2 + (2a + rho) p - q = 0, the positive one first
    s, t = b * b / r, 2 * a + rho
    root = np.sqrt(t * t + 4 * s * q)
    return (-t + root) / (2 * s), (-t - root) / (2 * s)

def cost_at_once(k, q=Q, r=R, a=A, b=B, rho=RHO, d0=D0):
    # present value of q d^2 + r v^2 from d0 under the rule v = -k d, if approvals landed at once
    return (q + r * k * k) * d0 * d0 / (2 * (a + b * k) + rho)

print(f"a = {A:.6f} a year (e^(-a/4) = {np.exp(-A / 4):.4f}); b = {B}; tau = {TAU} years; rho = {RHO:.6f}; q/r = {Q / R:.1f}")
print(f"a gap costs {Q * 100**2:.0f} a year at 100 short and {Q * 50**2:.0f} at 50 short; the premium is {R * 400**2:.0f} a year "
      f"at 400 approvals a year (${1e6 * R * 400:,.0f} a hire) and {R * 100**2:.2f} at 100 a year (${1e6 * R * 100:,.0f} a hire)")
a = 0.421442 a year (e^(-a/4) = 0.9000); b = 0.6; tau = 0.25 years; rho = 0.095310; q/r = 25.6
a gap costs 32 a year at 100 short and 8 at 50 short; the premium is 20 a year at 400 approvals a year ($50,000 a hire) and 1.25 at 100 a year ($12,500 a hire)

Panel 1 — Assemble the equation: a quadratic value and its two roots (Theorems 8.2 and 8.3; Worked Example 8.1, Step 2)

AXIOM Lab 2.8, step 1. Read as if approvals landed at once, the hiring problem is Theorem 8.3's with one stock. Try the value W(d)=−pd2W(d) = -pd^2. The rule that maximizes the Hamiltonian at its slope approves v=−(bp/r) dv = -(bp/r)\,d, and the HJB equation then misses, at every gap, by d2d^2 times the Riccati quadratic (b2/r)p2+(2a+ρ)p−q(b^2/r)p^2 + (2a + \rho)p - q. The quadratic has two roots. Theorem 8.2(iii) turns any other pp into an audit: on the gaps from 100 short to 100 over, where the best plan and these rules stay, a residual of at most ε\varepsilon a year puts WW within ε/ρ\varepsilon/\rho of the value and the greedy rule within 2ε/ρ2\varepsilon/\rho of the best. The positive root certifies the rule. The second root also solves the equation exactly, but its rule releases engineers while the bench is short; its discounted value does not tend to zero, so Theorem 8.2(ii) certifies nothing.

Python Code
p, p_minus = riccati()
K = B * p / R                                 # the rule v = -K d, approvals a year per engineer of gap
lam = A + B * K                               # the rate at which the gap closes under it
print(f"(b^2/r) p^2 + (2a + rho) p - q = {B * B / R:.0f} p^2 + {2 * A + RHO:.6f} p - {Q}: roots p = {p:.8f} and p- = {p_minus:.8f}")
print(f"best rule v = -{K:.4f} d a year ({K / 4:.4f} a quarter); the gap closes at a + bK = {lam:.4f} a year, "
      f"halving every {np.log(2) / lam:.4f} years ({12 * np.log(2) / lam:.2f} months)")
print(f"least cost from 100 short: p x 100^2 = {p * D0**2:.3f}; price of an engineer of gap there: 2p x 100 = {2 * p * 100:.4f}")
print(f"first approval rate {K * 100:.1f} a year; premium on the last approval 2rv = {2 * R * K * 100:.4f} = b x price = {B * 2 * p * 100:.4f}")

def riccati_gap(pc, q=Q, r=R, a=A, b=B, rho=RHO):   # the Riccati quadratic at a candidate p
    return (b * b / r) * pc * pc + (2 * a + rho) * pc - q
def residual(pc, d):                          # rho W - max over v of H(d, v, W'(d)) for W = -pc d^2
    return -d * d * riccati_gap(pc)

print("\n  candidate p   residual at   bound    value     greedy gain   its cost   loss    bound")
print("               100 short    eps/rho   off by    a year                            2 eps/rho")
for pc in (0.0005, 0.0008, 0.0009, p, 0.001, 0.0012):
    eps = abs(residual(pc, 100.0))            # the largest residual on the gaps from 100 short to 100 over
    k = B * pc / R
    print(f"  {pc:.8f} {eps:11.4f} {eps / RHO:10.4f} {abs(pc - p) * 1e4:9.4f} {k:11.4f} {cost_at_once(k):11.4f} "
          f"{cost_at_once(k) - p * 1e4:8.4f} {2 * eps / RHO:9.4f}")

K_minus = B * p_minus / R
grow = -A - B * K_minus
print(f"\nsecond root: W = {-p_minus:.8f} d^2 >= 0 solves the equation exactly; its rule v = {-K_minus:.4f} d releases "
      f"{-K_minus * 100:.0f} a year at 100 short")
print(f"its closed loop grows at -a + {-K_minus:.4f} b = {grow:.3f} a year, so e^(-rho t) W(d(t)) grows at {2 * grow - RHO:.3f} "
      f"a year: the limit condition fails and the rule's cost is infinite")
print(f"Theorem 8.2(iii) at the hurdle rate: the effective horizon 1/rho is {1 / RHO:.1f} years, so values whose residual is "
      f"at most $0.1 million a year are within {0.1 / RHO:.2f}")

ps = np.linspace(-0.0016, 0.0014, 601)
fig, ax = plt.subplots(figsize=(7.6, 3.6))
ax.axhline(0, color="#999999", lw=0.8)
ax.plot(ps * 1e3, residual(ps, 100.0), color="#1F4E79", lw=2)
ax.plot([p * 1e3], [0], "o", color="#1F4E79", ms=6)
ax.plot([p_minus * 1e3], [0], "o", color="#B71C1C", ms=6)
ax.annotate(f"p = {p:.6f}: approve {K:.2f} times\nthe gap a year; certified", xy=(p * 1e3, 0), xytext=(0.2, -27),
            fontsize=8, color="#1F4E79", arrowprops=dict(arrowstyle="-", color="#1F4E79", lw=0.7))
ax.annotate(f"p- = {p_minus:.6f}: releases {-K_minus * 100:.0f} a year\nat 100 short; fails the limit condition",
            xy=(p_minus * 1e3, 0), xytext=(-1.62, 27), fontsize=8, color="#B71C1C",
            arrowprops=dict(arrowstyle="-", color="#B71C1C", lw=0.7))
ax.set(xlabel="candidate p in the value -p d² (thousandths)", ylabel="HJB residual at 100 short ($ million a year)",
       title="The residual of a quadratic value vanishes at two roots (seed 26208)")
plt.tight_layout(); plt.show()
(b^2/r) p^2 + (2a + rho) p - q = 2880 p^2 + 0.938194 p - 0.0032: roots p = 0.00090372 and p- = -0.00122948
best rule v = -4.3379 d a year (1.0845 a quarter); the gap closes at a + bK = 3.0242 a year, halving every 0.2292 years (2.75 months)
least cost from 100 short: p x 100^2 = 9.037; price of an engineer of gap there: 2p x 100 = 0.1807
first approval rate 433.8 a year; premium on the last approval 2rv = 0.1084 = b x price = 0.1084

  candidate p   residual at   bound    value     greedy gain   its cost   loss    bound
               100 short    eps/rho   off by    a year                            2 eps/rho
  0.00050000     20.1090   210.9851    4.0372      2.4000     10.2666   1.2294  421.9702
  0.00080000      6.0624    63.6075    1.0372      3.8400      9.0931   0.0559  127.2151
  0.00090000      0.2283     2.3948    0.0372      4.3200      9.0373   0.0001    4.7897
  0.00090372      0.0000     0.0000    0.0000      4.3379      9.0372   0.0000    0.0000
  0.00100000      6.1819    64.8613    0.9628      4.8000      9.0771   0.0399  129.7226
  0.00120000     20.7303   217.5039    2.9628      5.7600      9.3593   0.3220  435.0077

second root: W = 0.00122948 d^2 >= 0 solves the equation exactly; its rule v = 5.9015 d releases 590 a year at 100 short
its closed loop grows at -a + 5.9015 b = 3.119 a year, so e^(-rho t) W(d(t)) grows at 6.144 a year: the limit condition fails and the rule's cost is infinite
Theorem 8.2(iii) at the hurdle rate: the effective horizon 1/rho is 10.5 years, so values whose residual is at most $0.1 million a year are within 1.05
The residual of a quadratic value vanishes at two roots (seed 26208)

Panel 2 — Read the Hamiltonian: the premium equals the value of an approval (Proposition 8.1(ii)–(iii); Worked Example 8.1, Step 2)

AXIOM Lab 2.8, step 2. At the gap dd the Hamiltonian of an approval rate vv is what the moment costs, −qd2−rv2-qd^2 - rv^2, plus the movement it causes priced at the value's slope, V′(d) (−ad+bv)V'(d)\,(-ad + bv). It is strictly concave in vv, so the best rate is where the marginal premium 2rv2rv equals the value of an approval, b V′(d)b\,V'(d): 60 percent of the price of an engineer of gap. At 100 short an engineer of gap is priced at $181,000, and the premium on the last approval, $108,000, equals what it brings. The price falls as the bench fills, because the value is concave, and the approvals fall with it.

Python Code
print("  gap    price of an engineer   best approval rate   marginal premium   value of an approval")
print("          of gap, V'(d)          b V'(d) / (2r)          2 r v               b V'(d)")
for d in (-100.0, -50.0, -25.0):
    m = -2 * p * d                            # the slope of the value -p d^2: what one more engineer on the bench is worth
    v = B * m / (2 * R)
    print(f"{d:6.0f} {m:16.4f} {v:21.1f} {2 * R * v:20.4f} {B * m:20.4f}")

vs = np.linspace(0, 500, 501)
fig, ax = plt.subplots(figsize=(7.6, 3.6))
for d, col in ((-100.0, "#1F4E79"), (-50.0, "#E65100"), (-25.0, "#616161")):
    m = -2 * p * d
    part = -R * vs**2 + m * B * vs            # the part of the Hamiltonian the approval rate moves
    vbest = B * m / (2 * R)
    ax.plot(vs, part, color=col, lw=2, label=f"{-d:.0f} short: an engineer of gap is worth ${1000 * m:.0f},000; approve {vbest:.0f} a year")
    ax.plot([vbest], [part.max()], "o", color=col, ms=5)
ax.axhline(0, color="#999999", lw=0.6)
ax.set(xlabel="approval rate v (engineers a year)", ylabel="-r v² + b V'(d) v ($ million a year)", ylim=(-4, 36),
       title="Approve until the premium meets the value of an approval (seed 26208)")
ax.legend(frameon=False, fontsize=8, loc="upper center", ncol=1); plt.tight_layout(); plt.show()
  gap    price of an engineer   best approval rate   marginal premium   value of an approval
          of gap, V'(d)          b V'(d) / (2r)          2 r v               b V'(d)
  -100           0.1807                 433.8               0.1084               0.1084
   -50           0.0904                 216.9               0.0542               0.0542
   -25           0.0452                 108.4               0.0271               0.0271
Approve until the premium meets the value of an approval (seed 26208)

Panel 3 — Find the gain by policy iteration (Theorem 8.3(iii); Section 8.6)

The hiring problem, read without the delay, needs no grid. Start from Volume I's cautious gain, 2 a year (half the gap a quarter). Evaluate the rule: its cost from the gap dd is pkd2p_k d^2 with pk=(q+rk2)/(2(a+bk)+ρ)p_k = (q + rk^2)/(2(a + bk) + \rho). Make the rule greedy for that cost, k←bpk/rk \leftarrow bp_k/r, and repeat. Each step is Newton's method on the Riccati equation (Kleinman): the cautious gain costs $11.08 million from 100 short, and the improved gains of 5.32, 4.42 and 4.338 a year cost $9.20, $9.04 and $9.037 million, the third within a dollar of the best. Every rule on the way keeps the discounted gap dying out, as Theorem 8.3(iii) says.

Python Code
k, kleinman = CAUTIOUS, []
for step in range(6):
    pk = (Q + R * k * k) / (2 * (A + B * k) + RHO)     # evaluate the rule v = -k d: its cost is pk d^2
    kleinman.append((k, pk))
    k = B * pk / R                                     # the rule that is greedy for that cost
print("step   gain a year   cost from 100 short   above the best   discounted gap dies out at")
for i, (k_, pk) in enumerate(kleinman):
    print(f"{i:4d} {k_:12.4f} {pk * 1e4:17.4f} {pk * 1e4 - p * 1e4:16.2e} {A + B * k_ + RHO / 2:16.3f} a year")
print(f"the third improved rule is within ${1e6 * (kleinman[3][1] - p) * 1e4:.2f} of the best (gain {kleinman[3][0]:.6f} against {K:.6f})")
step   gain a year   cost from 100 short   above the best   discounted gap dies out at
   0       2.0000           11.0838         2.05e+00            1.669 a year
   1       5.3202            9.2020         1.65e-01            3.661 a year
   2       4.4169            9.0385         1.25e-03            3.119 a year
   3       4.3385            9.0372         7.36e-08            3.072 a year
   4       4.3379            9.0372         0.00e+00            3.072 a year
   5       4.3379            9.0372         0.00e+00            3.072 a year
the third improved rule is within $0.07 of the best (gain 4.338466 against 4.337864)

Panel 4 — Allow for the delay: steer by the predicted gap (Proposition 8.3(ii); Worked Example 8.1, Step 3)

AXIOM Lab 2.8, step 3, first part: generate the rule from the value. Approvals take a quarter to land, so nothing HR does in the first quarter reaches the bench: the gap closes only by internal moves, to 90 short, and that quarter's cost, $7.13 million, is fixed whatever the rule. The state must carry the approvals in flight. The predicted gap z(t)=d(t+14)z(t) = d(t + \tfrac14) — today's gap carried over a quarter plus the approvals in the pipeline, each counted at 60 percent and net of the internal moves after it lands — moves as the gap would if approvals landed at once, z˙=−az+bv\dot z = -az + bv, and its cost is the gap's, discounted by a quarter more: q′=qe−ρ/4q' = qe^{-\rho/4}. So the best rule is Panel 1's with q′q': approve at 4.28 times the predicted gap a year, 1.07 times a quarter.

Python Code
def with_delay(tau=TAU, q=Q, r=R, a=A, b=B, rho=RHO, d0=D0):
    # Proposition 8.3(ii): the first quarter's cost is fixed; the rest is Theorem 8.3's problem in the predicted gap
    # z, with the cost of a gap discounted by the delay
    qz = q * np.exp(-rho * tau)
    pz, _ = riccati(qz, r, a, b, rho)
    z0 = np.exp(-a * tau) * d0                # nothing in flight: the gap a quarter ahead is today's, carried over
    first = q * d0 * d0 * (1 - np.exp(-(2 * a + rho) * tau)) / (2 * a + rho)
    return dict(q=qz, p=pz, K=b * pz / r, z0=z0, first=first, rest=pz * z0 * z0, total=first + pz * z0 * z0)

pre = with_delay()
Kz = pre["K"]
lam_z = A + B * Kz                            # the predicted gap closes at this rate
v_start = Kz * abs(pre["z0"])
approved_q1 = v_start * (1 - np.exp(-lam_z * TAU)) / lam_z
gap_1y = pre["z0"] * np.exp(-lam_z * (1 - TAU))
price_delay = (2 * Q * abs(D0) * (1 - np.exp(-(2 * A + RHO) * TAU)) / (2 * A + RHO)
               + 2 * pre["p"] * abs(pre["z0"]) * np.exp(-A * TAU))
print(f"q' = q e^(-rho/4) = {pre['q']:.8f}; p' = {pre['p']:.8f}; rule v = -{Kz:.4f} z a year ({Kz / 4:.4f} a quarter); z(0) = {pre['z0']:.3f}")
print(f"least cost from 100 short: {pre['first']:.3f} for the first quarter (fixed) + p' z(0)^2 = {pre['rest']:.3f} -> {pre['total']:.3f}")
print(f"the quarter's delay costs {pre['total'] - p * 1e4:.3f} (against {p * 1e4:.3f} if approvals landed at once)")
print(f"approvals start at {v_start:.1f} a year and ease as the pipeline fills: {approved_q1:.1f} in the first quarter; "
      f"the predicted gap closes at {lam_z:.3f} a year, so the gap after a year is {gap_1y:.2f}, with no overshoot")
print(f"at the start the marginal premium 2r x {v_start:.1f} = {2 * R * v_start:.4f} equals the value of an approval "
      f"b x 2p'|z(0)| = {B * 2 * pre['p'] * abs(pre['z0']):.4f}")
print(f"price of an engineer already on the bench at 100 short: {price_delay:.4f} with the delay, against {2 * p * 100:.4f} without")
q' = q e^(-rho/4) = 0.00312465; p' = 0.00089139; rule v = -4.2787 z a year (1.0697 a quarter); z(0) = -90.000
least cost from 100 short: 7.131 for the first quarter (fixed) + p' z(0)^2 = 7.220 -> 14.351
the quarter's delay costs 5.314 (against 9.037 if approvals landed at once)
approvals start at 385.1 a year and ease as the pipeline fills: 67.8 in the first quarter; the predicted gap closes at 2.989 a year, so the gap after a year is -9.57, with no overshoot
at the start the marginal premium 2r x 385.1 = 0.0963 equals the value of an approval b x 2p'|z(0)| = 0.0963
price of an engineer already on the bench at 100 short: 0.2870 with the delay, against 0.1807 without

Panel 5 — Generate and simulate rules (Table 8.3; Figure 8.2; Worked Example 8.1, Step 4)

AXIOM Lab 2.8, step 3. Every rule is run on the delay equation itself: steps of 10−410^{-4} and 5×10−55 \times 10^{-5} years over 12 years, the gap updated exactly over each step with the landing approvals held fixed, and the cost extrapolated to remove the step's first-order error (Online Appendix 8.B.1). Simulated this way, the predicted-gap rule costs exactly its closed form. Rules on today's gap are proportional and run continuously; the best gain on today's gap comes from a one-dimensional search over the gain.

Python Code
def simulate(k, on="today", tau_true=TAU, tau_rule=TAU, b_true=B, b_rule=B, dt=1e-4, T=12.0, record=False):
    # d'(t) = -a d(t) + b_true v(t - tau_true) under v = -k d (today's gap) or v = -k z (the predicted gap, which HR
    # computes with the delay tau_rule and the productivity b_rule it believes). Over each step the gap is updated
    # exactly with the landing approvals held fixed; the cost is summed step by step.
    n, lag, lag_r = int(round(T / dt)), int(round(tau_true / dt)), int(round(tau_rule / dt))
    dec, ez, ddisc = np.exp(-A * dt), np.exp(-A * tau_rule), np.exp(-RHO * dt)
    lands = (1 - dec) / A * b_true
    v = [0.0] * (n + 1)
    path = [0.0] * (n + 1) if record else None
    d, flight, cost, disc, peak, first_q = D0, 0.0, 0.0, 1.0, D0, 0.0
    for i in range(n):
        vi = -k * d if on == "today" else -k * (ez * d + flight)
        v[i] = vi
        if record:
            path[i] = d
        cost += disc * (Q * d * d + R * vi * vi) * dt
        if i * dt < 0.25:
            first_q += vi * dt
        d = d * dec + lands * (v[i - lag] if i >= lag else 0.0)
        flight = flight * dec + b_rule * dt * vi - b_rule * dt * (v[i - lag_r] if i >= lag_r else 0.0) * ez
        disc *= ddisc
        peak = max(peak, d)
    out = dict(cost=cost, peak=peak, first_q=first_q, dt=dt, vmax=max(v))
    if record:
        path[n] = d
        out["path"], out["v"] = np.array(path), np.array(v)
    return out

def simulate_rx(k, on="today", dt=1e-4, **kw):
    # the cost at dt and dt/2, extrapolated: 2 c(dt/2) - c(dt); paths and statistics from the finer run
    coarse = simulate(k, on, dt=dt, **kw)
    fine = simulate(k, on, dt=dt / 2, record=True, **kw)
    fine["cost"] = 2 * fine["cost"] - coarse["cost"]
    return fine

search = minimize_scalar(lambda k: simulate(k, dt=5e-4)["cost"], bounds=(0.5, 8.0), method="bounded", options={"xatol": 1e-4})
k_best = float(search.x)
RULES = [("Best rule: steer by the predicted gap", "predicted", Kz, p * 1e4),
         ("Step 2's gain on today's gap", "today", K, cost_at_once(K)),
         ("Best gain on today's gap", "today", k_best, cost_at_once(k_best)),
         ("Volume I's cautious gain", "today", CAUTIOUS, cost_at_once(CAUTIOUS)),
         ("Volume I's deadbeat gain", "today", DEADBEAT, cost_at_once(DEADBEAT))]
table83 = []
for name, on, k_, at_once in RULES:
    res = simulate_rx(k_, on)
    table83.append(dict(name=name, on=on, k=k_, cost=res["cost"], peak=res["peak"], first_q=res["first_q"],
                        d1=float(res["path"][int(round(1.0 / res["dt"]))]), at_once=at_once, res=res))
best_cost = table83[0]["cost"]
print(f"{'Table 8.3':38s} gain a   approved     largest   gap after   cost    extra   at once")
print(f"{'':38s} quarter  first quarter surplus   a year")
for r_ in table83:
    extra = "      -" if r_ is table83[0] else f"{r_['cost'] - best_cost:7.3f}"
    print(f"{r_['name']:38s} {r_['k'] / 4:6.3f}{'*' if r_['on'] == 'predicted' else ' '} {r_['first_q']:10.1f} "
          f"{max(r_['peak'], 0):11.2f} {r_['d1']:9.2f} {r_['cost']:9.3f} {extra} {r_['at_once']:8.3f}")
print("* on the predicted gap: the gap a quarter ahead, counting the approvals in flight")
print(f"best gain on today's gap {k_best:.4f} a year ({k_best / 4:.4f} a quarter); the predicted-gap rule simulated "
      f"{best_cost:.4f}, closed form {pre['total']:.4f}")
print(f"approvals land at once: the cautious gain is the worst of these, {cost_at_once(CAUTIOUS) - p * 1e4:.3f} above the best")

curve = {k_: (cost_at_once(k_), simulate_rx(k_, dt=5e-4)["cost"]) for k_ in (1, 2, 3, 4, 5, 6, 7, 8)}
print("\nFigure 8.3(a): cost from 100 short of v = -k d (the delayed runs at steps of 5e-4 and 2.5e-4 years)")
print("gain a year      " + "".join(f"{k_:8.2f}" for k_ in curve))
print("approvals at once" + "".join(f"{c_[0]:8.3f}" for c_ in curve.values()))
print("a quarter late   " + "".join(f"{c_[1]:8.3f}" for c_ in curve.values()))

fig, ax = plt.subplots(figsize=(7.6, 3.6))
for r_, col, ls, lab in ((table83[0], "#1F4E79", "-", "best rule, on the predicted gap"),
                         (table83[3], "#616161", "--", "Volume I's cautious gain"),
                         (table83[1], "#E65100", "-.", "Step 2's gain on today's gap"),
                         (table83[4], "#B71C1C", ":", "Volume I's deadbeat gain")):
    res = r_["res"]
    m = int(round(3.0 / res["dt"])) + 1
    t = np.arange(m) * res["dt"]
    ax.plot(4 * t[::40], res["path"][:m:40], color=col, ls=ls, lw=2 if ls == "-" else 1.5, label=lab)
ax.axhline(0, color="#999999", lw=0.6)
for r_, col, x in ((table83[1], "#E65100", 3.9), (table83[4], "#B71C1C", 3.2)):
    ax.text(x, r_["peak"] + 1.5, f"+{r_['peak']:.0f}", color=col, fontsize=8)
ax.set(xlim=(0, 12), ylim=(-105, 45), xlabel="quarters from today", ylabel="gap: bench minus target (engineers)",
       title="Counting the pipeline closes the gap without overshoot (seed 26208)")
ax.legend(frameon=False, fontsize=8, loc="lower right"); plt.tight_layout(); plt.show()
Table 8.3                              gain a   approved     largest   gap after   cost    extra   at once
                                       quarter  first quarter surplus   a year
Best rule: steer by the predicted gap   1.070*       67.8        0.00     -9.57    14.351       -    9.037
Step 2's gain on today's gap            1.084       102.9       15.87     12.24    17.471   3.120    9.037
Best gain on today's gap                0.621        58.9        0.12     -5.86    14.581   0.230   10.136
Volume I's cautious gain                0.500        47.5        0.00    -14.17    14.844   0.493   11.084
Volume I's deadbeat gain                1.500       142.4       36.56     10.94    25.070  10.718    9.462
* on the predicted gap: the gap a quarter ahead, counting the approvals in flight
best gain on today's gap 2.4823 a year (0.6206 a quarter); the predicted-gap rule simulated 14.3513, closed form 14.3513
approvals land at once: the cautious gain is the worst of these, 2.047 above the best

Figure 8.3(a): cost from 100 short of v = -k d (the delayed runs at steps of 5e-4 and 2.5e-4 years)
gain a year          1.00    2.00    3.00    4.00    5.00    6.00    7.00    8.00
approvals at once  15.551  11.084   9.530   9.062   9.116   9.462   9.986  10.628
a quarter late     18.013  14.844  14.832  16.547  19.826  25.070  33.382  47.466
Counting the pipeline closes the gap without overshoot (seed 26208)

Panel 6 — Why a rule on today's gap must be gentle (Proposition 8.3(i); Online Appendix 8.B.1)

AXIOM Lab 2.8, step 3, and its first discussion question. Without the delay, Theorem 8.3's rule can be strengthened by any factor without losing stability (Proposition 8.3(i)). A delay breaks that. A rule on today's gap, d˙=−a d(t)−bk d(t−τ)\dot d = -a\,d(t) - bk\,d(t - \tau), swings with growing amplitude once its characteristic equation has a root s=iωs = i\omega: bkcos⁡(ωτ)=−abk\cos(\omega\tau) = -a and bksin⁡(ωτ)=ωbk\sin(\omega\tau) = \omega. The smallest such gain is 10.92 a year, 2.73 a quarter, with swings of period 0.96 years. Simulations settle below it — with a gain of 10 a year the largest gap is 61.4 in years 2–4 and 8.4 in years 10–12 — and swing with growing amplitude above it: with 12 a year, 280 and then about 2,410. A window's largest gap converges at first order in the simulation step, so each is computed at steps of 5×10−55 \times 10^{-5} and 2.5×10−52.5 \times 10^{-5} years and extrapolated, 2m(Δt/2)−m(Δt)2m(\Delta t/2) - m(\Delta t) (Online Appendix 8.B.1). Volume I's quarterly review allowed gains below 1.67 a quarter, because there a quarter's approvals arrive at once rather than a little at a time. The rule on the predicted gap need not be gentle: the predicted gap moves without the delay, so the loop it closes has none.

Python Code
w_c = brentq(lambda w: w + A * np.tan(w * TAU), np.pi / (2 * TAU) + 1e-9, np.pi / TAU - 1e-9)
k_c = np.sqrt(A * A + w_c * w_c) / B
print(f"omega = {w_c:.2f}, between pi/(2 tau) = {np.pi / (2 * TAU):.2f} and pi/tau = {np.pi / TAU:.2f}; critical gain "
      f"(a^2 + omega^2)^(1/2) / b = {k_c:.2f} a year ({k_c / 4:.2f} a quarter); period 2 pi/omega = {2 * np.pi / w_c:.2f} years")
print(f"Volume I's quarterly review: stable while 0.6 x gain < 1, below {1 / 0.6:.2f} a quarter")
# A window's largest |gap| converges at first order in the step: compute it at steps of 5e-5 and 2.5e-5 years
# and extrapolate, 2 m(dt/2) - m(dt) (Online Appendix 8.B.1)
swings = {}
for k_ in (10.0, 12.0):
    runs = [simulate(k_, dt=step, T=12.0, record=True) for step in (5e-5, 2.5e-5)]
    swings[k_] = []
    print(f"gain {k_:.0f} a year ({k_ / 4:.1f} a quarter):")
    for t0, t1 in ((2.0, 4.0), (10.0, 12.0)):
        m_ = [float(np.abs(r_["path"][int(round(t0 / r_["dt"])):int(round(t1 / r_["dt"])) + 1]).max()) for r_ in runs]
        swings[k_].append(2 * m_[1] - m_[0])
        print(f"   largest gap in years {t0:.0f}-{t1:.0f}: {m_[0]:9.3f} at a step of 5e-5, {m_[1]:9.3f} at 2.5e-5 -> "
              f"extrapolated {swings[k_][-1]:9.3f}")
    print(f"   the swings {'die out' if swings[k_][1] < swings[k_][0] else 'grow'}")
omega = 6.54, between pi/(2 tau) = 6.28 and pi/tau = 12.57; critical gain (a^2 + omega^2)^(1/2) / b = 10.92 a year (2.73 a quarter); period 2 pi/omega = 0.96 years
Volume I's quarterly review: stable while 0.6 x gain < 1, below 1.67 a quarter
gain 10 a year (2.5 a quarter):
   largest gap in years 2-4:    61.434 at a step of 5e-5,    61.417 at 2.5e-5 -> extrapolated    61.400
   largest gap in years 10-12:     8.397 at a step of 5e-5,     8.384 at 2.5e-5 -> extrapolated     8.370
   the swings die out
gain 12 a year (3.0 a quarter):
   largest gap in years 2-4:   280.619 at a step of 5e-5,   280.476 at 2.5e-5 -> extrapolated   280.333
   largest gap in years 10-12:  2420.271 at a step of 5e-5,  2416.447 at 2.5e-5 -> extrapolated  2412.624
   the swings grow

Panel 7 — Test the declarations (Worked Example 8.1, Step 5; Figure 8.3(b))

The gain depends on the declared costs only through their ratio q/rq/r: doubling the cost of a gap calls for the same rule as halving the premium for speed, at a different cost. The delay matters more, above all when it is misdeclared: approvals that take half a year while HR steers for a quarter. Faster onboarding is worth real money. If only 30 percent of approvals became engineers, the rule built for 60 percent would come within $0.08 million of the best.

Python Code
print("declaration          gain at once   least cost at once   gain K' with the delay   least cost with the delay")
sens = {}
for name, kw in (("gap cost doubled", dict(q=2 * Q)), ("gap cost halved", dict(q=Q / 2)),
                 ("premium doubled", dict(r=2 * R)), ("premium halved", dict(r=R / 2))):
    p_, _ = riccati(**kw)
    k_ = B * p_ / kw.get("r", R)
    pre_ = with_delay(**kw)
    sens[name] = (k_, p_ * 1e4, pre_["K"], pre_["total"])
    print(f"{name:20s} {k_:10.3f} {p_ * 1e4:16.3f} {pre_['K']:20.3f} {pre_['total']:24.3f}")

print("\napprovals take half a year; HR steers as if they took a quarter (14 years simulated)")
half = {}
for name, on, k_ in (("best rule, built for a quarter", "predicted", Kz), ("Step 2's gain on today's gap", "today", K),
                     ("Volume I's cautious gain", "today", CAUTIOUS)):
    res = simulate_rx(k_, on, tau_true=0.5, tau_rule=TAU, T=14.0)
    half[name] = (res["cost"], res["peak"])
    print(f"  {name:32s} cost {res['cost']:7.3f}, largest surplus {max(res['peak'], 0):6.2f}")
re_half = with_delay(tau=0.5)
sim_half = simulate_rx(re_half["K"], "predicted", tau_true=0.5, tau_rule=0.5, T=14.0)
print(f"  {'rule built for half a year':32s} cost {re_half['total']:7.3f} (K' = {re_half['K']:.3f}; simulated "
      f"{sim_half['cost']:.3f}, largest surplus {max(sim_half['peak'], 0):.2f})")

onboard = {"at once": p * 1e4, "a month": with_delay(tau=1 / 12)["total"], "a quarter": pre["total"], "half a year": re_half["total"]}
print("\nleast cost by the time approvals take to land: " + ", ".join(f"{k_} {v_:.3f}" for k_, v_ in onboard.items()))
print(f"cutting the delay from a quarter to a month is worth {onboard['a quarter'] - onboard['a month']:.3f} from 100 short")

low = simulate_rx(Kz, "predicted", b_true=0.3, T=14.0)
low_re = with_delay(b=0.3)
print(f"\nonly 30 percent of approvals become engineers: the rule built for 60 percent costs {low['cost']:.3f} "
      f"(largest surplus {max(low['peak'], 0):.2f}); redesigned, K' = {low_re['K']:.3f}, {low_re['total']:.3f}: "
      f"within {low['cost'] - low_re['total']:.3f}")
declaration          gain at once   least cost at once   gain K' with the delay   least cost with the delay
gap cost doubled          6.416           13.367                6.332                   24.947
gap cost halved           2.880            6.001                2.839                    8.356
premium doubled           2.880           12.001                2.839                   16.712
premium halved            6.416            6.684                6.332                   12.474

approvals take half a year; HR steers as if they took a quarter (14 years simulated)
  best rule, built for a quarter   cost  19.995, largest surplus  16.35
  Step 2's gain on today's gap     cost  42.850, largest surplus  64.29
  Volume I's cautious gain         cost  19.530, largest surplus  12.07
  rule built for half a year       cost  18.540 (K' = 4.220; simulated 18.540, largest surplus 0.00)

least cost by the time approvals take to land: at once 9.037, a month 10.951, a quarter 14.351, half a year 18.540
cutting the delay from a quarter to a month is worth 3.400 from 100 short

only 30 percent of approvals become engineers: the rule built for 60 percent costs 19.611 (largest surplus 0.00); redesigned, K' = 3.675, 19.534: within 0.077

Panel 8 — Compare prices: the HJB equation along Chapter 6's best plans (Theorem 8.1(iii); Propositions 8.1 and 8.2)

AXIOM Lab 2.8, step 4. Chapter 6's capability problem (Worked Example 6.1): capability cc decays at δ=4ln⁡(1/0.975)=0.101\delta = 4\ln(1/0.975) = 0.101 a year; hiring and training cost $4 million a point, up to 10.13 points a year; the digital build waits, at $32 million a year, until capability first reaches the floor of 55, which it must then keep; ρ=ln⁡1.1\rho = \ln 1.1. Hiring enters linearly, so the rule compares a point's price with its cost (Proposition 8.1(i)): the cap where the price is above $4 million, nothing where it is below, the rent on the floor. Along each best plan the value's slope is Chapter 6's costate (Theorem 8.1(iii)), and the hurdle return on the position equals what the plan earns plus the change in the position's value (Proposition 8.1(iv)). The value has two corners (Proposition 8.2): at 43.45, where racing to the floor ties with never starting the build, and at 55, where the build starts.

Python Code
DELTA = 4 * np.log(1 / 0.975)          # attrition, 2.5 percent a quarter, a year in continuous time
UBAR = 100 * DELTA                     # hiring cap: keeps Volume I's ceiling of 100
KC, FLOOR, DELAY = 4.0, 55.0, 32.0     # $4 million a point; the floor; the delay while the build waits, a year
TOP = UBAR / DELTA
V_FLOOR = -KC * DELTA * FLOOR / RHO    # pay the rent, delta x 55 points a year, forever
NEVER = -DELAY / RHO                   # never start the build: the delay forever

def race_time(c0):                     # at the cap from c0 up to the floor
    return np.log((TOP - c0) / (TOP - FLOOR)) / DELTA if c0 < FLOOR else 0.0
def drift_time(c0):                    # hiring nothing, from c0 down to the floor
    return np.log(c0 / FLOOR) / DELTA if c0 > FLOOR else 0.0
def value(c0):                         # Chapter 6's best plan: race up to the floor or drift down to it, then the rent
    if c0 < FLOOR:
        t = race_time(c0)
        return -(KC * UBAR + DELAY) * (1 - np.exp(-RHO * t)) / RHO + np.exp(-RHO * t) * V_FLOOR
    return np.exp(-RHO * drift_time(c0)) * V_FLOOR
def best_value(c0):                    # the value function: below the floor, the better of racing and never starting
    return max(value(c0), NEVER) if c0 < FLOOR else value(c0)
def price(c0):                         # the slope of the value along each plan (Chapter 6's costate), $4m on the floor
    if c0 < FLOOR:
        return np.exp(-RHO * race_time(c0)) * (KC * UBAR + DELAY + RHO * V_FLOOR) / (UBAR - DELTA * c0)
    if c0 == FLOOR:
        return KC
    return np.exp(-RHO * drift_time(c0)) * (-RHO * V_FLOOR) / (DELTA * c0)

x = KC * UBAR / (KC * UBAR + DELAY + RHO * V_FLOOR)      # e^(-rho tau) at the level where racing ties never starting
c_a = TOP - (TOP - FLOOR) * x ** (-DELTA / RHO)
assert abs(c_a - brentq(lambda c: value(c) - NEVER, 30.0, 54.9, xtol=1e-12)) < 1e-9
print(f"delta = {DELTA:.6f}, cap {UBAR:.4f} points a year; V(45) = {best_value(45.0):.3f}, V(53) = {best_value(53.0):.3f}, "
      f"V(55) = {best_value(55.0):.3f}, V(58) = {best_value(58.0):.3f}")
for c0, what in ((53.0, "hire at the cap"), (55.0, "hold: pay the rent"), (58.0, "hire nothing")):
    print(f"  at {c0:.0f} a point is worth {price(c0):6.3f}; switching function V' - 4 = {price(c0) - KC:+.3f}: {what}")

V58, m58, drift58 = best_value(58.0), price(58.0), DELTA * 58.0
print(f"HJB at 58: rho V(58) = {RHO:.6f} x {V58:.3f} = {RHO * V58:.3f}; the drift {drift58:.4f} points a year at "
      f"{m58:.4f} a point costs {drift58 * m58:.3f}: carrying the position costs {-RHO * V58:.2f} a year, exactly that")

print("\nPMP-HJB comparison: Chapter 6's costate m(t) = m(0) e^((rho + delta) t) against the slope of the value at c(t)")
for name, c0, T_arc, path in (("drift from 58", 58.0, drift_time(58.0), lambda t: 58.0 * np.exp(-DELTA * t)),
                              ("race from 53", 53.0, race_time(53.0), lambda t: TOP - (TOP - 53.0) * np.exp(-DELTA * t))):
    ts = np.linspace(0, T_arc, 400, endpoint=False)
    costate = price(c0) * np.exp((RHO + DELTA) * ts)
    slope = np.array([(value(path(t) + 1e-5) - value(path(t) - 1e-5)) / 2e-5 for t in ts])
    print(f"  {name:13s}: {T_arc:.4f} years; the price goes from {costate[0]:.3f} to {price(c0) * np.exp((RHO + DELTA) * T_arc):.3f}"
          f" on arrival; largest gap between costate and slope {np.abs(costate - slope).max():.1e}")
ts = np.linspace(0, drift_time(58.0), 400, endpoint=False)
cs = 58.0 * np.exp(-DELTA * ts)
gap = max(abs(RHO * value(c) - price(c) * (-DELTA * c)) for c in cs)
print(f"  hurdle return along the drift: rho V(c(t)) = 0 + V'(c) dc/dt to {gap:.1e} (Proposition 8.1(iv))")

print(f"\ncorners (Proposition 8.2): at c_a = {c_a:.3f} the slope jumps from 0 to {price(c_a):.3f}; at the floor from "
      f"{KC + DELAY / (UBAR - DELTA * FLOOR):.3f} (its cost plus the delay it saves) to {KC:.0f}")
rent = KC * DELTA * FLOOR
print(f"holding the floor: the rent {rent:.2f} a year is {100 * rent / -V_FLOOR:.1f} percent of the position's {-V_FLOOR:.2f}: "
      f"the hurdle return, exactly")
print(f"holding at c_a would cost the rent on {c_a:.2f}, {KC * DELTA * c_a:.2f}, plus the delay: {KC * DELTA * c_a + DELAY:.2f} a year, "
      f"more than the {DELAY:.0f} a year never starting costs at the hurdle rate")
levels = np.concatenate([np.linspace(30.0, c_a - 0.01, 200), np.linspace(c_a + 0.01, FLOOR - 0.01, 300), np.linspace(FLOOR + 0.01, 80.0, 300)])
def hjb_gap(c0):                       # rho V - max over u in [0, cap] of {-4u - 32 1{c < 55} + V'(u - delta c)}
    slope = (best_value(c0 + 1e-6) - best_value(c0 - 1e-6)) / 2e-6
    wait = DELAY if c0 < FLOOR else 0.0
    return RHO * best_value(c0) - max(-KC * u - wait + slope * (u - DELTA * c0) for u in (0.0, UBAR))
print(f"the candidate value solves the HJB equation off its corners: largest residual {max(abs(hjb_gap(c)) for c in levels):.1e} "
      f"over {len(levels)} levels; so Proposition 8.2(i) certifies Chapter 6's plans across both corners")
delta = 0.101271, cap 10.1271 points a year; V(45) = -324.455, V(53) = -254.892, V(55) = -233.760, V(58) = -222.363
  at 53 a point is worth 10.130; switching function V' - 4 = +6.130: hire at the cap
  at 55 a point is worth  4.000; switching function V' - 4 = +0.000: hold: pay the rent
  at 58 a point is worth  3.608; switching function V' - 4 = -0.392: hire nothing
HJB at 58: rho V(58) = 0.095310 x -222.363 = -21.193; the drift 5.8737 points a year at 3.6082 a point costs 21.193: carrying the position costs 21.19 a year, exactly that

PMP-HJB comparison: Chapter 6's costate m(t) = m(0) e^((rho + delta) t) against the slope of the value at c(t)
  drift from 58: 0.5244 years; the price goes from 3.608 to 4.000 on arrival; largest gap between costate and slope 4.6e-09
  race from 53 : 0.4294 years; the price goes from 10.130 to 11.022 on arrival; largest gap between costate and slope 1.0e-08
  hurdle return along the drift: rho V(c(t)) = 0 + V'(c) dc/dt to 3.6e-15 (Proposition 8.1(iv))

corners (Proposition 8.2): at c_a = 43.446 the slope jumps from 0 to 7.073; at the floor from 11.022 (its cost plus the delay it saves) to 4
holding the floor: the rent 22.28 a year is 9.5 percent of the position's 233.76: the hurdle return, exactly
holding at c_a would cost the rent on 43.45, 17.60, plus the delay: 49.60 a year, more than the 32 a year never starting costs at the hurdle rate
the candidate value solves the HJB equation off its corners: largest residual 4.9e-07 over 800 levels; so Proposition 8.2(i) certifies Chapter 6's plans across both corners

Panel 9 — Solve on a grid: upwind schemes, corners and convergence (Proposition 8.4; Figure 8.1; Online Appendix 8.B.2)

AXIOM Lab 2.8, step 5. On a grid of spacing hh between 30 and 80, replace the value's slope by its difference toward the neighbor the drift points to. The equations are the Bellman equation of a dynamic program on the grid in which capability moves to that neighbor at the rate ∣f∣/h|f|/h. Each equation sets a level's value as a function that rises with its neighbor's value — the scheme is monotone — and the equations have exactly one solution, which policy iteration finds, with its rule, in finitely many steps. At each level Meridian can hire nothing, hire at the cap, or hold. Start from Chapter 6's plans — race below the floor, hold on it, drift above it — and refine the grid from one point to a sixteenth.

Python Code
NAMES = ("nothing", "cap", "hold")

def scheme(h, lo=30.0, hi=80.0):
    # Proposition 8.4(i): upwind equations on the grid, solved by policy iteration (a sparse linear solve per step)
    c = np.round(np.arange(lo, hi + 1e-9, h), 10)
    n, iF, j = len(c), int(round((FLOOR - lo) / h)), np.arange(len(c))
    cost, drift, ok = [], [], []
    for name, u in zip(NAMES, (np.zeros(n), np.full(n, UBAR), DELTA * c)):
        f = u - DELTA * c
        cst = KC * u + np.where(j < iF, DELAY, 0.0)
        allow = np.ones(n, bool)
        allow[iF] = f[iF] >= -1e-12             # the running build may not fall below the floor
        if f[0] < 0:                            # below the grid the build never starts: the delay forever
            if name == "nothing":
                cst[0], f[0] = DELAY, 0.0
            else:
                allow[0] = False
        allow[-1] &= f[-1] <= 0                 # hiring that would leave the grid is excluded
        cost.append(cst); drift.append(f); ok.append(allow)
    def evaluate(pol):
        f, cst = np.choose(pol, drift), np.choose(pol, cost)
        up, down = np.maximum(f, 0) / h, np.maximum(-f, 0) / h
        M = sp.diags([RHO + up + down, -up[:-1], -down[1:]], [0, 1, -1], format="csc")
        return spla.spsolve(M, -cst)
    pol = np.where(j < iF, 1, np.where(j == iF, 2, 0))     # Chapter 6's plans: race, hold, drift
    edges = []
    for step in range(1, 5001):
        V = evaluate(pol)
        Vup, Vdown = np.append(V[1:], V[-1]), np.insert(V[:-1], 0, V[0])
        best, arg = np.full(n, -np.inf), np.full(n, -1)
        for i, name in enumerate(NAMES):        # greedy for V; a tie keeps the earlier decision
            f = drift[i]
            slope = np.where(f > 0, (Vup - V) / h, np.where(f < 0, (V - Vdown) / h, 0.0))
            val = -cost[i] + f * slope
            take = ok[i] & ((arg < 0) | (val > best + 1e-12))
            best, arg = np.where(take, val, best), np.where(take, i, arg)
        if (arg == pol).all():
            break
        pol = arg
        edges.append(c[(pol == 0) & (j < iF)].max() if ((pol == 0) & (j < iF)).any() else None)
    exact = np.array([best_value(x) for x in c])
    err = np.abs(V - exact)
    Lam = np.array([np.abs(drift[i]) / h for i in range(3)])
    weights = np.where(np.array(ok), Lam / (RHO + Lam), 0.0).max()
    return dict(h=h, c=c, V=V, pol=pol, steps=step, edges=edges, n=n, iF=iF,
                vals={x: float(np.interp(x, c, V)) for x in (45.0, 53.0, 55.0, 58.0)},
                err4=max(abs(np.interp(x, c, V) - best_value(x)) for x in (45.0, 53.0, 55.0, 58.0)),
                err_all=float(err.max()), at=float(c[err.argmax()]), race_from=float(c[(pol == 1) & (j < iF)].min()),
                below=(V[iF] - V[iF - 1]) / h, above=(V[iF + 1] - V[iF]) / h, modulus=float(weights))

grids = [scheme(h) for h in (1.0, 0.5, 0.25, 0.125, 0.0625)]
exact4 = {x: best_value(x) for x in (45.0, 53.0, 55.0, 58.0)}
print("closed form: " + ", ".join(f"V({x:.0f}) = {v_:.3f}" for x, v_ in exact4.items()) + f"; never-start threshold {c_a:.3f}")
print("  grid   levels  steps    V(45)     V(53)     V(55)     V(58)   error at   error over all   race   price at the floor")
print("                                                                these four  levels (at)     from    below   above")
for g in grids:
    print(f"{g['h']:7.4f} {g['n']:6d} {g['steps']:5d} " + " ".join(f"{v_:9.3f}" for v_ in g["vals"].values())
          + f" {g['err4']:9.4f} {g['err_all']:9.4f} ({g['at']:.4f}) {g['race_from']:7.4f} {g['below']:7.3f} {g['above']:7.3f}")
print(f"closed form{'':72s} {c_a:7.3f} {KC + DELAY / (UBAR - DELTA * FLOOR):7.3f} {KC:7.3f}")
print("the error halves with the spacing: " + ", ".join(f"{grids[i]['err_all'] / grids[i + 1]['err_all']:.2f}" for i in range(4)))
print(f"on the floor the scheme is exact: {grids[-1]['vals'][55.0]:.3f} = -4 delta 55 / rho = {V_FLOOR:.3f}")
print("grid 1: the never-start edge after each improvement: " + ", ".join(f"{e:.0f}" for e in grids[0]["edges"])
      + f"; evaluation {grids[0]['steps']} confirms the rule")
print("monotonicity audit: every weight on a neighbor is nonnegative and they sum to at most "
      + ", ".join(f"{g['modulus']:.5f}" for g in grids) + " (grid 1 to 1/16): a contraction")
print(f"the curse (Proposition 8.4(iii)): two stocks on grids of 801 levels need {801**2:,} positions; Meridian's eight "
      f"coordinates {801.0**8:.1e}; a linear-quadratic model of them, {8 * 9 // 2} Riccati unknowns")

g1 = grids[0]
cs = np.linspace(40, 62, 1101)
sel = (g1["c"] >= 40) & (g1["c"] <= 62)
fig, ax = plt.subplots(figsize=(7.6, 3.6))
ax.plot(cs, [best_value(c) for c in cs], color="#1F4E79", lw=2, label="closed form (Chapter 6)")
ax.plot(g1["c"][sel], g1["V"][sel], "o", color="#E65100", ms=4, label="upwind scheme, grid of one point")
ax.axhline(NEVER, xmax=(c_a - 40) / 22, color="#616161", lw=0.8, ls="--")
ax.text(40.3, NEVER + 3, f"never start: {NEVER:.2f}", fontsize=8, color="#616161")
ax.annotate(f"corner at {c_a:.2f}: racing\nties with never starting", xy=(c_a, NEVER), xytext=(46.3, -338), fontsize=8,
            arrowprops=dict(arrowstyle="-", color="#333333", lw=0.7))
ax.annotate("corner at 55: the build\nstarts; the price falls\nfrom \\$11.02m to \\$4m", xy=(FLOOR, V_FLOOR), xytext=(56.2, -268),
            fontsize=8, arrowprops=dict(arrowstyle="-", color="#333333", lw=0.7))
ax.set(xlim=(40, 62), ylim=(-345, -205), xlabel="workforce capability (points)", ylabel="value of the position ($ million)",
       title="Chapter 6's value has corners at 43.45 and 55 (seed 26208)")
ax.legend(frameon=False, fontsize=8, loc="lower right"); plt.tight_layout(); plt.show()
closed form: V(45) = -324.455, V(53) = -254.892, V(55) = -233.760, V(58) = -222.363; never-start threshold 43.446
  grid   levels  steps    V(45)     V(53)     V(55)     V(58)   error at   error over all   race   price at the floor
                                                                these four  levels (at)     from    below   above
 1.0000     51    15  -322.873  -254.464  -233.760  -222.551    1.5825    1.6814 (44.0000) 44.0000  10.566   3.864
 0.5000    101    28  -323.657  -254.676  -233.760  -222.457    0.7981    0.8713 (43.5000) 43.5000  10.789   3.931
 0.2500    201    55  -324.054  -254.783  -233.760  -222.410    0.4008    0.4375 (43.5000) 43.5000  10.904   3.965
 0.1250    401   109  -324.254  -254.838  -233.760  -222.386    0.2008    0.2192 (43.5000) 43.5000  10.963   3.982
 0.0625    801   216  -324.355  -254.865  -233.760  -222.375    0.1005    0.1097 (43.5000) 43.4375  10.992   3.991
closed form                                                                          43.446  11.022   4.000
the error halves with the spacing: 1.93, 1.99, 2.00, 2.00
on the floor the scheme is exact: -233.760 = -4 delta 55 / rho = -233.760
grid 1: the never-start edge after each improvement: 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43; evaluation 15 confirms the rule
monotonicity audit: every weight on a neighbor is nonnegative and they sum to at most 0.98837, 0.99415, 0.99707, 0.99853, 0.99927 (grid 1 to 1/16): a contraction
the curse (Proposition 8.4(iii)): two stocks on grids of 801 levels need 641,601 positions; Meridian's eight coordinates 1.7e+23; a linear-quadratic model of them, 36 Riccati unknowns
Chapter 6's value has corners at 43.45 and 55 (seed 26208)

Validation — the book's numbers, and agreement with DCT_V2_Ch08_Lab.xlsx

Each checkpoint is a number printed in Chapter 8 (Worked Example 8.1, Table 8.3, Sections 8.2–8.6, Figures 8.1–8.3) or in Online Appendix 8.B.1–8.B.2, with a tolerance of half a unit in its last printed digit. The workbook recomputes the ones marked workbook with Excel formulas and shows PASS against the same engine values on its Checks sheet.

Python Code
T83 = {r_["name"]: r_ for r_ in table83}
today2, tbest, caut, dead = (T83[n_] for n_ in ("Step 2's gain on today's gap", "Best gain on today's gap",
                                                  "Volume I's cautious gain", "Volume I's deadbeat gain"))
g1, g16 = grids[0], grids[-1]
checks = [
    ("Riccati root p (workbook)", p, 0.00090372, 5e-9),
    ("second root p- (workbook)", p_minus, -0.00122948, 5e-9),
    ("gain K, a year (workbook)", K, 4.3379, 5e-5),
    ("half-life of the gap, months (workbook)", 12 * np.log(2) / lam, 2.75, 5e-3),
    ("least cost without the delay (workbook)", p * 1e4, 9.037, 5e-4),
    ("price of an engineer of gap at 100 short (workbook)", 2 * p * 100, 0.1807, 5e-5),
    ("second root: its closed loop grows (workbook)", grow, 3.119, 5e-4),
    ("policy iteration: first improved gain (workbook)", kleinman[1][0], 5.3202, 5e-5),
    ("policy iteration: second improved gain (workbook)", kleinman[2][0], 4.4169, 5e-5),
    ("policy iteration: third improved gain (workbook)", kleinman[3][0], 4.3385, 5e-5),
    ("policy iteration: cost of the first improved rule (workbook)", kleinman[1][1] * 1e4, 9.2020, 5e-5),
    ("q' = q e^(-rho/4) (workbook)", pre["q"], 0.00312465, 5e-9),
    ("gain K' on the predicted gap, a year (workbook)", Kz, 4.2787, 5e-5),
    ("first quarter's cost (workbook)", pre["first"], 7.131, 5e-4),
    ("least cost with the delay (workbook)", pre["total"], 14.351, 5e-4),
    ("the quarter's delay costs (workbook)", pre["total"] - p * 1e4, 5.314, 5e-4),
    ("approvals in the first quarter (workbook)", approved_q1, 67.8, 0.05),
    ("gap after a year, best rule (workbook)", gap_1y, -9.57, 5e-3),
    ("price of an engineer with the delay (workbook)", price_delay, 0.2870, 5e-5),
    ("predicted-gap rule, simulated", T83["Best rule: steer by the predicted gap"]["cost"], 14.3513, 5e-5),
    ("Step 2's gain on today's gap: cost", today2["cost"], 17.471, 5e-4),
    ("Step 2's gain on today's gap: largest surplus", today2["peak"], 15.87, 5e-3),
    ("Step 2's gain on today's gap: gap after a year", today2["d1"], 12.24, 5e-3),
    ("best gain on today's gap, a year", k_best, 2.482, 5e-4),
    ("best gain on today's gap: extra cost", tbest["cost"] - best_cost, 0.230, 5e-4),
    ("best gain on today's gap: approved in the first quarter", tbest["first_q"], 58.9, 0.05),
    ("Volume I's cautious gain: extra cost", caut["cost"] - best_cost, 0.493, 5e-4),
    ("Volume I's deadbeat gain: cost", dead["cost"], 25.070, 5e-4),
    ("Volume I's deadbeat gain: largest surplus", dead["peak"], 36.56, 5e-3),
    ("best gain on today's gap, at once (workbook)", cost_at_once(k_best), 10.136, 5e-4),
    ("cautious gain at once (workbook)", cost_at_once(CAUTIOUS), 11.084, 5e-4),
    ("deadbeat gain at once (workbook)", cost_at_once(DEADBEAT), 9.462, 5e-4),
    ("critical gain on today's gap, a year (workbook)", k_c, 10.92, 5e-3),
    ("gain 10: largest gap in years 2-4", swings[10.0][0], 61.4, 0.05),
    ("gain 10: largest gap in years 10-12", swings[10.0][1], 8.4, 0.05),
    ("gain 12: largest gap in years 2-4", swings[12.0][0], 280, 0.5),
    ("gain 12: largest gap in years 10-12 (about)", swings[12.0][1], 2410, 5),
    ("gap cost doubled: gain K' (workbook)", sens["gap cost doubled"][2], 6.332, 5e-4),
    ("gap cost doubled: least cost with the delay (workbook)", sens["gap cost doubled"][3], 24.947, 5e-4),
    ("premium doubled: least cost with the delay (workbook)", sens["premium doubled"][3], 16.712, 5e-4),
    ("half a year's delay: rule built for a quarter", half["best rule, built for a quarter"][0], 19.995, 5e-4),
    ("half a year's delay: Step 2's gain on today's gap", half["Step 2's gain on today's gap"][0], 42.850, 5e-4),
    ("half a year's delay: cautious gain", half["Volume I's cautious gain"][0], 19.530, 5e-4),
    ("half a year's delay: rule built for it (workbook)", re_half["total"], 18.540, 5e-4),
    ("least cost if approvals land in a month (workbook)", onboard["a month"], 10.951, 5e-4),
    ("productivity 30%: rule built for 60%", low["cost"], 19.611, 5e-4),
    ("productivity 30%: redesigned rule (workbook)", low_re["total"], 19.534, 5e-4),
    ("Chapter 6: V(45) (workbook)", best_value(45.0), -324.455, 5e-4),
    ("Chapter 6: V(53) (workbook)", best_value(53.0), -254.892, 5e-4),
    ("Chapter 6: V(58) (workbook)", best_value(58.0), -222.363, 5e-4),
    ("never-start threshold (workbook)", c_a, 43.446, 5e-4),
    ("price just above the threshold (workbook)", price(c_a), 7.07, 5e-3),
    ("price just below the floor (workbook)", KC + DELAY / (UBAR - DELTA * FLOOR), 11.022, 5e-4),
    ("HJB at 58: hurdle return on the position (workbook)", -RHO * V58, 21.193, 5e-4),
    ("HJB at 58: drift, points a year (workbook)", drift58, 5.8737, 5e-5),
    ("HJB at 58: price of a point (workbook)", m58, 3.6082, 5e-5),
    ("holding at the threshold, a year (workbook)", KC * DELTA * c_a + DELAY, 49.60, 5e-3),
    ("scheme, grid 1: policy-iteration steps", g1["steps"], 15, 0),
    ("scheme, grid 1/16: policy-iteration steps", g16["steps"], 216, 0),
    ("scheme, grid 1: largest error at 45, 53, 55, 58 (workbook)", g1["err4"], 1.5825, 5e-5),
    ("scheme, grid 1: largest error over all levels (workbook)", g1["err_all"], 1.681, 5e-4),
    ("scheme, grid 1/16: largest error over all levels (workbook)", g16["err_all"], 0.110, 5e-4),
    ("scheme, grid 1/16: price just below the floor (workbook)", g16["below"], 10.992, 5e-4),
    ("scheme, grid 1/16: price just above the floor (workbook)", g16["above"], 3.991, 5e-4),
    ("scheme, grid 1/16: the race starts from (workbook)", g16["race_from"], 43.4375, 5e-5),
]
ok = 0
for name, got, want, tol in checks:
    status = "PASS" if abs(got - want) <= tol else "FAIL"; ok += status == "PASS"
    fmt = ".8f" if abs(want) < 0.01 else ".4f"
    print(f"{name:62s} {got:14{fmt}}   book {want:12{fmt}}   {status}")
print(f"\n{ok} of {len(checks)} checkpoints PASS")
Riccati root p (workbook)                                          0.00090372   book   0.00090372   PASS
second root p- (workbook)                                         -0.00122948   book  -0.00122948   PASS
gain K, a year (workbook)                                              4.3379   book       4.3379   PASS
half-life of the gap, months (workbook)                                2.7504   book       2.7500   PASS
least cost without the delay (workbook)                                9.0372   book       9.0370   PASS
price of an engineer of gap at 100 short (workbook)                    0.1807   book       0.1807   PASS
second root: its closed loop grows (workbook)                          3.1195   book       3.1190   PASS
policy iteration: first improved gain (workbook)                       5.3202   book       5.3202   PASS
policy iteration: second improved gain (workbook)                      4.4169   book       4.4169   PASS
policy iteration: third improved gain (workbook)                       4.3385   book       4.3385   PASS
policy iteration: cost of the first improved rule (workbook)           9.2020   book       9.2020   PASS
q' = q e^(-rho/4) (workbook)                                       0.00312465   book   0.00312465   PASS
gain K' on the predicted gap, a year (workbook)                        4.2787   book       4.2787   PASS
first quarter's cost (workbook)                                        7.1310   book       7.1310   PASS
least cost with the delay (workbook)                                  14.3513   book      14.3510   PASS
the quarter's delay costs (workbook)                                   5.3141   book       5.3140   PASS
approvals in the first quarter (workbook)                             67.8112   book      67.8000   PASS
gap after a year, best rule (workbook)                                -9.5671   book      -9.5700   PASS
price of an engineer with the delay (workbook)                         0.2870   book       0.2870   PASS
predicted-gap rule, simulated                                         14.3513   book      14.3513   PASS
Step 2's gain on today's gap: cost                                    17.4708   book      17.4710   PASS
Step 2's gain on today's gap: largest surplus                         15.8666   book      15.8700   PASS
Step 2's gain on today's gap: gap after a year                        12.2423   book      12.2400   PASS
best gain on today's gap, a year                                       2.4823   book       2.4820   PASS
best gain on today's gap: extra cost                                   0.2299   book       0.2300   PASS
best gain on today's gap: approved in the first quarter               58.9019   book      58.9000   PASS
Volume I's cautious gain: extra cost                                   0.4927   book       0.4930   PASS
Volume I's deadbeat gain: cost                                        25.0695   book      25.0700   PASS
Volume I's deadbeat gain: largest surplus                             36.5589   book      36.5600   PASS
best gain on today's gap, at once (workbook)                          10.1359   book      10.1360   PASS
cautious gain at once (workbook)                                      11.0838   book      11.0840   PASS
deadbeat gain at once (workbook)                                       9.4616   book       9.4620   PASS
critical gain on today's gap, a year (workbook)                       10.9236   book      10.9200   PASS
gain 10: largest gap in years 2-4                                     61.3996   book      61.4000   PASS
gain 10: largest gap in years 10-12                                    8.3705   book       8.4000   PASS
gain 12: largest gap in years 2-4                                    280.3330   book     280.0000   PASS
gain 12: largest gap in years 10-12 (about)                         2412.6239   book    2410.0000   PASS
gap cost doubled: gain K' (workbook)                                   6.3319   book       6.3320   PASS
gap cost doubled: least cost with the delay (workbook)                24.9472   book      24.9470   PASS
premium doubled: least cost with the delay (workbook)                 16.7124   book      16.7120   PASS
half a year's delay: rule built for a quarter                         19.9949   book      19.9950   PASS
half a year's delay: Step 2's gain on today's gap                     42.8504   book      42.8500   PASS
half a year's delay: cautious gain                                    19.5295   book      19.5300   PASS
half a year's delay: rule built for it (workbook)                     18.5396   book      18.5400   PASS
least cost if approvals land in a month (workbook)                    10.9508   book      10.9510   PASS
productivity 30%: rule built for 60%                                  19.6109   book      19.6110   PASS
productivity 30%: redesigned rule (workbook)                          19.5338   book      19.5340   PASS
Chapter 6: V(45) (workbook)                                         -324.4552   book    -324.4550   PASS
Chapter 6: V(53) (workbook)                                         -254.8921   book    -254.8920   PASS
Chapter 6: V(58) (workbook)                                         -222.3627   book    -222.3630   PASS
never-start threshold (workbook)                                      43.4462   book      43.4460   PASS
price just above the threshold (workbook)                              7.0729   book       7.0700   PASS
price just below the floor (workbook)                                 11.0218   book      11.0220   PASS
HJB at 58: hurdle return on the position (workbook)                   21.1934   book      21.1930   PASS
HJB at 58: drift, points a year (workbook)                             5.8737   book       5.8737   PASS
HJB at 58: price of a point (workbook)                                 3.6082   book       3.6082   PASS
holding at the threshold, a year (workbook)                           49.5994   book      49.6000   PASS
scheme, grid 1: policy-iteration steps                                15.0000   book      15.0000   PASS
scheme, grid 1/16: policy-iteration steps                            216.0000   book     216.0000   PASS
scheme, grid 1: largest error at 45, 53, 55, 58 (workbook)             1.5825   book       1.5825   PASS
scheme, grid 1: largest error over all levels (workbook)               1.6814   book       1.6810   PASS
scheme, grid 1/16: largest error over all levels (workbook)            0.1097   book       0.1100   PASS
scheme, grid 1/16: price just below the floor (workbook)              10.9922   book      10.9920   PASS
scheme, grid 1/16: price just above the floor (workbook)               3.9912   book       3.9910   PASS
scheme, grid 1/16: the race starts from (workbook)                    43.4375   book      43.4375   PASS

65 of 65 checkpoints PASS

Next. Chapter 9 opens Part III, where outside events push the stocks at random: the HJB equation gains a term for their spread, and verification, viscosity solutions and monotone schemes carry over (Section 8.5). AXIOM-08 runs the same models interactively (Lab 2.8); this notebook and the workbook are its reproducible record.

Dynamic Corporate Transformation — Volume I: Foundations and Mathematical Framework; Volume II: Enterprise Optimization & Applications
Jump to any chapter

Volume I: Foundations and Mathematical Framework

  1. Ch. 1Introduction to Dynamic Corporate Transformation
  2. Ch. 2Enterprise Systems and Transformation
  3. Ch. 3Mathematical Foundations
  4. Ch. 4Enterprise Modeling Principles
  5. Ch. 5Enterprise State Representation
  6. Ch. 6Enterprise Transformation Operators
  7. Ch. 7Dynamic Enterprise Systems
  8. Ch. 8Stochastic Enterprise Dynamics
  9. Ch. 9Enterprise State Architecture
  10. Ch. 10Enterprise Capital Architecture
  11. Ch. 11Enterprise Performance Architecture
  12. Ch. 12Enterprise Risk, Resilience, and Robustness Architecture
  13. Ch. 13Unified Enterprise Transformation Architecture
  14. Ch. 14Mathematical Analysis of the Unified Enterprise Transformation Architecture
  15. Ch. 15Mathematical Formulation of Enterprise Optimization
  16. Ch. 16Synthesis, Future Directions, and Transition to Volume II

Volume II: Enterprise Optimization & Applications

  1. Ch. 1Introduction to Enterprise Optimization
  2. Ch. 2The General Enterprise Optimization Problem Revisited
  3. Ch. 3Convex Enterprise Optimization
  4. Ch. 4Nonlinear and Mixed-Integer Enterprise Optimization
  5. Ch. 5Dynamic Enterprise Optimization
  6. Ch. 6Optimal Control of Enterprise Systems
  7. Ch. 7Dynamic Programming for Enterprise Systems
  8. Ch. 8Hamilton–Jacobi–Bellman Enterprise Framework
  9. Ch. 9Stochastic Enterprise Optimization
  10. Ch. 10Neuro-Fuzzy Robust Enterprise Optimization
  11. Ch. 11Distributionally Robust Enterprise Optimization
  12. Ch. 12Multi-Objective Enterprise Optimization
  13. Ch. 13Machine Learning for Enterprise Transformation
  14. Ch. 14Artificial Intelligence for Enterprise Optimization
  15. Ch. 15Enterprise Digital Twins and Autonomous Enterprise Transformation
  16. Ch. 16Enterprise Applications and Integrated Transformation Case Studies

Dynamic Corporate Transformation

Springer Nature · Management for Professionals · Forthcoming 2027

  • Volume I — Foundations and Mathematical Framework
  • Volume II — Enterprise Optimization & Applications
Buy Volume I: Dynamic Corporate Transformation: Foundations and Mathematical FrameworkBuy Volume II: Dynamic Corporate Transformation: Enterprise Optimization & Applications
Jump to any chapter

Volume I: Foundations and Mathematical Framework

  1. Ch. 1Introduction to Dynamic Corporate Transformation
  2. Ch. 2Enterprise Systems and Transformation
  3. Ch. 3Mathematical Foundations
  4. Ch. 4Enterprise Modeling Principles
  5. Ch. 5Enterprise State Representation
  6. Ch. 6Enterprise Transformation Operators
  7. Ch. 7Dynamic Enterprise Systems
  8. Ch. 8Stochastic Enterprise Dynamics
  9. Ch. 9Enterprise State Architecture
  10. Ch. 10Enterprise Capital Architecture
  11. Ch. 11Enterprise Performance Architecture
  12. Ch. 12Enterprise Risk, Resilience, and Robustness Architecture
  13. Ch. 13Unified Enterprise Transformation Architecture
  14. Ch. 14Mathematical Analysis of the Unified Enterprise Transformation Architecture
  15. Ch. 15Mathematical Formulation of Enterprise Optimization
  16. Ch. 16Synthesis, Future Directions, and Transition to Volume II

Volume II: Enterprise Optimization & Applications

  1. Ch. 1Introduction to Enterprise Optimization
  2. Ch. 2The General Enterprise Optimization Problem Revisited
  3. Ch. 3Convex Enterprise Optimization
  4. Ch. 4Nonlinear and Mixed-Integer Enterprise Optimization
  5. Ch. 5Dynamic Enterprise Optimization
  6. Ch. 6Optimal Control of Enterprise Systems
  7. Ch. 7Dynamic Programming for Enterprise Systems
  8. Ch. 8Hamilton–Jacobi–Bellman Enterprise Framework
  9. Ch. 9Stochastic Enterprise Optimization
  10. Ch. 10Neuro-Fuzzy Robust Enterprise Optimization
  11. Ch. 11Distributionally Robust Enterprise Optimization
  12. Ch. 12Multi-Objective Enterprise Optimization
  13. Ch. 13Machine Learning for Enterprise Transformation
  14. Ch. 14Artificial Intelligence for Enterprise Optimization
  15. Ch. 15Enterprise Digital Twins and Autonomous Enterprise Transformation
  16. Ch. 16Enterprise Applications and Integrated Transformation Case Studies