{
 "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\n# --- The opus: tesserae with variable weights (Defs. 2.1-2.2) --------------\nw = np.array([3.0, 1.0, 4.0, 1.5, 2.5, 1.0])\nA = {0, 2, 4}                       # the selection: WHICH tesserae\n\ndef value(w, A):\n    return w[sorted(A)].sum() / w.sum()     # |T| = w(A)/W\n\nprint(f\"|T| = {value(w, A):.4f}\")\n\n# --- Equitesseral check: equal weights recover the classical fraction -----\nw_eq = np.full_like(w, w.mean())\nprint(f\"equalized: each tessera has value {value(w_eq, {0}):.4f} = 1/{len(w)}\")\n\nfig, ax = plt.subplots(figsize=(8, 3))\ncolors = [ACCENT if i in A else 'lightsteelblue' for i in range(len(w))]\nax.bar(range(len(w)), w, color=colors, edgecolor='k')\nfor i, wi in enumerate(w):\n    ax.text(i, wi + 0.05, f\"{wi:g}\", ha='center')\nax.set(xlabel='tessera index i', ylabel='weight $w_i$',\n       title=f\"selection $A$ (red):  $|T| = w(A)/W = {value(w, A):.4f}$\")\nplt.tight_layout(); plt.show()\n"
  }
 ]
}