{
 "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\nfrom matplotlib.patches import Rectangle\n\nw = np.array([3.0, 1.0, 4.0, 1.5]);  A = [0, 2]     # columns: opus 1\nu = np.array([2.0, 1.0, 3.0]);       B = [1, 2]     # rows:    opus 2\n\nP = np.outer(u, w)                      # the product opus w x u, shown as a mosaic\nblock = P[np.ix_(B, A)].sum() / P.sum()\nprod  = (w[A].sum() / w.sum()) * (u[B].sum() / u.sum())\nprint(f\"block share = {block:.6f}   |T1|.|T2| = {prod:.6f}   \"\n      f\"equal: {np.isclose(block, prod)}  (Thm 5.1)\")\n\nfig, ax = plt.subplots(figsize=(6, 4))\nax.imshow(P, cmap='Blues')\nfor i in range(len(u)):\n    for j in range(len(w)):\n        ax.text(j, i, f\"{P[i, j]:g}\", ha='center', va='center')\nax.add_patch(Rectangle((min(A)-0.5, min(B)-0.5), len(A), len(B),\n                       fill=False, edgecolor=ACCENT, lw=2.5))\nax.set_title(f\"$A \\\\times B$ highlighted: share {block:.4f} = $|T_1||T_2|$ (Thm 5.1)\")\nplt.tight_layout(); plt.show()\n"
  }
 ]
}