{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "id": "cell-0",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": "# --- house style (the Press palette: accent/navy/gold/parchment) ---\nimport matplotlib as mpl\nACCENT, NAVY, GOLD, PARCH = '#7a1f1f', '#1f3a5f', '#b8860b', '#f7f2e7'\nmpl.rcParams.update({'figure.facecolor': PARCH, 'axes.facecolor': '#fffdf6',\n                     'axes.edgecolor': '#c9bfa3', 'font.family': 'serif'})\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nf = lambda x: 1.2*np.exp(-((x-0.3)**2)/0.004) + 0.9*np.exp(-((x-0.7)**2)/0.01) + 0.05\nxx = np.linspace(0, 1, 4001)\nfv = f(xx)                                       # global peak at x = 0.3\nD_win  = (xx >= 0.18) & (xx <= 0.42)            # contains the peak\nD_lose = (xx >= 0.60) & (xx <= 0.80)            # does not\n\ndef share(lam, mask):\n    z = lam * fv                                 # exponentiate the rule\n    z = z - z.max()                              # log-sum-exp stability\n    e = np.exp(z)\n    return e[mask].sum() / e.sum()\n\nlams = np.linspace(0, 12, 121)\ns_win  = [share(l, D_win)  for l in lams]\ns_lose = [share(l, D_lose) for l in lams]\n\nfig, ax = plt.subplots(figsize=(8, 4))\nax.plot(lams, s_win,  color=ACCENT, lw=2, label='D contains the peak -> 1')\nax.plot(lams, s_lose, color=NAVY,   lw=2, label='D misses the peak -> 0')\nax.set(xlabel='lambda', ylabel='share of D',\n       title=\"exponential morphing concentrates the opus on the rule's summit (Thm 12.2)\")\nax.legend(); plt.tight_layout(); plt.show()\n\nprint(f\"lambda = 12:  share(D with peak) = {s_win[-1]:.6f}   \"\n      f\"share(D without) = {s_lose[-1]:.2e}\")\n"
  }
 ]
}