{
 "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\nrng = np.random.default_rng(7)\nw = rng.uniform(0.5, 3.0, size=8); W = w.sum()\nv = lambda S: w[sorted(S)].sum() / W if S else 0.0\n\nA, B = {0, 1, 2, 3}, {2, 3, 4, 5}\nlhs = v(A) + v(B) - v(A & B)\nrhs = v(A | B)\nprint(f\"v(A)+v(B)-v(overlap) = {lhs:.6f}   v(union) = {rhs:.6f}   \"\n      f\"paid back exactly: {np.isclose(lhs, rhs)}  (Thm 3.3)\")\n\nfig, ax = plt.subplots(figsize=(8, 3))\ngroup = ['both' if i in A and i in B else 'A only' if i in A\n         else 'B only' if i in B else 'neither' for i in range(8)]\ncmap = {'both': GOLD, 'A only': ACCENT, 'B only': NAVY, 'neither': 'lightgrey'}\nax.bar(range(8), w, color=[cmap[g] for g in group], edgecolor='k')\nax.set(xlabel='tessera', ylabel='weight',\n       title='gold tesserae are counted twice by v(A)+v(B) - paid back once')\nplt.tight_layout(); plt.show()\n"
  }
 ]
}