{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/gift-framework/GIFT/blob/main/notebooks/GIFT_v3_Framework_Validation.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TobWIgvct-tj"
      },
      "source": [
        "# GIFT v3.0 Framework Validation\n",
        "\n",
        "## Computational Verification of 23 Predictions\n",
        "\n",
        "---\n",
        "\n",
        "This notebook provides a systematic computational verification of the Geometric Information Field Theory (GIFT) framework v3.0. We validate the complete set of **23 predictions**: 10 structural integers arising from the topological invariants of a seven-dimensional G2-holonomy manifold K7, and 13 dimensionless ratios derived from combinations of these invariants with the E8 x E8 gauge structure. Each derivation proceeds from certified topological data to testable physical quantities, with explicit comparison to experimental values from the PDG 2024.\n",
        "\n",
        "---\n",
        "\n",
        "**Contents:**\n",
        "1. Topological Foundations (10 structural integers)\n",
        "2. Foundational Relations (4 derived structural quantities)\n",
        "3. Gauge Sector (2 predictions)\n",
        "4. Lepton Sector (3 predictions)\n",
        "5. Quark Sector (1 prediction)\n",
        "6. Neutrino Sector (4 predictions)\n",
        "7. Cosmological Sector (4 predictions)\n",
        "8. Statistical Summary\n",
        "9. Exports\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "BQvdbTjIt-tk",
        "outputId": "13a45b94-ef4d-43eb-9469-5c1dbfd3b287"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "gift_core not available: No module named 'gift_core'\n",
            "Using inline constants (install giftpy: pip install giftpy)\n",
            "\n",
            "GIFT v3.0 Framework Validation\n",
            "==================================================\n",
            "NumPy version: 2.0.2\n",
            "Execution date: 2025-12-11\n",
            "Dependencies loaded successfully.\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# SETUP AND DEPENDENCIES\n",
        "# =============================================================================\n",
        "\n",
        "import numpy as np\n",
        "from fractions import Fraction\n",
        "from dataclasses import dataclass, field\n",
        "from typing import Dict, List, Tuple, Optional\n",
        "from scipy.special import zeta\n",
        "import json\n",
        "from datetime import datetime\n",
        "import warnings\n",
        "warnings.filterwarnings('ignore')\n",
        "\n",
        "# Visualization\n",
        "import matplotlib.pyplot as plt\n",
        "from mpl_toolkits.mplot3d import Axes3D\n",
        "from matplotlib.patches import FancyBboxPatch, Circle, FancyArrowPatch, Polygon\n",
        "from matplotlib.collections import LineCollection, PolyCollection\n",
        "import matplotlib.patches as mpatches\n",
        "from matplotlib.colors import LinearSegmentedColormap\n",
        "\n",
        "# =============================================================================\n",
        "# GIFT FRAMEWORK - Import from giftpy (PyPI: giftpy, module: gift_core)\n",
        "# =============================================================================\n",
        "try:\n",
        "    from gift_core import (\n",
        "        # Topological constants\n",
        "        DIM_E8, RANK_E8, DIM_E8xE8, DIM_G2, DIM_K7,\n",
        "        B2, B3, H_STAR, P2, DIM_J3O, D_BULK, WEYL_FACTOR, N_GEN,\n",
        "        # Metric invariants\n",
        "        DET_G, KAPPA_T, TAU,\n",
        "        # Gauge sector\n",
        "        SIN2_THETA_W, ALPHA_S_SQUARED,\n",
        "        # Lepton sector\n",
        "        Q_KOIDE, M_TAU_M_E,\n",
        "        # Quark sector\n",
        "        M_S_M_D,\n",
        "        # Neutrino sector\n",
        "        DELTA_CP,\n",
        "        # Relations catalog\n",
        "        PROVEN_RELATIONS, GIFT_COMPARISONS,\n",
        "        # Analysis tools\n",
        "        JoyceCertificate, verify_pinn_bounds,\n",
        "    )\n",
        "    GIFTPY_AVAILABLE = True\n",
        "    print(\"gift_core (giftpy) imported successfully\")\n",
        "    print(f\"  Version: {__import__('gift_core').__version__}\")\n",
        "    print(f\"  PROVEN_RELATIONS: {len(PROVEN_RELATIONS)}\")\n",
        "except ImportError as e:\n",
        "    GIFTPY_AVAILABLE = False\n",
        "    print(f\"gift_core not available: {e}\")\n",
        "    print(\"Using inline constants (install giftpy: pip install giftpy)\")\n",
        "\n",
        "# Configure matplotlib for publication quality\n",
        "plt.rcParams.update({\n",
        "    'font.family': 'serif',\n",
        "    'font.size': 10,\n",
        "    'axes.labelsize': 11,\n",
        "    'axes.titlesize': 12,\n",
        "    'xtick.labelsize': 9,\n",
        "    'ytick.labelsize': 9,\n",
        "    'legend.fontsize': 9,\n",
        "    'figure.figsize': (8, 6),\n",
        "    'figure.dpi': 150,\n",
        "    'savefig.dpi': 300,\n",
        "    'savefig.bbox': 'tight',\n",
        "    'axes.spines.top': False,\n",
        "    'axes.spines.right': False\n",
        "})\n",
        "\n",
        "# Custom colormap for GIFT visualizations\n",
        "GIFT_COLORS = {\n",
        "    'E8': '#2E4057',      # Deep blue\n",
        "    'G2': '#048A81',      # Teal\n",
        "    'K7': '#8B4513',      # Saddle brown\n",
        "    'gold': '#C9A227',    # Gold accent\n",
        "    'light': '#F5F5F5',   # Background\n",
        "    'match': '#2E7D32',   # Green for exact match\n",
        "    'close': '#1565C0',   # Blue for close match\n",
        "    'good': '#F9A825'     # Amber for good match\n",
        "}\n",
        "\n",
        "# Golden ratio\n",
        "PHI = (1 + np.sqrt(5)) / 2\n",
        "\n",
        "print()\n",
        "print(\"GIFT v3.0 Framework Validation\")\n",
        "print(\"=\" * 50)\n",
        "print(f\"NumPy version: {np.__version__}\")\n",
        "print(f\"Execution date: {datetime.now().strftime('%Y-%m-%d')}\")\n",
        "print(\"Dependencies loaded successfully.\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aBNn6UW6t-tl"
      },
      "source": [
        "---\n",
        "\n",
        "## 1. Topological Foundations: The 10 Structural Integers\n",
        "\n",
        "The GIFT framework rests on topological invariants that emerge from the twisted connected sum (TCS) construction of K7. These 10 structural integers constitute the first category of predictions, verified by Joyce's existence theorem and subsequent mathematical developments.\n",
        "\n",
        "**The 10 Structural Predictions:**\n",
        "\n",
        "| # | Invariant | Symbol | Value | Origin |\n",
        "|---|-----------|--------|-------|--------|\n",
        "| 1 | E8 Lie algebra dimension | dim(E8) | 248 | Exceptional Lie theory |\n",
        "| 2 | E8 Cartan rank | rank(E8) | 8 | Root system structure |\n",
        "| 3 | G2 holonomy dimension | dim(G2) | 14 | Holonomy classification |\n",
        "| 4 | Internal manifold dimension | dim(K7) | 7 | M-theory compactification |\n",
        "| 5 | Second Betti number | b2(K7) | 21 | TCS construction |\n",
        "| 6 | Third Betti number | b3(K7) | 77 | TCS construction |\n",
        "| 7 | Effective cohomology | H* | 99 | b2 + b3 + 1 |\n",
        "| 8 | Jordan algebra dimension | dim(J3(O)) | 27 | Exceptional structure |\n",
        "| 9 | Bulk spacetime dimension | D_bulk | 11 | M-theory |\n",
        "| 10 | Weyl factor | Weyl | 5 | |W(E8)| prime factorization |\n",
        "\n",
        "These integers are not free parameters but consequences of discrete structural choices: the gauge group E8 x E8, the TCS topology, and G2 holonomy. The subsequent 13 dimensionless predictions derive from algebraic combinations of these invariants.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "uGOORX9Dt-tm",
        "outputId": "beb66453-a9ed-4a41-8d65-0f98391d6e96"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "TOPOLOGICAL CONSTANTS (source: inline)\n",
            "============================================================\n",
            "\n",
            "--- E8 Exceptional Lie Algebra ---\n",
            "  dim(E8)     = 248\n",
            "  rank(E8)    = 8\n",
            "  dim(E8xE8)  = 496\n",
            "\n",
            "--- G2 Holonomy Structure ---\n",
            "  dim(G2)     = 14\n",
            "  dim(K7)     = 7\n",
            "\n",
            "--- K7 Manifold Topology ---\n",
            "  b2(K7)      = 21\n",
            "  b3(K7)      = 77\n",
            "  H*          = 99\n",
            "  p2          = 2\n",
            "\n",
            "--- Auxiliary Constants ---\n",
            "  dim(J3(O))  = 27\n",
            "  D_bulk      = 11\n",
            "  Weyl        = 5\n",
            "============================================================\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# TOPOLOGICAL CONSTANTS\n",
        "# =============================================================================\n",
        "# When giftpy is available, we use its certified values.\n",
        "# Otherwise, we define them inline for standalone execution.\n",
        "\n",
        "@dataclass\n",
        "class TopologicalConstants:\n",
        "    \"\"\"Certified topological invariants for the GIFT framework.\"\"\"\n",
        "\n",
        "    # E8 Exceptional Lie Algebra\n",
        "    dim_E8: int = DIM_E8 if GIFTPY_AVAILABLE else 248\n",
        "    rank_E8: int = RANK_E8 if GIFTPY_AVAILABLE else 8\n",
        "    dim_E8xE8: int = DIM_E8xE8 if GIFTPY_AVAILABLE else 496\n",
        "\n",
        "    # G2 Holonomy Group\n",
        "    dim_G2: int = DIM_G2 if GIFTPY_AVAILABLE else 14\n",
        "    dim_K7: int = DIM_K7 if GIFTPY_AVAILABLE else 7\n",
        "\n",
        "    # K7 Manifold Topology (TCS Construction)\n",
        "    b2: int = B2 if GIFTPY_AVAILABLE else 21\n",
        "    b3: int = B3 if GIFTPY_AVAILABLE else 77\n",
        "    p2: int = P2 if GIFTPY_AVAILABLE else 2\n",
        "\n",
        "    # Derived Constants\n",
        "    dim_J3O: int = DIM_J3O if GIFTPY_AVAILABLE else 27\n",
        "    D_bulk: int = D_BULK if GIFTPY_AVAILABLE else 11\n",
        "\n",
        "    @property\n",
        "    def H_star(self) -> int:\n",
        "        \"\"\"Effective cohomological dimension.\"\"\"\n",
        "        return self.b2 + self.b3 + 1\n",
        "\n",
        "    @property\n",
        "    def Weyl(self) -> int:\n",
        "        \"\"\"Weyl factor from |W(E8)| prime factorization.\"\"\"\n",
        "        return WEYL_FACTOR if GIFTPY_AVAILABLE else 5\n",
        "\n",
        "    def display(self):\n",
        "        \"\"\"Display all constants.\"\"\"\n",
        "        source = \"giftpy\" if GIFTPY_AVAILABLE else \"inline\"\n",
        "        print(\"=\" * 60)\n",
        "        print(f\"TOPOLOGICAL CONSTANTS (source: {source})\")\n",
        "        print(\"=\" * 60)\n",
        "        print(\"\\n--- E8 Exceptional Lie Algebra ---\")\n",
        "        print(f\"  dim(E8)     = {self.dim_E8}\")\n",
        "        print(f\"  rank(E8)    = {self.rank_E8}\")\n",
        "        print(f\"  dim(E8xE8)  = {self.dim_E8xE8}\")\n",
        "        print(\"\\n--- G2 Holonomy Structure ---\")\n",
        "        print(f\"  dim(G2)     = {self.dim_G2}\")\n",
        "        print(f\"  dim(K7)     = {self.dim_K7}\")\n",
        "        print(\"\\n--- K7 Manifold Topology ---\")\n",
        "        print(f\"  b2(K7)      = {self.b2}\")\n",
        "        print(f\"  b3(K7)      = {self.b3}\")\n",
        "        print(f\"  H*          = {self.H_star}\")\n",
        "        print(f\"  p2          = {self.p2}\")\n",
        "        print(\"\\n--- Auxiliary Constants ---\")\n",
        "        print(f\"  dim(J3(O))  = {self.dim_J3O}\")\n",
        "        print(f\"  D_bulk      = {self.D_bulk}\")\n",
        "        print(f\"  Weyl        = {self.Weyl}\")\n",
        "        print(\"=\" * 60)\n",
        "\n",
        "# Initialize constants\n",
        "T = TopologicalConstants()\n",
        "T.display()\n",
        "\n",
        "# If giftpy available, show comparison data\n",
        "if GIFTPY_AVAILABLE:\n",
        "    print(f\"\\nPROVEN_RELATIONS from gift_core: {len(PROVEN_RELATIONS)} relations certified\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uvwaRoCot-tn"
      },
      "source": [
        "### 1.1 Verification of Topological Identities\n",
        "\n",
        "Several algebraic relations among these constants serve as consistency checks."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "7JkRQyu5t-tn",
        "outputId": "dfacf2f6-a69d-464b-ee2b-11d0c8fa55da"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Topological Consistency Verification\n",
            "--------------------------------------------------\n",
            "[PASS] H* = b2 + b3 + 1 = 21 + 77 + 1 = 99\n",
            "[PASS] dim(E8xE8) = 2 * dim(E8) = 2 * 248 = 496\n",
            "[PASS] p2 = dim(G2)/dim(K7) = 14/7 = 2\n",
            "[PASS] chi(K7) = 0 (G2 holonomy requirement)\n",
            "[PASS] Exceptional Chain: E6=6*13, E7=7*19, E8=8*31\n",
            "--------------------------------------------------\n",
            "All checks passed: True\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# TOPOLOGICAL CONSISTENCY CHECKS\n",
        "# =============================================================================\n",
        "\n",
        "print(\"Topological Consistency Verification\")\n",
        "print(\"-\" * 50)\n",
        "\n",
        "checks = []\n",
        "\n",
        "# Check 1: H* = b2 + b3 + 1\n",
        "c1 = T.H_star == T.b2 + T.b3 + 1\n",
        "checks.append(c1)\n",
        "print(f\"[{'PASS' if c1 else 'FAIL'}] H* = b2 + b3 + 1 = {T.b2} + {T.b3} + 1 = {T.H_star}\")\n",
        "\n",
        "# Check 2: dim(E8xE8) = 2 * dim(E8)\n",
        "c2 = T.dim_E8xE8 == 2 * T.dim_E8\n",
        "checks.append(c2)\n",
        "print(f\"[{'PASS' if c2 else 'FAIL'}] dim(E8xE8) = 2 * dim(E8) = 2 * {T.dim_E8} = {T.dim_E8xE8}\")\n",
        "\n",
        "# Check 3: p2 = dim(G2) / dim(K7)\n",
        "c3 = T.p2 == T.dim_G2 // T.dim_K7\n",
        "checks.append(c3)\n",
        "print(f\"[{'PASS' if c3 else 'FAIL'}] p2 = dim(G2)/dim(K7) = {T.dim_G2}/{T.dim_K7} = {T.p2}\")\n",
        "\n",
        "# Check 4: Euler characteristic chi(K7) = 0\n",
        "betti = [1, 0, T.b2, T.b3, T.b3, T.b2, 0, 1]\n",
        "chi = sum((-1)**i * betti[i] for i in range(8))\n",
        "c4 = chi == 0\n",
        "checks.append(c4)\n",
        "print(f\"[{'PASS' if c4 else 'FAIL'}] chi(K7) = {chi} (G2 holonomy requirement)\")\n",
        "\n",
        "# Check 5: Exceptional Chain E6-E7-E8\n",
        "primes = [13, 19, 31]  # prime(6), prime(8), prime(11)\n",
        "dims = [78, 133, 248]  # dim(E6), dim(E7), dim(E8)\n",
        "c5 = all(n * p == d for n, p, d in zip([6, 7, 8], primes, dims))\n",
        "checks.append(c5)\n",
        "print(f\"[{'PASS' if c5 else 'FAIL'}] Exceptional Chain: E6=6*13, E7=7*19, E8=8*31\")\n",
        "\n",
        "print(\"-\" * 50)\n",
        "print(f\"All checks passed: {all(checks)}\")"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 1.2 The G2 Calibrating 3-Form on K7\n",
        "\n",
        "The G2 structure on the 7-dimensional manifold K7 is defined by a calibrating 3-form $\\varphi$. In standard coordinates on $\\mathbb{R}^7$, this form has precisely 7 non-zero components corresponding to the octonion multiplication table. The following visualization represents this structure schematically."
      ],
      "metadata": {
        "id": "g5xpHAh5t-tn"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# =============================================================================\n",
        "# FIGURE 1: THE G2 3-FORM ON K7\n",
        "# =============================================================================\n",
        "\n",
        "def draw_g2_3form():\n",
        "    \"\"\"\n",
        "    Visualize the G2 calibrating 3-form structure.\n",
        "\n",
        "    The standard G2 3-form in R^7 is:\n",
        "    phi = e123 + e145 + e167 + e246 - e257 - e347 - e356\n",
        "\n",
        "    This corresponds to the Fano plane / octonion multiplication structure.\n",
        "    \"\"\"\n",
        "    fig, axes = plt.subplots(1, 2, figsize=(12, 5.5))\n",
        "\n",
        "    # --- Left panel: Fano plane representation ---\n",
        "    ax = axes[0]\n",
        "    ax.set_aspect('equal')\n",
        "    ax.set_xlim(-1.6, 1.6)\n",
        "    ax.set_ylim(-1.5, 1.7)\n",
        "    ax.axis('off')\n",
        "    ax.set_title(r'$G_2$ Structure: Fano Plane', fontsize=13, fontweight='bold', pad=15)\n",
        "\n",
        "    # Fano plane vertices (7 points)\n",
        "    # Outer triangle\n",
        "    r_out = 1.2\n",
        "    angles_out = [90, 210, 330]\n",
        "    outer = [(r_out * np.cos(np.radians(a)), r_out * np.sin(np.radians(a))) for a in angles_out]\n",
        "\n",
        "    # Inner triangle (inverted)\n",
        "    r_in = 0.6\n",
        "    angles_in = [270, 30, 150]\n",
        "    inner = [(r_in * np.cos(np.radians(a)), r_in * np.sin(np.radians(a))) for a in angles_in]\n",
        "\n",
        "    # Center\n",
        "    center = (0, 0)\n",
        "\n",
        "    # All 7 points with labels\n",
        "    points = [center] + outer + inner  # indices: 0=center, 1,2,3=outer, 4,5,6=inner\n",
        "    labels = ['1', '2', '3', '4', '5', '6', '7']\n",
        "\n",
        "    # Fano plane lines (each represents a term in phi)\n",
        "    # The 7 lines of the Fano plane\n",
        "    lines_indices = [\n",
        "        (1, 2, 3),  # outer triangle: e123\n",
        "        (1, 4, 5),  # e145\n",
        "        (1, 6, 0),  # e167 -> using center as 7\n",
        "        (2, 4, 6),  # e246\n",
        "        (2, 5, 0),  # e257\n",
        "        (3, 4, 0),  # e347\n",
        "        (3, 5, 6),  # e356\n",
        "    ]\n",
        "\n",
        "    # Redefine points more cleanly for Fano plane\n",
        "    # Standard Fano plane layout\n",
        "    pts = {\n",
        "        1: (0, 1.3),\n",
        "        2: (-1.1, -0.6),\n",
        "        3: (1.1, -0.6),\n",
        "        4: (0, 0.3),\n",
        "        5: (-0.55, -0.25),\n",
        "        6: (0.55, -0.25),\n",
        "        7: (0, -0.6)\n",
        "    }\n",
        "\n",
        "    # Draw lines first (behind points)\n",
        "    fano_lines = [\n",
        "        ([1, 2, 4], '+', GIFT_COLORS['E8']),      # e124 -> actually e123 etc\n",
        "        ([1, 3, 5], '+', GIFT_COLORS['E8']),\n",
        "        ([2, 3, 6], '+', GIFT_COLORS['E8']),\n",
        "        ([1, 6, 7], '+', GIFT_COLORS['G2']),\n",
        "        ([2, 5, 7], '-', GIFT_COLORS['K7']),\n",
        "        ([3, 4, 7], '-', GIFT_COLORS['K7']),\n",
        "        ([4, 5, 6], '+', GIFT_COLORS['G2']),\n",
        "    ]\n",
        "\n",
        "    # Draw outer triangle\n",
        "    triangle_pts = [pts[1], pts[2], pts[3], pts[1]]\n",
        "    xs, ys = zip(*triangle_pts)\n",
        "    ax.plot(xs, ys, color=GIFT_COLORS['E8'], linewidth=2, zorder=1)\n",
        "\n",
        "    # Draw inner triangle\n",
        "    inner_tri = [pts[4], pts[5], pts[6], pts[4]]\n",
        "    xs, ys = zip(*inner_tri)\n",
        "    ax.plot(xs, ys, color=GIFT_COLORS['G2'], linewidth=2, zorder=1)\n",
        "\n",
        "    # Draw medians to center\n",
        "    for i in [1, 2, 3]:\n",
        "        ax.plot([pts[i][0], pts[7][0]], [pts[i][1], pts[7][1]],\n",
        "                color=GIFT_COLORS['K7'], linewidth=1.5, zorder=1)\n",
        "\n",
        "    # Draw inscribed circle\n",
        "    circle = Circle((0, 0.1), 0.55, fill=False, color=GIFT_COLORS['gold'],\n",
        "                   linewidth=2, linestyle='--', zorder=1)\n",
        "    ax.add_patch(circle)\n",
        "\n",
        "    # Draw points\n",
        "    for idx, (x, y) in pts.items():\n",
        "        circle = Circle((x, y), 0.12, color='white', ec=GIFT_COLORS['E8'],\n",
        "                        linewidth=2, zorder=3)\n",
        "        ax.add_patch(circle)\n",
        "        ax.text(x, y, str(idx), ha='center', va='center', fontsize=11,\n",
        "               fontweight='bold', zorder=4)\n",
        "\n",
        "    # Legend text\n",
        "    ax.text(0, -1.35, r'7 vertices $\\leftrightarrow$ 7 dimensions of $K_7$',\n",
        "           ha='center', fontsize=10, style='italic')\n",
        "    ax.text(0, -1.55, r'7 lines $\\leftrightarrow$ 7 terms in $\\varphi$',\n",
        "           ha='center', fontsize=10, style='italic')\n",
        "\n",
        "    # --- Right panel: 3-form components ---\n",
        "    ax = axes[1]\n",
        "    ax.set_xlim(0, 10)\n",
        "    ax.set_ylim(0, 10)\n",
        "    ax.axis('off')\n",
        "    ax.set_title(r'The Calibrating 3-Form $\\varphi$', fontsize=13, fontweight='bold', pad=15)\n",
        "\n",
        "    # Display the formula\n",
        "    formula_parts = [\n",
        "        (r'$\\varphi = $', 0.5, 8.5, 'black', 12),\n",
        "        (r'$e^{123}$', 1.8, 8.5, GIFT_COLORS['E8'], 12),\n",
        "        (r'$+\\, e^{145}$', 3.0, 8.5, GIFT_COLORS['E8'], 12),\n",
        "        (r'$+\\, e^{167}$', 4.5, 8.5, GIFT_COLORS['G2'], 12),\n",
        "        (r'$+\\, e^{246}$', 6.0, 8.5, GIFT_COLORS['G2'], 12),\n",
        "        (r'$-\\, e^{257}$', 7.5, 8.5, GIFT_COLORS['K7'], 12),\n",
        "        (r'$-\\, e^{347}$', 3.5, 7.5, GIFT_COLORS['K7'], 12),\n",
        "        (r'$-\\, e^{356}$', 5.5, 7.5, GIFT_COLORS['K7'], 12),\n",
        "    ]\n",
        "\n",
        "    for text, x, y, color, size in formula_parts:\n",
        "        ax.text(x, y, text, fontsize=size, color=color, fontweight='bold')\n",
        "\n",
        "    # Properties box\n",
        "    props = [\n",
        "        (r'$\\bullet$ 7 non-zero components', 5, 6.0),\n",
        "        (r'$\\bullet$ $\\|\\varphi\\|^2 = 7 = \\dim(K_7)$', 5, 5.3),\n",
        "        (r'$\\bullet$ Stabilizer $= G_2 \\subset GL(7)$', 5, 4.6),\n",
        "        (r'$\\bullet$ Torsion-free: $d\\varphi = 0$', 5, 3.9),\n",
        "    ]\n",
        "\n",
        "    rect = FancyBboxPatch((0.8, 3.3), 8.4, 3.2, boxstyle=\"round,pad=0.1\",\n",
        "                          facecolor=GIFT_COLORS['light'], edgecolor=GIFT_COLORS['E8'],\n",
        "                          linewidth=1.5, zorder=1)\n",
        "    ax.add_patch(rect)\n",
        "\n",
        "    for text, x, y in props:\n",
        "        ax.text(x, y, text, fontsize=10, ha='center', va='center')\n",
        "\n",
        "    # Hodge dual\n",
        "    ax.text(5, 2.2, r'Hodge dual: $\\psi = \\star\\varphi$ (4-form, 35 components)',\n",
        "           fontsize=10, ha='center', style='italic', color=GIFT_COLORS['E8'])\n",
        "\n",
        "    # Connection to physics\n",
        "    ax.text(5, 1.0, r'$G_2$ holonomy $\\Rightarrow$ Ricci-flat $\\Rightarrow$ $\\mathcal{N}=1$ SUSY in 4D',\n",
        "           fontsize=10, ha='center', color=GIFT_COLORS['G2'], fontweight='bold')\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.savefig('fig1_g2_3form.pdf', bbox_inches='tight')\n",
        "    plt.savefig('fig1_g2_3form.png', bbox_inches='tight', dpi=300)\n",
        "    plt.show()\n",
        "    print(\"Figure 1 saved: fig1_g2_3form.pdf, fig1_g2_3form.png\")\n",
        "\n",
        "draw_g2_3form()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 563
        },
        "id": "tL5d889Gt-to",
        "outputId": "8bc4c619-b0fe-4775-b064-6f71f3635186"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 1800x825 with 2 Axes>"
            ],
            "image/png": "[encoded data, 146512 characters]\n"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Figure 1 saved: fig1_g2_3form.pdf, fig1_g2_3form.png\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# =============================================================================\n",
        "# FIGURE 2: K7 TWISTED CONNECTED SUM CONSTRUCTION\n",
        "# =============================================================================\n",
        "\n",
        "def draw_k7_construction():\n",
        "    \"\"\"\n",
        "    Visualize the Twisted Connected Sum construction of K7.\n",
        "\n",
        "    K7 = M1^T cup_{K3 x S1} M2^T\n",
        "\n",
        "    where M1, M2 are asymptotically cylindrical G2 manifolds.\n",
        "    \"\"\"\n",
        "    fig, axes = plt.subplots(1, 2, figsize=(13, 5))\n",
        "\n",
        "    # --- Left panel: TCS schematic ---\n",
        "    ax = axes[0]\n",
        "    ax.set_xlim(-0.5, 10.5)\n",
        "    ax.set_ylim(-1, 7)\n",
        "    ax.axis('off')\n",
        "    ax.set_title(r'Twisted Connected Sum Construction of $K_7$',\n",
        "                fontsize=13, fontweight='bold', pad=15)\n",
        "\n",
        "    # M1 region (left blob)\n",
        "    from matplotlib.patches import Ellipse\n",
        "\n",
        "    # Draw M1 as elongated shape\n",
        "    m1_ellipse = Ellipse((2, 3), 3.5, 4, angle=0,\n",
        "                         facecolor='#E3F2FD', edgecolor=GIFT_COLORS['E8'],\n",
        "                         linewidth=2, alpha=0.8)\n",
        "    ax.add_patch(m1_ellipse)\n",
        "    ax.text(2, 3, r'$M_1^T$', fontsize=14, ha='center', va='center', fontweight='bold')\n",
        "    ax.text(2, 1.5, r'$b_2 = 11$', fontsize=10, ha='center', color=GIFT_COLORS['E8'])\n",
        "    ax.text(2, 1.0, r'$b_3 = 40$', fontsize=10, ha='center', color=GIFT_COLORS['E8'])\n",
        "\n",
        "    # M2 region (right blob)\n",
        "    m2_ellipse = Ellipse((8, 3), 3.5, 4, angle=0,\n",
        "                         facecolor='#E8F5E9', edgecolor=GIFT_COLORS['G2'],\n",
        "                         linewidth=2, alpha=0.8)\n",
        "    ax.add_patch(m2_ellipse)\n",
        "    ax.text(8, 3, r'$M_2^T$', fontsize=14, ha='center', va='center', fontweight='bold')\n",
        "    ax.text(8, 1.5, r'$b_2 = 10$', fontsize=10, ha='center', color=GIFT_COLORS['G2'])\n",
        "    ax.text(8, 1.0, r'$b_3 = 37$', fontsize=10, ha='center', color=GIFT_COLORS['G2'])\n",
        "\n",
        "    # Gluing region (neck)\n",
        "    neck_x = [3.7, 4.3, 4.3, 5.7, 5.7, 6.3, 6.3, 5.7, 5.7, 4.3, 4.3, 3.7]\n",
        "    neck_y = [3.5, 3.8, 4.5, 4.5, 3.8, 3.5, 2.5, 2.2, 1.5, 1.5, 2.2, 2.5]\n",
        "    ax.fill(neck_x, neck_y, color=GIFT_COLORS['gold'], alpha=0.4, edgecolor=GIFT_COLORS['K7'], linewidth=2)\n",
        "    ax.text(5, 3, r'$K3 \\times S^1$', fontsize=10, ha='center', va='center', fontweight='bold')\n",
        "\n",
        "    # Twist arrow\n",
        "    ax.annotate('', xy=(5.8, 4.8), xytext=(4.2, 4.8),\n",
        "                arrowprops=dict(arrowstyle='->', color=GIFT_COLORS['K7'], lw=2))\n",
        "    ax.text(5, 5.3, r'twist $\\phi$', fontsize=10, ha='center', color=GIFT_COLORS['K7'])\n",
        "\n",
        "    # Result equation\n",
        "    ax.text(5, -0.3, r'$K_7 = M_1^T \\cup_\\phi M_2^T$', fontsize=12, ha='center', fontweight='bold')\n",
        "    ax.text(5, -0.8, r'Compact $G_2$-holonomy 7-manifold', fontsize=10, ha='center', style='italic')\n",
        "\n",
        "    # --- Right panel: Betti numbers and cohomology ---\n",
        "    ax = axes[1]\n",
        "    ax.set_xlim(0, 10)\n",
        "    ax.set_ylim(0, 10)\n",
        "    ax.axis('off')\n",
        "    ax.set_title(r'Cohomology of $K_7$ (Mayer-Vietoris)',\n",
        "                fontsize=13, fontweight='bold', pad=15)\n",
        "\n",
        "    # Betti number computation - using plain text alignment instead of \\phantom\n",
        "    y_start = 8.5\n",
        "    dy = 0.7\n",
        "\n",
        "    computations = [\n",
        "        (r'$b_2(K_7) = b_2(M_1) + b_2(M_2)$', GIFT_COLORS['E8'], 5),\n",
        "        (r'$= 11 + 10 = \\mathbf{21}$', GIFT_COLORS['E8'], 6.2),\n",
        "        ('', 'black', 5),\n",
        "        (r'$b_3(K_7) = b_3(M_1) + b_3(M_2)$', GIFT_COLORS['G2'], 5),\n",
        "        (r'$= 40 + 37 = \\mathbf{77}$', GIFT_COLORS['G2'], 6.2),\n",
        "        ('', 'black', 5),\n",
        "        (r'$H^* = b_2 + b_3 + 1 = \\mathbf{99}$', GIFT_COLORS['K7'], 5),\n",
        "    ]\n",
        "\n",
        "    for i, (text, color, x_pos) in enumerate(computations):\n",
        "        ax.text(x_pos, y_start - i * dy, text, fontsize=11, ha='center', color=color)\n",
        "\n",
        "    # Euler characteristic box\n",
        "    rect = FancyBboxPatch((1, 2.8), 8, 1.8, boxstyle=\"round,pad=0.1\",\n",
        "                          facecolor=GIFT_COLORS['light'], edgecolor=GIFT_COLORS['E8'],\n",
        "                          linewidth=1.5)\n",
        "    ax.add_patch(rect)\n",
        "    ax.text(5, 4.0, r'Euler characteristic:', fontsize=10, ha='center', fontweight='bold')\n",
        "    ax.text(5, 3.3, r'$\\chi(K_7) = 1 - 0 + 21 - 77 + 77 - 21 + 0 - 1 = 0$',\n",
        "           fontsize=10, ha='center')\n",
        "\n",
        "    # Physical interpretation\n",
        "    ax.text(5, 1.8, r'$b_2 = 21$ harmonic 2-forms $\\rightarrow$ gauge moduli',\n",
        "           fontsize=9, ha='center', style='italic')\n",
        "    ax.text(5, 1.2, r'$b_3 = 77$ harmonic 3-forms $\\rightarrow$ matter modes',\n",
        "           fontsize=9, ha='center', style='italic')\n",
        "    ax.text(5, 0.6, r'$\\chi = 0$ required for $G_2$ holonomy',\n",
        "           fontsize=9, ha='center', style='italic', color=GIFT_COLORS['G2'])\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.savefig('fig2_k7_construction.pdf', bbox_inches='tight')\n",
        "    plt.savefig('fig2_k7_construction.png', bbox_inches='tight', dpi=300)\n",
        "    plt.show()\n",
        "    print(\"Figure 2 saved: fig2_k7_construction.pdf, fig2_k7_construction.png\")\n",
        "\n",
        "draw_k7_construction()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 457
        },
        "id": "pxl585OZt-to",
        "outputId": "fc3f4b7a-ca6d-4728-c56c-58301ac2e4f6"
      },
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 1950x750 with 2 Axes>"
            ],
            "image/png": "[encoded data, 152804 characters]\n"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Figure 2 saved: fig2_k7_construction.pdf, fig2_k7_construction.png\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zRkdlzgFt-tp"
      },
      "source": [
        "---\n",
        "\n",
        "## 2. Foundational Relations\n",
        "\n",
        "Having established the 10 structural integers, we now derive the 18 dimensionless relations that follow from algebraic combinations of these invariants. The first four relations (N_gen, τ, κ_T, det(g)) are structural quantities without direct experimental comparison; the remaining 14 are testable predictions, of which 13 are compared to current experimental values.\n",
        "\n",
        "**The 18 Dimensionless Derivations:**\n",
        "\n",
        "| Sector | Count | Relations |\n",
        "|--------|-------|-----------|\n",
        "| Foundational | 4 | N_gen, τ, κ_T, det(g) |\n",
        "| Gauge | 2 | sin²θ_W, α_s |\n",
        "| Lepton | 3 | Q_Koide, m_τ/m_e, m_μ/m_e |\n",
        "| Quark | 1 | m_s/m_d |\n",
        "| Neutrino | 4 | δ_CP, θ₁₃, θ₂₃, θ₁₂ |\n",
        "| Cosmological | 4 | λ_H, Ω_DE, n_s, α⁻¹ |\n",
        "| **Total** | **18** | **(13 with experimental comparison)** |\n",
        "\n",
        "The categorization \"23 predictions = 10 structural + 13 dimensionless\" in the main paper reflects this breakdown.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "id": "4W-ay-Zst-tq"
      },
      "outputs": [],
      "source": [
        "# =============================================================================\n",
        "# PREDICTION DATA STRUCTURE\n",
        "# =============================================================================\n",
        "\n",
        "@dataclass\n",
        "class Prediction:\n",
        "    \"\"\"A single GIFT prediction with experimental comparison.\"\"\"\n",
        "    name: str\n",
        "    symbol: str\n",
        "    formula: str\n",
        "    value: float\n",
        "    exact: Optional[Fraction] = None\n",
        "    experimental: Optional[float] = None\n",
        "    uncertainty: Optional[float] = None\n",
        "    unit: str = \"\"\n",
        "    status: str = \"PROVEN\"\n",
        "\n",
        "    @property\n",
        "    def deviation(self) -> Optional[float]:\n",
        "        \"\"\"Percentage deviation from experiment.\"\"\"\n",
        "        if self.experimental is None or self.experimental == 0:\n",
        "            return None\n",
        "        return abs(self.value - self.experimental) / abs(self.experimental) * 100\n",
        "\n",
        "    def display(self):\n",
        "        \"\"\"Display prediction details.\"\"\"\n",
        "        print(f\"\\n{self.name} ({self.symbol})\")\n",
        "        print(\"-\" * 40)\n",
        "        print(f\"  Formula: {self.formula}\")\n",
        "        if self.exact:\n",
        "            print(f\"  Exact:   {self.exact} = {float(self.exact):.6f}\")\n",
        "        else:\n",
        "            print(f\"  Value:   {self.value:.6f}{self.unit}\")\n",
        "        if self.experimental is not None:\n",
        "            unc = f\" +/- {self.uncertainty}\" if self.uncertainty else \"\"\n",
        "            print(f\"  Exp:     {self.experimental}{unc}{self.unit}\")\n",
        "            print(f\"  Dev:     {self.deviation:.3f}%\")\n",
        "        print(f\"  Status:  {self.status}\")\n",
        "\n",
        "# Storage for all predictions\n",
        "predictions: List[Prediction] = []"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "IwJaGkJot-tq",
        "outputId": "4069fc23-ad48-41b1-f3e3-016a5e45cf10"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 1: Generation Number\n",
            "============================================================\n",
            "\n",
            "Derivation (Atiyah-Singer Index Theorem):\n",
            "  (rank(E8) + N_gen) * b2 = N_gen * b3\n",
            "  (8 + N_gen) * 21 = N_gen * 77\n",
            "  8 * 21 = N_gen * (77 - 21)\n",
            "  168 = N_gen * 56\n",
            "  N_gen = 168 / 56 = 3\n",
            "\n",
            "Verification: (8 + 3) * 21 = 231, 3 * 77 = 231\n",
            "LHS = RHS: True\n",
            "\n",
            "Generation Number (N_gen)\n",
            "----------------------------------------\n",
            "  Formula: rank(E8) * b2 / (b3 - b2)\n",
            "  Exact:   3 = 3.000000\n",
            "  Exp:     3\n",
            "  Dev:     0.000%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 1: GENERATION NUMBER N_gen = 3\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 1: Generation Number\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# Derivation via Atiyah-Singer index constraint\n",
        "# (rank(E8) + N_gen) * b2 = N_gen * b3\n",
        "# Solving for N_gen:\n",
        "# rank(E8) * b2 = N_gen * (b3 - b2)\n",
        "# N_gen = rank(E8) * b2 / (b3 - b2)\n",
        "\n",
        "N_gen = T.rank_E8 * T.b2 // (T.b3 - T.b2)\n",
        "\n",
        "print(\"\\nDerivation (Atiyah-Singer Index Theorem):\")\n",
        "print(f\"  (rank(E8) + N_gen) * b2 = N_gen * b3\")\n",
        "print(f\"  ({T.rank_E8} + N_gen) * {T.b2} = N_gen * {T.b3}\")\n",
        "print(f\"  {T.rank_E8} * {T.b2} = N_gen * ({T.b3} - {T.b2})\")\n",
        "print(f\"  {T.rank_E8 * T.b2} = N_gen * {T.b3 - T.b2}\")\n",
        "print(f\"  N_gen = {T.rank_E8 * T.b2} / {T.b3 - T.b2} = {N_gen}\")\n",
        "\n",
        "# Verification\n",
        "lhs = (T.rank_E8 + N_gen) * T.b2\n",
        "rhs = N_gen * T.b3\n",
        "print(f\"\\nVerification: ({T.rank_E8} + {N_gen}) * {T.b2} = {lhs}, {N_gen} * {T.b3} = {rhs}\")\n",
        "print(f\"LHS = RHS: {lhs == rhs}\")\n",
        "\n",
        "pred_Ngen = Prediction(\n",
        "    name=\"Generation Number\",\n",
        "    symbol=\"N_gen\",\n",
        "    formula=\"rank(E8) * b2 / (b3 - b2)\",\n",
        "    value=N_gen,\n",
        "    exact=Fraction(3, 1),\n",
        "    experimental=3,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_Ngen.display()\n",
        "predictions.append(pred_Ngen)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "r7Sbuvjut-tr",
        "outputId": "afc0bb7d-0cf4-45cf-9958-754530c96bbe"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 2: Hierarchy Parameter\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  tau = dim(E8xE8) * b2 / (dim(J3(O)) * H*)\n",
            "      = 496 * 21 / (27 * 99)\n",
            "      = 10416 / 2673\n",
            "      = 3472/891\n",
            "\n",
            "Prime factorization:\n",
            "  Numerator:   3472 = 2^4 * 7 * 31\n",
            "  Denominator: 891 = 3^4 * 11\n",
            "\n",
            "Hierarchy Parameter (tau)\n",
            "----------------------------------------\n",
            "  Formula: dim(E8xE8) * b2 / (dim(J3(O)) * H*)\n",
            "  Exact:   3472/891 = 3.896745\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 2: HIERARCHY PARAMETER tau\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 2: Hierarchy Parameter\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# tau = dim(E8xE8) * b2 / (dim(J3(O)) * H*)\n",
        "tau_num = T.dim_E8xE8 * T.b2\n",
        "tau_den = T.dim_J3O * T.H_star\n",
        "tau = Fraction(tau_num, tau_den)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  tau = dim(E8xE8) * b2 / (dim(J3(O)) * H*)\")\n",
        "print(f\"      = {T.dim_E8xE8} * {T.b2} / ({T.dim_J3O} * {T.H_star})\")\n",
        "print(f\"      = {tau_num} / {tau_den}\")\n",
        "print(f\"      = {tau}\")\n",
        "\n",
        "# Prime factorization\n",
        "print(f\"\\nPrime factorization:\")\n",
        "print(f\"  Numerator:   {tau.numerator} = 2^4 * 7 * 31\")\n",
        "print(f\"  Denominator: {tau.denominator} = 3^4 * 11\")\n",
        "\n",
        "pred_tau = Prediction(\n",
        "    name=\"Hierarchy Parameter\",\n",
        "    symbol=\"tau\",\n",
        "    formula=\"dim(E8xE8) * b2 / (dim(J3(O)) * H*)\",\n",
        "    value=float(tau),\n",
        "    exact=tau,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_tau.display()\n",
        "predictions.append(pred_tau)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "U9zk-M2Rt-tr",
        "outputId": "6dce6c0c-e09a-4f2b-f655-74cba88b943b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 3: Torsion Magnitude\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  kappa_T = 1 / (b3 - dim(G2) - p2)\n",
            "          = 1 / (77 - 14 - 2)\n",
            "          = 1 / 61\n",
            "          = 1/61\n",
            "\n",
            "Geometric interpretation of 61:\n",
            "  61 = dim(F4) + N_gen^2 = 52 + 9\n",
            "\n",
            "Torsion Magnitude (kappa_T)\n",
            "----------------------------------------\n",
            "  Formula: 1 / (b3 - dim(G2) - p2)\n",
            "  Exact:   1/61 = 0.016393\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 3: TORSION MAGNITUDE kappa_T = 1/61\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 3: Torsion Magnitude\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# kappa_T = 1 / (b3 - dim(G2) - p2)\n",
        "kappa_den = T.b3 - T.dim_G2 - T.p2\n",
        "kappa_T = Fraction(1, kappa_den)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  kappa_T = 1 / (b3 - dim(G2) - p2)\")\n",
        "print(f\"          = 1 / ({T.b3} - {T.dim_G2} - {T.p2})\")\n",
        "print(f\"          = 1 / {kappa_den}\")\n",
        "print(f\"          = {kappa_T}\")\n",
        "\n",
        "# Decomposition of 61\n",
        "print(f\"\\nGeometric interpretation of 61:\")\n",
        "print(f\"  61 = dim(F4) + N_gen^2 = 52 + 9\")\n",
        "\n",
        "pred_kappa = Prediction(\n",
        "    name=\"Torsion Magnitude\",\n",
        "    symbol=\"kappa_T\",\n",
        "    formula=\"1 / (b3 - dim(G2) - p2)\",\n",
        "    value=float(kappa_T),\n",
        "    exact=kappa_T,\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_kappa.display()\n",
        "predictions.append(pred_kappa)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "hfjKvU5gt-tr",
        "outputId": "e177e9e1-4d3a-41fb-dd42-cb2f84858053"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 4: Metric Determinant\n",
            "============================================================\n",
            "\n",
            "Derivation (Method 1):\n",
            "  det(g) = p2 + 1/(b2 + dim(G2) - N_gen)\n",
            "         = 2 + 1/(21 + 14 - 3)\n",
            "         = 2 + 1/32\n",
            "         = 65/32\n",
            "\n",
            "Derivation (Method 2):\n",
            "  det(g) = Weyl * (rank(E8) + Weyl) / 2^Weyl\n",
            "         = 5 * (8 + 5) / 2^5\n",
            "         = 5 * 13 / 32\n",
            "         = 65/32\n",
            "\n",
            "Consistency: 65/32 = 65/32: True\n",
            "\n",
            "Metric Determinant (det(g))\n",
            "----------------------------------------\n",
            "  Formula: p2 + 1/(b2 + dim(G2) - N_gen)\n",
            "  Exact:   65/32 = 2.031250\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 4: METRIC DETERMINANT det(g) = 65/32\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 4: Metric Determinant\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# det(g) = p2 + 1/(b2 + dim(G2) - N_gen)\n",
        "det_frac_den = T.b2 + T.dim_G2 - N_gen\n",
        "det_g = Fraction(T.p2 * det_frac_den + 1, det_frac_den)\n",
        "\n",
        "print(\"\\nDerivation (Method 1):\")\n",
        "print(f\"  det(g) = p2 + 1/(b2 + dim(G2) - N_gen)\")\n",
        "print(f\"         = {T.p2} + 1/({T.b2} + {T.dim_G2} - {N_gen})\")\n",
        "print(f\"         = {T.p2} + 1/{det_frac_den}\")\n",
        "print(f\"         = {det_g}\")\n",
        "\n",
        "# Alternative derivation\n",
        "det_g_alt = Fraction(T.Weyl * (T.rank_E8 + T.Weyl), 2**T.Weyl)\n",
        "print(\"\\nDerivation (Method 2):\")\n",
        "print(f\"  det(g) = Weyl * (rank(E8) + Weyl) / 2^Weyl\")\n",
        "print(f\"         = {T.Weyl} * ({T.rank_E8} + {T.Weyl}) / 2^{T.Weyl}\")\n",
        "print(f\"         = {T.Weyl} * {T.rank_E8 + T.Weyl} / {2**T.Weyl}\")\n",
        "print(f\"         = {det_g_alt}\")\n",
        "\n",
        "print(f\"\\nConsistency: {det_g} = {det_g_alt}: {det_g == det_g_alt}\")\n",
        "\n",
        "pred_detg = Prediction(\n",
        "    name=\"Metric Determinant\",\n",
        "    symbol=\"det(g)\",\n",
        "    formula=\"p2 + 1/(b2 + dim(G2) - N_gen)\",\n",
        "    value=float(det_g),\n",
        "    exact=det_g,\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_detg.display()\n",
        "predictions.append(pred_detg)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "O5jfdAHnt-tr"
      },
      "source": [
        "---\n",
        "\n",
        "## 3. Gauge Sector\n",
        "\n",
        "The gauge sector predictions concern electroweak mixing and the strong coupling constant."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "1sAxg10bt-tr",
        "outputId": "b3d5c5c6-a9fd-413b-eff3-4655cd1c853b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 5: Weinberg Angle\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  sin^2(theta_W) = b2 / (b3 + dim(G2))\n",
            "                 = 21 / (77 + 14)\n",
            "                 = 21 / 91\n",
            "                 = 3/13\n",
            "\n",
            "Weinberg Angle (sin^2(theta_W))\n",
            "----------------------------------------\n",
            "  Formula: b2 / (b3 + dim(G2))\n",
            "  Exact:   3/13 = 0.230769\n",
            "  Exp:     0.23122 +/- 4e-05\n",
            "  Dev:     0.195%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 5: WEINBERG ANGLE sin^2(theta_W) = 3/13\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 5: Weinberg Angle\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# sin^2(theta_W) = b2 / (b3 + dim(G2))\n",
        "sin2_num = T.b2\n",
        "sin2_den = T.b3 + T.dim_G2\n",
        "sin2_theta_W = Fraction(sin2_num, sin2_den)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  sin^2(theta_W) = b2 / (b3 + dim(G2))\")\n",
        "print(f\"                 = {T.b2} / ({T.b3} + {T.dim_G2})\")\n",
        "print(f\"                 = {sin2_num} / {sin2_den}\")\n",
        "print(f\"                 = {sin2_theta_W}\")\n",
        "\n",
        "# Experimental comparison\n",
        "sin2_exp = 0.23122\n",
        "sin2_unc = 0.00004\n",
        "\n",
        "pred_sin2 = Prediction(\n",
        "    name=\"Weinberg Angle\",\n",
        "    symbol=\"sin^2(theta_W)\",\n",
        "    formula=\"b2 / (b3 + dim(G2))\",\n",
        "    value=float(sin2_theta_W),\n",
        "    exact=sin2_theta_W,\n",
        "    experimental=sin2_exp,\n",
        "    uncertainty=sin2_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_sin2.display()\n",
        "predictions.append(pred_sin2)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3juWi6Rbt-ts",
        "outputId": "effb7510-3d38-4037-9eed-0e3ae31ab9b1"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 6: Strong Coupling Constant\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  alpha_s(M_Z) = sqrt(2) / (dim(G2) - p2)\n",
            "               = sqrt(2) / (14 - 2)\n",
            "               = sqrt(2) / 12\n",
            "               = 0.117851\n",
            "\n",
            "Geometric origin:\n",
            "  sqrt(2) = E8 root length\n",
            "  12 = effective gauge degrees of freedom\n",
            "\n",
            "Strong Coupling (alpha_s(M_Z))\n",
            "----------------------------------------\n",
            "  Formula: sqrt(2) / (dim(G2) - p2)\n",
            "  Value:   0.117851\n",
            "  Exp:     0.1179 +/- 0.0009\n",
            "  Dev:     0.041%\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 6: STRONG COUPLING alpha_s = sqrt(2)/12\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 6: Strong Coupling Constant\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# alpha_s = sqrt(2) / (dim(G2) - p2)\n",
        "alpha_s_den = T.dim_G2 - T.p2\n",
        "alpha_s = np.sqrt(2) / alpha_s_den\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  alpha_s(M_Z) = sqrt(2) / (dim(G2) - p2)\")\n",
        "print(f\"               = sqrt(2) / ({T.dim_G2} - {T.p2})\")\n",
        "print(f\"               = sqrt(2) / {alpha_s_den}\")\n",
        "print(f\"               = {alpha_s:.6f}\")\n",
        "\n",
        "print(\"\\nGeometric origin:\")\n",
        "print(f\"  sqrt(2) = E8 root length\")\n",
        "print(f\"  12 = effective gauge degrees of freedom\")\n",
        "\n",
        "# Experimental comparison\n",
        "alpha_s_exp = 0.1179\n",
        "alpha_s_unc = 0.0009\n",
        "\n",
        "pred_alpha_s = Prediction(\n",
        "    name=\"Strong Coupling\",\n",
        "    symbol=\"alpha_s(M_Z)\",\n",
        "    formula=\"sqrt(2) / (dim(G2) - p2)\",\n",
        "    value=alpha_s,\n",
        "    experimental=alpha_s_exp,\n",
        "    uncertainty=alpha_s_unc,\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_alpha_s.display()\n",
        "predictions.append(pred_alpha_s)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "L-bUgWr0t-ts"
      },
      "source": [
        "---\n",
        "\n",
        "## 4. Lepton Sector\n",
        "\n",
        "The lepton sector predictions address the long-standing Koide relation and charged lepton mass ratios."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "gJ5oqsBEt-ts",
        "outputId": "383b5dd8-aeb8-4cfb-e3e4-fb8d7551eeef"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 7: Koide Parameter\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  Q_Koide = dim(G2) / b2\n",
            "          = 14 / 21\n",
            "          = 2/3\n",
            "\n",
            "Physical definition (Koide, 1981):\n",
            "  Q = (m_e + m_mu + m_tau) / (sqrt(m_e) + sqrt(m_mu) + sqrt(m_tau))^2\n",
            "\n",
            "Koide Parameter (Q_Koide)\n",
            "----------------------------------------\n",
            "  Formula: dim(G2) / b2\n",
            "  Exact:   2/3 = 0.666667\n",
            "  Exp:     0.666661 +/- 7e-06\n",
            "  Dev:     0.001%\n",
            "  Status:  PROVEN\n",
            "\n",
            "Remark: This provides a geometric explanation for a relation\n",
            "that has remained unexplained for over four decades.\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 7: KOIDE PARAMETER Q = 2/3\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 7: Koide Parameter\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# Q_Koide = dim(G2) / b2\n",
        "Q_Koide = Fraction(T.dim_G2, T.b2)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  Q_Koide = dim(G2) / b2\")\n",
        "print(f\"          = {T.dim_G2} / {T.b2}\")\n",
        "print(f\"          = {Q_Koide}\")\n",
        "\n",
        "print(\"\\nPhysical definition (Koide, 1981):\")\n",
        "print(\"  Q = (m_e + m_mu + m_tau) / (sqrt(m_e) + sqrt(m_mu) + sqrt(m_tau))^2\")\n",
        "\n",
        "# Experimental comparison\n",
        "Q_exp = 0.666661\n",
        "Q_unc = 0.000007\n",
        "\n",
        "pred_Q = Prediction(\n",
        "    name=\"Koide Parameter\",\n",
        "    symbol=\"Q_Koide\",\n",
        "    formula=\"dim(G2) / b2\",\n",
        "    value=float(Q_Koide),\n",
        "    exact=Q_Koide,\n",
        "    experimental=Q_exp,\n",
        "    uncertainty=Q_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_Q.display()\n",
        "predictions.append(pred_Q)\n",
        "\n",
        "print(\"\\nRemark: This provides a geometric explanation for a relation\")\n",
        "print(\"that has remained unexplained for over four decades.\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "RpK3QsV0t-ts",
        "outputId": "3dade5ab-5d48-4373-a823-e40c810aa8d5"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 8: Tau-Electron Mass Ratio\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  m_tau/m_e = dim(K7) + 10*dim(E8) + 10*H*\n",
            "            = 7 + 10*248 + 10*99\n",
            "            = 7 + 2480 + 990\n",
            "            = 3477\n",
            "\n",
            "Prime factorization:\n",
            "  3477 = 3 * 19 * 61\n",
            "       = N_gen * prime(rank(E8)) * kappa_T^(-1)\n",
            "       = 3 * 19 * 61\n",
            "\n",
            "Tau-Electron Mass Ratio (m_tau/m_e)\n",
            "----------------------------------------\n",
            "  Formula: dim(K7) + 10*dim(E8) + 10*H*\n",
            "  Exact:   3477 = 3477.000000\n",
            "  Exp:     3477.15 +/- 0.05\n",
            "  Dev:     0.004%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 8: TAU-ELECTRON MASS RATIO m_tau/m_e = 3477\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 8: Tau-Electron Mass Ratio\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# m_tau/m_e = dim(K7) + 10*dim(E8) + 10*H*\n",
        "m_tau_m_e = T.dim_K7 + 10 * T.dim_E8 + 10 * T.H_star\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  m_tau/m_e = dim(K7) + 10*dim(E8) + 10*H*\")\n",
        "print(f\"            = {T.dim_K7} + 10*{T.dim_E8} + 10*{T.H_star}\")\n",
        "print(f\"            = {T.dim_K7} + {10*T.dim_E8} + {10*T.H_star}\")\n",
        "print(f\"            = {m_tau_m_e}\")\n",
        "\n",
        "# Prime factorization\n",
        "print(\"\\nPrime factorization:\")\n",
        "print(f\"  3477 = 3 * 19 * 61\")\n",
        "print(f\"       = N_gen * prime(rank(E8)) * kappa_T^(-1)\")\n",
        "print(f\"       = {N_gen} * {19} * {61}\")\n",
        "\n",
        "# Experimental comparison\n",
        "m_tau_m_e_exp = 3477.15\n",
        "m_tau_m_e_unc = 0.05\n",
        "\n",
        "pred_mtau = Prediction(\n",
        "    name=\"Tau-Electron Mass Ratio\",\n",
        "    symbol=\"m_tau/m_e\",\n",
        "    formula=\"dim(K7) + 10*dim(E8) + 10*H*\",\n",
        "    value=float(m_tau_m_e),\n",
        "    exact=Fraction(m_tau_m_e, 1),\n",
        "    experimental=m_tau_m_e_exp,\n",
        "    uncertainty=m_tau_m_e_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_mtau.display()\n",
        "predictions.append(pred_mtau)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "XO6btb5mt-ts",
        "outputId": "fe09d17f-e1dd-4308-cb80-b9a5ae5536d9"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 9: Muon-Electron Mass Ratio\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  m_mu/m_e = dim(J3(O))^phi\n",
            "           = 27^((1+sqrt(5))/2)\n",
            "           = 27^1.618034\n",
            "           = 207.0119\n",
            "\n",
            "Geometric origin:\n",
            "  27 = dim(J3(O)) = dimension of exceptional Jordan algebra\n",
            "  phi = golden ratio from McKay correspondence\n",
            "\n",
            "Muon-Electron Mass Ratio (m_mu/m_e)\n",
            "----------------------------------------\n",
            "  Formula: dim(J3(O))^phi\n",
            "  Value:   207.011857\n",
            "  Exp:     206.768\n",
            "  Dev:     0.118%\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 9: MUON-ELECTRON MASS RATIO m_mu/m_e = 27^phi\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 9: Muon-Electron Mass Ratio\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# m_mu/m_e = dim(J3(O))^phi where phi = golden ratio\n",
        "m_mu_m_e = T.dim_J3O ** PHI\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  m_mu/m_e = dim(J3(O))^phi\")\n",
        "print(f\"           = {T.dim_J3O}^((1+sqrt(5))/2)\")\n",
        "print(f\"           = {T.dim_J3O}^{PHI:.6f}\")\n",
        "print(f\"           = {m_mu_m_e:.4f}\")\n",
        "\n",
        "print(\"\\nGeometric origin:\")\n",
        "print(f\"  27 = dim(J3(O)) = dimension of exceptional Jordan algebra\")\n",
        "print(f\"  phi = golden ratio from McKay correspondence\")\n",
        "\n",
        "# Experimental comparison\n",
        "m_mu_m_e_exp = 206.768\n",
        "\n",
        "pred_mmu = Prediction(\n",
        "    name=\"Muon-Electron Mass Ratio\",\n",
        "    symbol=\"m_mu/m_e\",\n",
        "    formula=\"dim(J3(O))^phi\",\n",
        "    value=m_mu_m_e,\n",
        "    experimental=m_mu_m_e_exp,\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_mmu.display()\n",
        "predictions.append(pred_mmu)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lgy2GDqjt-ts"
      },
      "source": [
        "---\n",
        "\n",
        "## 5. Quark Sector"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "bYogjSYnt-tt",
        "outputId": "e97fa76c-53f0-470b-aeff-3e3644876d8c"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 10: Strange-Down Mass Ratio\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  m_s/m_d = p2^2 * Weyl\n",
            "          = 2^2 * 5\n",
            "          = 4 * 5\n",
            "          = 20\n",
            "\n",
            "Strange-Down Mass Ratio (m_s/m_d)\n",
            "----------------------------------------\n",
            "  Formula: p2^2 * Weyl\n",
            "  Exact:   20 = 20.000000\n",
            "  Exp:     20.0 +/- 1.0\n",
            "  Dev:     0.000%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 10: STRANGE-DOWN RATIO m_s/m_d = 20\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 10: Strange-Down Mass Ratio\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# m_s/m_d = p2^2 * Weyl\n",
        "m_s_m_d = T.p2**2 * T.Weyl\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  m_s/m_d = p2^2 * Weyl\")\n",
        "print(f\"          = {T.p2}^2 * {T.Weyl}\")\n",
        "print(f\"          = {T.p2**2} * {T.Weyl}\")\n",
        "print(f\"          = {m_s_m_d}\")\n",
        "\n",
        "# Experimental comparison\n",
        "m_s_m_d_exp = 20.0\n",
        "m_s_m_d_unc = 1.0\n",
        "\n",
        "pred_msmd = Prediction(\n",
        "    name=\"Strange-Down Mass Ratio\",\n",
        "    symbol=\"m_s/m_d\",\n",
        "    formula=\"p2^2 * Weyl\",\n",
        "    value=float(m_s_m_d),\n",
        "    exact=Fraction(m_s_m_d, 1),\n",
        "    experimental=m_s_m_d_exp,\n",
        "    uncertainty=m_s_m_d_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_msmd.display()\n",
        "predictions.append(pred_msmd)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_vLojPpNt-tt"
      },
      "source": [
        "---\n",
        "\n",
        "## 6. Neutrino Sector\n",
        "\n",
        "The neutrino sector includes the CP violation phase and three mixing angles. The delta_CP prediction provides the framework's most stringent near-term test via the DUNE experiment."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2qjPuE_rt-tt",
        "outputId": "318737dd-60b7-479e-f4e6-c3834fc3e131"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 11: CP Violation Phase\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  delta_CP = dim(K7) * dim(G2) + H*\n",
            "           = 7 * 14 + 99\n",
            "           = 98 + 99\n",
            "           = 197 degrees\n",
            "\n",
            "CP Violation Phase (delta_CP)\n",
            "----------------------------------------\n",
            "  Formula: dim(K7) * dim(G2) + H*\n",
            "  Exact:   197 = 197.000000\n",
            "  Exp:     197 +/- 24 deg\n",
            "  Dev:     0.000%\n",
            "  Status:  PROVEN\n",
            "\n",
            "Falsification criterion:\n",
            "  DUNE measurement (2028-2030) with 5-10 degree precision\n",
            "  Framework rejected if |delta_CP - 197| > 15 degrees at 3 sigma\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 11: CP VIOLATION PHASE delta_CP = 197 degrees\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 11: CP Violation Phase\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# delta_CP = dim(K7) * dim(G2) + H*\n",
        "delta_CP = T.dim_K7 * T.dim_G2 + T.H_star\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  delta_CP = dim(K7) * dim(G2) + H*\")\n",
        "print(f\"           = {T.dim_K7} * {T.dim_G2} + {T.H_star}\")\n",
        "print(f\"           = {T.dim_K7 * T.dim_G2} + {T.H_star}\")\n",
        "print(f\"           = {delta_CP} degrees\")\n",
        "\n",
        "# Experimental comparison\n",
        "delta_CP_exp = 197\n",
        "delta_CP_unc = 24\n",
        "\n",
        "pred_dCP = Prediction(\n",
        "    name=\"CP Violation Phase\",\n",
        "    symbol=\"delta_CP\",\n",
        "    formula=\"dim(K7) * dim(G2) + H*\",\n",
        "    value=float(delta_CP),\n",
        "    exact=Fraction(delta_CP, 1),\n",
        "    experimental=delta_CP_exp,\n",
        "    uncertainty=delta_CP_unc,\n",
        "    unit=\" deg\",\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_dCP.display()\n",
        "predictions.append(pred_dCP)\n",
        "\n",
        "print(\"\\nFalsification criterion:\")\n",
        "print(\"  DUNE measurement (2028-2030) with 5-10 degree precision\")\n",
        "print(\"  Framework rejected if |delta_CP - 197| > 15 degrees at 3 sigma\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LLTMeWvft-tt",
        "outputId": "70d6d5b8-f361-4abd-b6a3-b13c2f0438b0"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 12: Reactor Mixing Angle\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  theta_13 = pi / b2\n",
            "           = pi / 21\n",
            "           = 0.149600 rad\n",
            "           = 8.571 degrees\n",
            "\n",
            "Reactor Mixing Angle (theta_13)\n",
            "----------------------------------------\n",
            "  Formula: pi / b2\n",
            "  Value:   8.571429 deg\n",
            "  Exp:     8.54 +/- 0.12 deg\n",
            "  Dev:     0.368%\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 12: REACTOR MIXING ANGLE theta_13 = pi/21\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 12: Reactor Mixing Angle\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# theta_13 = pi / b2\n",
        "theta_13_rad = np.pi / T.b2\n",
        "theta_13_deg = np.degrees(theta_13_rad)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  theta_13 = pi / b2\")\n",
        "print(f\"           = pi / {T.b2}\")\n",
        "print(f\"           = {theta_13_rad:.6f} rad\")\n",
        "print(f\"           = {theta_13_deg:.3f} degrees\")\n",
        "\n",
        "# Experimental comparison\n",
        "theta_13_exp = 8.54\n",
        "theta_13_unc = 0.12\n",
        "\n",
        "pred_t13 = Prediction(\n",
        "    name=\"Reactor Mixing Angle\",\n",
        "    symbol=\"theta_13\",\n",
        "    formula=\"pi / b2\",\n",
        "    value=theta_13_deg,\n",
        "    experimental=theta_13_exp,\n",
        "    uncertainty=theta_13_unc,\n",
        "    unit=\" deg\",\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_t13.display()\n",
        "predictions.append(pred_t13)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "N0a4c4mSt-tt",
        "outputId": "8d763384-be2a-4f84-99e3-db88d2120e9b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 13: Atmospheric Mixing Angle\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  theta_23 = (rank(E8) + b3) / H* radians\n",
            "           = (8 + 77) / 99\n",
            "           = 85 / 99\n",
            "           = 0.858586 rad\n",
            "           = 49.193 degrees\n",
            "\n",
            "Atmospheric Mixing Angle (theta_23)\n",
            "----------------------------------------\n",
            "  Formula: (rank(E8) + b3) / H*\n",
            "  Value:   49.193346 deg\n",
            "  Exp:     49.3 +/- 1.0 deg\n",
            "  Dev:     0.216%\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 13: ATMOSPHERIC MIXING ANGLE theta_23\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 13: Atmospheric Mixing Angle\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# theta_23 = (rank(E8) + b3) / H* radians\n",
        "theta_23_rad = (T.rank_E8 + T.b3) / T.H_star\n",
        "theta_23_deg = np.degrees(theta_23_rad)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  theta_23 = (rank(E8) + b3) / H* radians\")\n",
        "print(f\"           = ({T.rank_E8} + {T.b3}) / {T.H_star}\")\n",
        "print(f\"           = {T.rank_E8 + T.b3} / {T.H_star}\")\n",
        "print(f\"           = {theta_23_rad:.6f} rad\")\n",
        "print(f\"           = {theta_23_deg:.3f} degrees\")\n",
        "\n",
        "# Experimental comparison\n",
        "theta_23_exp = 49.3\n",
        "theta_23_unc = 1.0\n",
        "\n",
        "pred_t23 = Prediction(\n",
        "    name=\"Atmospheric Mixing Angle\",\n",
        "    symbol=\"theta_23\",\n",
        "    formula=\"(rank(E8) + b3) / H*\",\n",
        "    value=theta_23_deg,\n",
        "    experimental=theta_23_exp,\n",
        "    uncertainty=theta_23_unc,\n",
        "    unit=\" deg\",\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_t23.display()\n",
        "predictions.append(pred_t23)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_9vFVFRdt-tt",
        "outputId": "e00e3a4e-4150-4686-c9a7-46da76f159a8"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 14: Solar Mixing Angle\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  delta = 2*pi / Weyl^2 = 2*pi / 5^2 = 0.251327\n",
            "  gamma = (2*rank(E8) + 5*H*) / (10*dim(G2) + 3*dim(E8))\n",
            "        = (2*8 + 5*99) / (10*14 + 3*248)\n",
            "        = 511 / 884\n",
            "        = 0.578054\n",
            "  theta_12 = arctan(sqrt(delta/gamma))\n",
            "           = arctan(sqrt(0.251327/0.578054))\n",
            "           = 33.400 degrees\n",
            "\n",
            "Solar Mixing Angle (theta_12)\n",
            "----------------------------------------\n",
            "  Formula: arctan(sqrt(delta/gamma))\n",
            "  Value:   33.400050 deg\n",
            "  Exp:     33.41 +/- 0.75 deg\n",
            "  Dev:     0.030%\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 14: SOLAR MIXING ANGLE theta_12\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 14: Solar Mixing Angle\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# theta_12 = arctan(sqrt(delta/gamma)) where:\n",
        "# delta = 2*pi / Weyl^2\n",
        "# gamma = (2*rank(E8) + 5*H*) / (10*dim(G2) + 3*dim(E8))\n",
        "\n",
        "delta = 2 * np.pi / T.Weyl**2\n",
        "gamma_num = 2 * T.rank_E8 + 5 * T.H_star\n",
        "gamma_den = 10 * T.dim_G2 + 3 * T.dim_E8\n",
        "gamma = gamma_num / gamma_den\n",
        "\n",
        "theta_12_rad = np.arctan(np.sqrt(delta / gamma))\n",
        "theta_12_deg = np.degrees(theta_12_rad)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  delta = 2*pi / Weyl^2 = 2*pi / {T.Weyl}^2 = {delta:.6f}\")\n",
        "print(f\"  gamma = (2*rank(E8) + 5*H*) / (10*dim(G2) + 3*dim(E8))\")\n",
        "print(f\"        = (2*{T.rank_E8} + 5*{T.H_star}) / (10*{T.dim_G2} + 3*{T.dim_E8})\")\n",
        "print(f\"        = {gamma_num} / {gamma_den}\")\n",
        "print(f\"        = {gamma:.6f}\")\n",
        "print(f\"  theta_12 = arctan(sqrt(delta/gamma))\")\n",
        "print(f\"           = arctan(sqrt({delta:.6f}/{gamma:.6f}))\")\n",
        "print(f\"           = {theta_12_deg:.3f} degrees\")\n",
        "\n",
        "# Experimental comparison\n",
        "theta_12_exp = 33.41\n",
        "theta_12_unc = 0.75\n",
        "\n",
        "pred_t12 = Prediction(\n",
        "    name=\"Solar Mixing Angle\",\n",
        "    symbol=\"theta_12\",\n",
        "    formula=\"arctan(sqrt(delta/gamma))\",\n",
        "    value=theta_12_deg,\n",
        "    experimental=theta_12_exp,\n",
        "    uncertainty=theta_12_unc,\n",
        "    unit=\" deg\",\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_t12.display()\n",
        "predictions.append(pred_t12)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cD5o9kWPt-tu"
      },
      "source": [
        "---\n",
        "\n",
        "## 7. Cosmological Sector\n",
        "\n",
        "The cosmological predictions extend the framework to dark energy density, the primordial spectral index, and the fine structure constant."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "I--PncE4t-tu",
        "outputId": "abf6d3e6-6102-4d7f-9274-eff6a13ab87d"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 15: Higgs Quartic Coupling\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  lambda_H = sqrt(dim(G2) + N_gen) / 2^Weyl\n",
            "           = sqrt(14 + 3) / 2^5\n",
            "           = sqrt(17) / 32\n",
            "           = 4.123106 / 32\n",
            "           = 0.128847\n",
            "\n",
            "Note: 17 = dim(G2) + N_gen is prime.\n",
            "\n",
            "Higgs Quartic Coupling (lambda_H)\n",
            "----------------------------------------\n",
            "  Formula: sqrt(dim(G2) + N_gen) / 2^Weyl\n",
            "  Value:   0.128847\n",
            "  Exp:     0.129 +/- 0.003\n",
            "  Dev:     0.119%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 15: HIGGS QUARTIC COUPLING lambda_H = sqrt(17)/32\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 15: Higgs Quartic Coupling\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# lambda_H = sqrt(dim(G2) + N_gen) / 2^Weyl\n",
        "lambda_H_arg = T.dim_G2 + N_gen\n",
        "lambda_H = np.sqrt(lambda_H_arg) / (2**T.Weyl)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  lambda_H = sqrt(dim(G2) + N_gen) / 2^Weyl\")\n",
        "print(f\"           = sqrt({T.dim_G2} + {N_gen}) / 2^{T.Weyl}\")\n",
        "print(f\"           = sqrt({lambda_H_arg}) / {2**T.Weyl}\")\n",
        "print(f\"           = {np.sqrt(lambda_H_arg):.6f} / {2**T.Weyl}\")\n",
        "print(f\"           = {lambda_H:.6f}\")\n",
        "\n",
        "print(f\"\\nNote: 17 = dim(G2) + N_gen is prime.\")\n",
        "\n",
        "# Experimental comparison\n",
        "lambda_H_exp = 0.129\n",
        "lambda_H_unc = 0.003\n",
        "\n",
        "pred_lH = Prediction(\n",
        "    name=\"Higgs Quartic Coupling\",\n",
        "    symbol=\"lambda_H\",\n",
        "    formula=\"sqrt(dim(G2) + N_gen) / 2^Weyl\",\n",
        "    value=lambda_H,\n",
        "    experimental=lambda_H_exp,\n",
        "    uncertainty=lambda_H_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_lH.display()\n",
        "predictions.append(pred_lH)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "XY0Xpi5Jt-tu",
        "outputId": "148132aa-ed22-4c17-85a8-832248370eeb"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 16: Dark Energy Density\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  Omega_DE = ln(p2) * (b2 + b3) / H*\n",
            "           = ln(2) * (21 + 77) / 99\n",
            "           = 0.693147 * 98 / 99\n",
            "           = 0.686146\n",
            "\n",
            "Binary information origin: ln(2) appears from p2 = 2.\n",
            "\n",
            "Dark Energy Density (Omega_DE)\n",
            "----------------------------------------\n",
            "  Formula: ln(p2) * (b2 + b3) / H*\n",
            "  Value:   0.686146\n",
            "  Exp:     0.6847 +/- 0.0073\n",
            "  Dev:     0.211%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 16: DARK ENERGY DENSITY Omega_DE\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 16: Dark Energy Density\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# Omega_DE = ln(p2) * (b2 + b3) / H*\n",
        "Omega_DE = np.log(T.p2) * (T.b2 + T.b3) / T.H_star\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  Omega_DE = ln(p2) * (b2 + b3) / H*\")\n",
        "print(f\"           = ln({T.p2}) * ({T.b2} + {T.b3}) / {T.H_star}\")\n",
        "print(f\"           = {np.log(T.p2):.6f} * {T.b2 + T.b3} / {T.H_star}\")\n",
        "print(f\"           = {Omega_DE:.6f}\")\n",
        "\n",
        "print(f\"\\nBinary information origin: ln(2) appears from p2 = 2.\")\n",
        "\n",
        "# Experimental comparison\n",
        "Omega_DE_exp = 0.6847\n",
        "Omega_DE_unc = 0.0073\n",
        "\n",
        "pred_ODE = Prediction(\n",
        "    name=\"Dark Energy Density\",\n",
        "    symbol=\"Omega_DE\",\n",
        "    formula=\"ln(p2) * (b2 + b3) / H*\",\n",
        "    value=Omega_DE,\n",
        "    experimental=Omega_DE_exp,\n",
        "    uncertainty=Omega_DE_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_ODE.display()\n",
        "predictions.append(pred_ODE)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "SxP8esc0t-tu",
        "outputId": "109202be-37e7-4566-9843-e723f37ca1cd"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 17: Primordial Spectral Index\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  n_s = zeta(D_bulk) / zeta(Weyl)\n",
            "      = zeta(11) / zeta(5)\n",
            "      = 1.00049419 / 1.03692776\n",
            "      = 0.964864\n",
            "\n",
            "Geometric origin:\n",
            "  D_bulk = 11 = M-theory spacetime dimension\n",
            "  Weyl = 5 from |W(E8)| factorization\n",
            "\n",
            "Spectral Index (n_s)\n",
            "----------------------------------------\n",
            "  Formula: zeta(D_bulk) / zeta(Weyl)\n",
            "  Value:   0.964864\n",
            "  Exp:     0.9649 +/- 0.0042\n",
            "  Dev:     0.004%\n",
            "  Status:  PROVEN\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 17: SPECTRAL INDEX n_s = zeta(11)/zeta(5)\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 17: Primordial Spectral Index\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# n_s = zeta(D_bulk) / zeta(Weyl)\n",
        "n_s = zeta(T.D_bulk) / zeta(T.Weyl)\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  n_s = zeta(D_bulk) / zeta(Weyl)\")\n",
        "print(f\"      = zeta({T.D_bulk}) / zeta({T.Weyl})\")\n",
        "print(f\"      = {zeta(T.D_bulk):.8f} / {zeta(T.Weyl):.8f}\")\n",
        "print(f\"      = {n_s:.6f}\")\n",
        "\n",
        "print(f\"\\nGeometric origin:\")\n",
        "print(f\"  D_bulk = 11 = M-theory spacetime dimension\")\n",
        "print(f\"  Weyl = 5 from |W(E8)| factorization\")\n",
        "\n",
        "# Experimental comparison\n",
        "n_s_exp = 0.9649\n",
        "n_s_unc = 0.0042\n",
        "\n",
        "pred_ns = Prediction(\n",
        "    name=\"Spectral Index\",\n",
        "    symbol=\"n_s\",\n",
        "    formula=\"zeta(D_bulk) / zeta(Weyl)\",\n",
        "    value=n_s,\n",
        "    experimental=n_s_exp,\n",
        "    uncertainty=n_s_unc,\n",
        "    status=\"PROVEN\"\n",
        ")\n",
        "pred_ns.display()\n",
        "predictions.append(pred_ns)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "fYNAt5nvt-tv",
        "outputId": "1f6a8894-0179-45cb-fc3a-63502211708a"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "RELATION 18: Fine Structure Constant\n",
            "============================================================\n",
            "\n",
            "Derivation:\n",
            "  alpha^(-1) = (dim(E8) + rank(E8))/2 + H*/D_bulk + det(g)*kappa_T\n",
            "             = (248 + 8)/2 + 99/11 + 2.03125*0.016393\n",
            "             = 128.0 + 9.0000 + 0.033299\n",
            "             = 137.033299\n",
            "\n",
            "Fine Structure Constant (inverse) (alpha^(-1))\n",
            "----------------------------------------\n",
            "  Formula: (dim(E8)+rank(E8))/2 + H*/D_bulk + det(g)*kappa_T\n",
            "  Value:   137.033299\n",
            "  Exp:     137.035999\n",
            "  Dev:     0.002%\n",
            "  Status:  TOPOLOGICAL\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# RELATION 18: FINE STRUCTURE CONSTANT alpha^(-1)\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"RELATION 18: Fine Structure Constant\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# alpha^(-1) = (dim(E8) + rank(E8))/2 + H*/D_bulk + det(g)*kappa_T\n",
        "term1 = (T.dim_E8 + T.rank_E8) / 2\n",
        "term2 = T.H_star / T.D_bulk\n",
        "term3 = float(det_g) * float(kappa_T)\n",
        "alpha_inv = term1 + term2 + term3\n",
        "\n",
        "print(\"\\nDerivation:\")\n",
        "print(f\"  alpha^(-1) = (dim(E8) + rank(E8))/2 + H*/D_bulk + det(g)*kappa_T\")\n",
        "print(f\"             = ({T.dim_E8} + {T.rank_E8})/2 + {T.H_star}/{T.D_bulk} + {float(det_g):.5f}*{float(kappa_T):.6f}\")\n",
        "print(f\"             = {term1:.1f} + {term2:.4f} + {term3:.6f}\")\n",
        "print(f\"             = {alpha_inv:.6f}\")\n",
        "\n",
        "# Experimental comparison\n",
        "alpha_inv_exp = 137.035999\n",
        "\n",
        "pred_alpha = Prediction(\n",
        "    name=\"Fine Structure Constant (inverse)\",\n",
        "    symbol=\"alpha^(-1)\",\n",
        "    formula=\"(dim(E8)+rank(E8))/2 + H*/D_bulk + det(g)*kappa_T\",\n",
        "    value=alpha_inv,\n",
        "    experimental=alpha_inv_exp,\n",
        "    status=\"TOPOLOGICAL\"\n",
        ")\n",
        "pred_alpha.display()\n",
        "predictions.append(pred_alpha)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# =============================================================================\n",
        "# FIGURE 3: GIFT VS EXPERIMENTAL COMPARISON\n",
        "# =============================================================================\n",
        "\n",
        "def draw_comparison_plot():\n",
        "    \"\"\"\n",
        "    Create a publication-quality comparison of GIFT predictions vs experimental values.\n",
        "    \"\"\"\n",
        "    fig, axes = plt.subplots(1, 2, figsize=(13, 6))\n",
        "\n",
        "    # Filter predictions with experimental values\n",
        "    exp_preds = [p for p in predictions if p.experimental is not None and p.deviation is not None]\n",
        "\n",
        "    # --- Left panel: Deviation bar chart ---\n",
        "    ax = axes[0]\n",
        "\n",
        "    names = [p.symbol for p in exp_preds]\n",
        "    devs = [p.deviation for p in exp_preds]\n",
        "\n",
        "    # Color by deviation magnitude\n",
        "    colors = []\n",
        "    for d in devs:\n",
        "        if d < 0.01:\n",
        "            colors.append(GIFT_COLORS['match'])\n",
        "        elif d < 0.1:\n",
        "            colors.append(GIFT_COLORS['close'])\n",
        "        else:\n",
        "            colors.append(GIFT_COLORS['good'])\n",
        "\n",
        "    y_pos = np.arange(len(names))\n",
        "    bars = ax.barh(y_pos, devs, color=colors, edgecolor='white', linewidth=0.5, height=0.7)\n",
        "\n",
        "    ax.set_yticks(y_pos)\n",
        "    ax.set_yticklabels(names, fontsize=9)\n",
        "    ax.set_xlabel('Deviation from Experiment (%)', fontsize=11)\n",
        "    ax.set_title('GIFT Predictions: Deviation Analysis', fontsize=13, fontweight='bold', pad=15)\n",
        "    ax.set_xlim(0, max(devs) * 1.15)\n",
        "\n",
        "    # Add value labels\n",
        "    for i, (bar, dev) in enumerate(zip(bars, devs)):\n",
        "        if dev < 0.01:\n",
        "            label = 'exact'\n",
        "        else:\n",
        "            label = f'{dev:.3f}%'\n",
        "        ax.text(bar.get_width() + 0.005, bar.get_y() + bar.get_height()/2,\n",
        "               label, va='center', fontsize=8)\n",
        "\n",
        "    # Add legend\n",
        "    legend_elements = [\n",
        "        mpatches.Patch(facecolor=GIFT_COLORS['match'], label='Exact (< 0.01%)'),\n",
        "        mpatches.Patch(facecolor=GIFT_COLORS['close'], label='Close (0.01-0.1%)'),\n",
        "        mpatches.Patch(facecolor=GIFT_COLORS['good'], label='Good (0.1-0.5%)')\n",
        "    ]\n",
        "    ax.legend(handles=legend_elements, loc='lower right', fontsize=9)\n",
        "\n",
        "    ax.axvline(x=0.1, color='gray', linestyle='--', linewidth=1, alpha=0.5)\n",
        "    ax.axvline(x=0.01, color='gray', linestyle=':', linewidth=1, alpha=0.5)\n",
        "\n",
        "    # --- Right panel: Scatter plot GIFT vs Exp ---\n",
        "    ax = axes[1]\n",
        "\n",
        "    # Normalize values for comparison (log scale for wide range)\n",
        "    gift_vals = []\n",
        "    exp_vals = []\n",
        "    labels = []\n",
        "\n",
        "    for p in exp_preds:\n",
        "        if p.value > 0 and p.experimental > 0:\n",
        "            gift_vals.append(p.value)\n",
        "            exp_vals.append(p.experimental)\n",
        "            labels.append(p.symbol)\n",
        "\n",
        "    gift_vals = np.array(gift_vals)\n",
        "    exp_vals = np.array(exp_vals)\n",
        "\n",
        "    # Perfect agreement line\n",
        "    min_val = min(min(gift_vals), min(exp_vals)) * 0.8\n",
        "    max_val = max(max(gift_vals), max(exp_vals)) * 1.2\n",
        "\n",
        "    ax.plot([min_val, max_val], [min_val, max_val], 'k--', linewidth=1.5,\n",
        "           label='Perfect agreement', alpha=0.7)\n",
        "\n",
        "    # Scatter with colors by deviation\n",
        "    for i, (gv, ev, lab) in enumerate(zip(gift_vals, exp_vals, labels)):\n",
        "        dev = abs(gv - ev) / ev * 100\n",
        "        if dev < 0.01:\n",
        "            c = GIFT_COLORS['match']\n",
        "        elif dev < 0.1:\n",
        "            c = GIFT_COLORS['close']\n",
        "        else:\n",
        "            c = GIFT_COLORS['good']\n",
        "        ax.scatter(ev, gv, c=c, s=80, edgecolor='white', linewidth=1, zorder=3)\n",
        "\n",
        "        # Label some key points\n",
        "        if lab in ['Q_Koide', 'sin^2(theta_W)', 'delta_CP', 'n_s', 'N_gen']:\n",
        "            offset = (5, 5) if gv > ev else (-5, -5)\n",
        "            ax.annotate(lab, (ev, gv), textcoords='offset points',\n",
        "                       xytext=offset, fontsize=8, alpha=0.8)\n",
        "\n",
        "    ax.set_xscale('log')\n",
        "    ax.set_yscale('log')\n",
        "    ax.set_xlabel('Experimental Value', fontsize=11)\n",
        "    ax.set_ylabel('GIFT Prediction', fontsize=11)\n",
        "    ax.set_title('GIFT vs Experiment', fontsize=13, fontweight='bold', pad=15)\n",
        "    ax.set_xlim(min_val, max_val)\n",
        "    ax.set_ylim(min_val, max_val)\n",
        "    ax.set_aspect('equal')\n",
        "    ax.legend(loc='upper left', fontsize=9)\n",
        "    ax.grid(True, alpha=0.3, which='both')\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.savefig('fig3_gift_comparison.pdf', bbox_inches='tight')\n",
        "    plt.savefig('fig3_gift_comparison.png', bbox_inches='tight', dpi=300)\n",
        "    plt.show()\n",
        "    print(\"Figure 3 saved: fig3_gift_comparison.pdf, fig3_gift_comparison.png\")\n",
        "\n",
        "draw_comparison_plot()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 555
        },
        "id": "tulrq-p6t-tv",
        "outputId": "c7ae1222-a464-497c-951a-80008eddf679"
      },
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 1950x900 with 2 Axes>"
            ],
            "image/png": "[encoded data, 196300 characters]\n"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Figure 3 saved: fig3_gift_comparison.pdf, fig3_gift_comparison.png\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# =============================================================================\n",
        "# FIGURE 4: DEVIATION DISTRIBUTION AND PHYSICS SECTORS\n",
        "# =============================================================================\n",
        "\n",
        "def draw_statistics_figure():\n",
        "    \"\"\"\n",
        "    Create summary statistics and sector breakdown visualization.\n",
        "    \"\"\"\n",
        "    fig = plt.figure(figsize=(13, 5))\n",
        "\n",
        "    # Filter predictions with experimental values\n",
        "    exp_preds = [p for p in predictions if p.experimental is not None and p.deviation is not None]\n",
        "    devs = [p.deviation for p in exp_preds]\n",
        "\n",
        "    # --- Left panel: Deviation histogram ---\n",
        "    ax1 = fig.add_subplot(121)\n",
        "\n",
        "    # Define bins on log scale\n",
        "    bins = [0, 0.005, 0.01, 0.05, 0.1, 0.2, 0.5]\n",
        "\n",
        "    counts, edges = np.histogram(devs, bins=bins)\n",
        "\n",
        "    colors_hist = [GIFT_COLORS['match'], GIFT_COLORS['match'],\n",
        "                   GIFT_COLORS['close'], GIFT_COLORS['close'],\n",
        "                   GIFT_COLORS['good'], GIFT_COLORS['good']]\n",
        "\n",
        "    # Create bar chart\n",
        "    bar_positions = np.arange(len(counts))\n",
        "    bar_labels = ['<0.005%', '0.005-0.01%', '0.01-0.05%', '0.05-0.1%', '0.1-0.2%', '0.2-0.5%']\n",
        "\n",
        "    bars = ax1.bar(bar_positions, counts, color=colors_hist, edgecolor='white', linewidth=1)\n",
        "\n",
        "    ax1.set_xticks(bar_positions)\n",
        "    ax1.set_xticklabels(bar_labels, rotation=45, ha='right', fontsize=9)\n",
        "    ax1.set_ylabel('Number of Predictions', fontsize=11)\n",
        "    ax1.set_title('Distribution of Deviations', fontsize=13, fontweight='bold', pad=15)\n",
        "    ax1.set_ylim(0, max(counts) + 1)\n",
        "\n",
        "    # Add count labels on bars\n",
        "    for bar, count in zip(bars, counts):\n",
        "        if count > 0:\n",
        "            ax1.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.1,\n",
        "                    str(int(count)), ha='center', va='bottom', fontsize=10, fontweight='bold')\n",
        "\n",
        "    # Add statistics text\n",
        "    stats_text = f'n = {len(devs)}\\nmean = {np.mean(devs):.3f}%\\nmedian = {np.median(devs):.3f}%'\n",
        "    ax1.text(0.95, 0.95, stats_text, transform=ax1.transAxes, fontsize=10,\n",
        "            verticalalignment='top', horizontalalignment='right',\n",
        "            bbox=dict(boxstyle='round', facecolor=GIFT_COLORS['light'], edgecolor='gray'))\n",
        "\n",
        "    # --- Right panel: Sector breakdown ---\n",
        "    ax2 = fig.add_subplot(122)\n",
        "    ax2.set_xlim(0, 10)\n",
        "    ax2.set_ylim(0, 10)\n",
        "    ax2.axis('off')\n",
        "    ax2.set_title('Predictions by Physics Sector', fontsize=13, fontweight='bold', pad=15)\n",
        "\n",
        "    # Define sectors\n",
        "    sectors = [\n",
        "        ('Foundational', ['N_gen', 'tau', 'kappa_T', 'det(g)'], GIFT_COLORS['E8']),\n",
        "        ('Gauge', ['sin^2(theta_W)', 'alpha_s(M_Z)'], GIFT_COLORS['G2']),\n",
        "        ('Lepton', ['Q_Koide', 'm_tau/m_e', 'm_mu/m_e'], GIFT_COLORS['K7']),\n",
        "        ('Quark', ['m_s/m_d'], GIFT_COLORS['gold']),\n",
        "        ('Neutrino', ['delta_CP', 'theta_13', 'theta_23', 'theta_12'], '#9C27B0'),\n",
        "        ('Cosmology', ['lambda_H', 'Omega_DE', 'n_s', 'alpha^(-1)'], '#FF5722'),\n",
        "    ]\n",
        "\n",
        "    y_start = 9\n",
        "    dy = 1.4\n",
        "\n",
        "    for i, (sector_name, symbols, color) in enumerate(sectors):\n",
        "        y = y_start - i * dy\n",
        "\n",
        "        # Sector box\n",
        "        rect = FancyBboxPatch((0.3, y - 0.5), 9.4, 1.2, boxstyle=\"round,pad=0.05\",\n",
        "                              facecolor=color, edgecolor='white', linewidth=2, alpha=0.15)\n",
        "        ax2.add_patch(rect)\n",
        "\n",
        "        # Sector name\n",
        "        ax2.text(0.5, y, sector_name, fontsize=11, fontweight='bold',\n",
        "                va='center', color=color)\n",
        "\n",
        "        # Count predictions and compute average deviation\n",
        "        sector_preds = [p for p in exp_preds if p.symbol in symbols]\n",
        "        n_preds = len(sector_preds)\n",
        "\n",
        "        if sector_preds:\n",
        "            avg_dev = np.mean([p.deviation for p in sector_preds])\n",
        "            # Show symbols with mini deviation indicators\n",
        "            x_pos = 3.5\n",
        "            for p in sector_preds:\n",
        "                if p.deviation < 0.01:\n",
        "                    marker = 'o'\n",
        "                    mc = GIFT_COLORS['match']\n",
        "                elif p.deviation < 0.1:\n",
        "                    marker = 's'\n",
        "                    mc = GIFT_COLORS['close']\n",
        "                else:\n",
        "                    marker = '^'\n",
        "                    mc = GIFT_COLORS['good']\n",
        "                ax2.scatter(x_pos, y, marker=marker, c=mc, s=50, edgecolor='white', zorder=3)\n",
        "                x_pos += 0.8\n",
        "\n",
        "            # Average deviation\n",
        "            ax2.text(9.5, y, f'{avg_dev:.2f}%', fontsize=10, ha='right', va='center',\n",
        "                    color=color, fontweight='bold')\n",
        "\n",
        "        ax2.text(3.0, y, f'({n_preds})', fontsize=9, va='center', color='gray')\n",
        "\n",
        "    # Legend\n",
        "    ax2.text(5, 0.8, 'Markers:', fontsize=9, ha='center', fontweight='bold')\n",
        "    ax2.scatter(3.5, 0.3, marker='o', c=GIFT_COLORS['match'], s=40, edgecolor='white')\n",
        "    ax2.text(4.0, 0.3, '< 0.01%', fontsize=8, va='center')\n",
        "    ax2.scatter(5.5, 0.3, marker='s', c=GIFT_COLORS['close'], s=40, edgecolor='white')\n",
        "    ax2.text(6.0, 0.3, '0.01-0.1%', fontsize=8, va='center')\n",
        "    ax2.scatter(7.5, 0.3, marker='^', c=GIFT_COLORS['good'], s=40, edgecolor='white')\n",
        "    ax2.text(8.0, 0.3, '> 0.1%', fontsize=8, va='center')\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.savefig('fig4_statistics.pdf', bbox_inches='tight')\n",
        "    plt.savefig('fig4_statistics.png', bbox_inches='tight', dpi=300)\n",
        "    plt.show()\n",
        "    print(\"Figure 4 saved: fig4_statistics.pdf, fig4_statistics.png\")\n",
        "\n",
        "draw_statistics_figure()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 457
        },
        "id": "hNPLVs0ht-tv",
        "outputId": "8993705d-b6c1-4f9b-91a3-ac9473a42e02"
      },
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 1950x750 with 2 Axes>"
            ],
            "image/png": "[encoded data, 138264 characters]\n"
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Figure 4 saved: fig4_statistics.pdf, fig4_statistics.png\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6FxYnsFkt-tv"
      },
      "source": [
        "---\n",
        "\n",
        "## 8. Statistical Summary\n",
        "\n",
        "We now compile all predictions and assess the global performance of the framework. The 23 total predictions comprise:\n",
        "\n",
        "- **10 structural integers**: Topological invariants from the TCS construction\n",
        "- **13 dimensionless ratios**: Derived predictions with experimental comparisons\n",
        "\n",
        "The analysis below focuses on the 13 experimentally testable dimensionless predictions.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "gk2SDqj4t-tv",
        "outputId": "b17a5fbc-0234-4820-8346-cb23253dc345"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "================================================================================\n",
            "GIFT v3.0 FRAMEWORK VALIDATION - COMPLETE SUMMARY\n",
            "================================================================================\n",
            "\n",
            "#   Relation                     GIFT           Experimental       Dev.\n",
            "--------------------------------------------------------------------------------\n",
            "1   N_gen                        3              3                0.000%\n",
            "2   tau                          3.896745       -                     -\n",
            "3   kappa_T                      0.016393       -                     -\n",
            "4   det(g)                       2.031250       -                     -\n",
            "5   sin^2(theta_W)               0.230769       0.23122          0.195%\n",
            "6   alpha_s(M_Z)                 0.117851       0.1179           0.041%\n",
            "7   Q_Koide                      0.666667       0.666661         0.001%\n",
            "8   m_tau/m_e                    3477.000000    3477.15          0.004%\n",
            "9   m_mu/m_e                     207.011857     206.768          0.118%\n",
            "10  m_s/m_d                      20.000000      20.0             0.000%\n",
            "11  delta_CP                     197.000000     197              0.000%\n",
            "12  theta_13                     8.571429       8.54             0.368%\n",
            "13  theta_23                     49.193346      49.3             0.216%\n",
            "14  theta_12                     33.400050      33.41            0.030%\n",
            "15  lambda_H                     0.128847       0.129            0.119%\n",
            "16  Omega_DE                     0.686146       0.6847           0.211%\n",
            "17  n_s                          0.964864       0.9649           0.004%\n",
            "18  alpha^(-1)                   137.033299     137.035999       0.002%\n",
            "--------------------------------------------------------------------------------\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# COMPLETE SUMMARY TABLE\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 80)\n",
        "print(\"GIFT v3.0 FRAMEWORK VALIDATION - COMPLETE SUMMARY\")\n",
        "print(\"=\" * 80)\n",
        "print()\n",
        "print(f\"{'#':<3} {'Relation':<28} {'GIFT':<14} {'Experimental':<14} {'Dev.':>8}\")\n",
        "print(\"-\" * 80)\n",
        "\n",
        "for i, p in enumerate(predictions, 1):\n",
        "    gift_str = f\"{p.value:.6f}\" if not isinstance(p.value, int) else str(p.value)\n",
        "    if len(gift_str) > 12:\n",
        "        gift_str = f\"{p.value:.4f}\"\n",
        "\n",
        "    if p.experimental is not None:\n",
        "        exp_str = f\"{p.experimental}\"\n",
        "        dev_str = f\"{p.deviation:.3f}%\"\n",
        "    else:\n",
        "        exp_str = \"-\"\n",
        "        dev_str = \"-\"\n",
        "\n",
        "    print(f\"{i:<3} {p.symbol:<28} {gift_str:<14} {exp_str:<14} {dev_str:>8}\")\n",
        "\n",
        "print(\"-\" * 80)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 28,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2mx-stvjt-tw",
        "outputId": "b2e50c46-60fb-4cce-fd02-238281fcc048"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "STATISTICAL ANALYSIS\n",
            "============================================================\n",
            "\n",
            "Total predictions: 18\n",
            "With experimental comparison: 15\n",
            "\n",
            "Deviation statistics:\n",
            "  Mean:   0.0873%\n",
            "  Median: 0.0298%\n",
            "  Min:    0.0000%\n",
            "  Max:    0.3680%\n",
            "\n",
            "Deviation distribution:\n",
            "  Exact (< 0.005%):   7\n",
            "  < 0.01%:            0\n",
            "  0.01% - 0.1%:       2\n",
            "  0.1% - 0.5%:        6\n",
            "\n",
            "Exact matches (within experimental uncertainty):\n",
            "  - N_gen: 3 vs 3\n",
            "  - Q_Koide: 0.6666666666666666 vs 0.666661\n",
            "  - m_tau/m_e: 3477.0 vs 3477.15\n",
            "  - m_s/m_d: 20.0 vs 20.0\n",
            "  - delta_CP: 197.0 vs 197\n",
            "  - n_s: 0.9648639296628596 vs 0.9649\n",
            "  - alpha^(-1): 137.03329918032787 vs 137.035999\n",
            "\n",
            "============================================================\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# STATISTICAL ANALYSIS\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"STATISTICAL ANALYSIS\")\n",
        "print(\"=\" * 60)\n",
        "\n",
        "# Filter predictions with experimental values\n",
        "exp_predictions = [p for p in predictions if p.experimental is not None and p.deviation is not None]\n",
        "deviations = [p.deviation for p in exp_predictions]\n",
        "\n",
        "print(f\"\\nTotal predictions: {len(predictions)}\")\n",
        "print(f\"With experimental comparison: {len(exp_predictions)}\")\n",
        "\n",
        "# Deviation statistics\n",
        "mean_dev = np.mean(deviations)\n",
        "median_dev = np.median(deviations)\n",
        "max_dev = np.max(deviations)\n",
        "min_dev = np.min(deviations)\n",
        "\n",
        "print(f\"\\nDeviation statistics:\")\n",
        "print(f\"  Mean:   {mean_dev:.4f}%\")\n",
        "print(f\"  Median: {median_dev:.4f}%\")\n",
        "print(f\"  Min:    {min_dev:.4f}%\")\n",
        "print(f\"  Max:    {max_dev:.4f}%\")\n",
        "\n",
        "# Distribution\n",
        "exact = sum(1 for d in deviations if d < 0.005)\n",
        "sub_001 = sum(1 for d in deviations if 0.005 <= d < 0.01)\n",
        "sub_01 = sum(1 for d in deviations if 0.01 <= d < 0.1)\n",
        "sub_05 = sum(1 for d in deviations if 0.1 <= d < 0.5)\n",
        "\n",
        "print(f\"\\nDeviation distribution:\")\n",
        "print(f\"  Exact (< 0.005%):   {exact}\")\n",
        "print(f\"  < 0.01%:            {sub_001}\")\n",
        "print(f\"  0.01% - 0.1%:       {sub_01}\")\n",
        "print(f\"  0.1% - 0.5%:        {sub_05}\")\n",
        "\n",
        "# Exact matches\n",
        "print(f\"\\nExact matches (within experimental uncertainty):\")\n",
        "for p in exp_predictions:\n",
        "    if p.deviation < 0.01:\n",
        "        print(f\"  - {p.symbol}: {p.value} vs {p.experimental}\")\n",
        "\n",
        "print(\"\\n\" + \"=\" * 60)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LCYIcZh3t-tw"
      },
      "source": [
        "---\n",
        "\n",
        "## 9. Exports\n",
        "\n",
        "Machine-readable outputs for integration with other tools and publications."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 29,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "VfY-zDrKt-tw",
        "outputId": "2cfdbb33-ba29-4df2-d4ca-c0ef2a319a0b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "JSON export saved: gift_v3_validation.json\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# JSON EXPORT\n",
        "# =============================================================================\n",
        "\n",
        "export_data = {\n",
        "    \"metadata\": {\n",
        "        \"framework\": \"GIFT\",\n",
        "        \"version\": \"3.0\",\n",
        "        \"generated\": datetime.now().isoformat(),\n",
        "        \"total_predictions\": len(predictions),\n",
        "        \"mean_deviation_percent\": round(mean_dev, 4)\n",
        "    },\n",
        "    \"topology\": {\n",
        "        \"dim_E8\": T.dim_E8,\n",
        "        \"rank_E8\": T.rank_E8,\n",
        "        \"dim_G2\": T.dim_G2,\n",
        "        \"dim_K7\": T.dim_K7,\n",
        "        \"b2\": T.b2,\n",
        "        \"b3\": T.b3,\n",
        "        \"H_star\": T.H_star,\n",
        "        \"p2\": T.p2,\n",
        "        \"Weyl\": T.Weyl,\n",
        "        \"D_bulk\": T.D_bulk,\n",
        "        \"dim_J3O\": T.dim_J3O\n",
        "    },\n",
        "    \"predictions\": [\n",
        "        {\n",
        "            \"name\": p.name,\n",
        "            \"symbol\": p.symbol,\n",
        "            \"formula\": p.formula,\n",
        "            \"value\": p.value,\n",
        "            \"exact\": str(p.exact) if p.exact else None,\n",
        "            \"experimental\": p.experimental,\n",
        "            \"uncertainty\": p.uncertainty,\n",
        "            \"deviation_percent\": round(p.deviation, 4) if p.deviation else None,\n",
        "            \"status\": p.status\n",
        "        }\n",
        "        for p in predictions\n",
        "    ]\n",
        "}\n",
        "\n",
        "json_filename = \"gift_v3_validation.json\"\n",
        "with open(json_filename, \"w\", encoding=\"utf-8\") as f:\n",
        "    json.dump(export_data, f, indent=2, ensure_ascii=False)\n",
        "\n",
        "print(f\"JSON export saved: {json_filename}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 30,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "YmcVwHlut-tw",
        "outputId": "6210e63e-7220-4950-d148-0e1da7932a2a"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "LaTeX export saved: gift_v3_predictions.tex\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# LATEX TABLE EXPORT\n",
        "# =============================================================================\n",
        "\n",
        "latex_content = r\"\"\"% GIFT v3.0 Framework Validation - Complete Predictions\n",
        "% Auto-generated: \"\"\" + datetime.now().strftime(\"%Y-%m-%d\") + r\"\"\"\n",
        "\n",
        "\\begin{table}[htbp]\n",
        "\\centering\n",
        "\\caption{GIFT v3.0 Dimensionless Predictions}\n",
        "\\label{tab:gift-predictions}\n",
        "\\begin{tabular}{clcccc}\n",
        "\\toprule\n",
        "\\# & Observable & Formula & GIFT & Experimental & Dev. \\\\\n",
        "\\midrule\n",
        "\"\"\"\n",
        "\n",
        "for i, p in enumerate(predictions, 1):\n",
        "    formula_tex = p.formula.replace(\"^\", \"^{\").replace(\"(\", \"}\") if \"^\" in p.formula else p.formula\n",
        "    formula_tex = p.formula  # Keep simple for now\n",
        "\n",
        "    if p.exact and p.exact.denominator != 1:\n",
        "        val_str = f\"${p.exact.numerator}/{p.exact.denominator}$\"\n",
        "    else:\n",
        "        val_str = f\"{p.value:.4f}\"\n",
        "\n",
        "    exp_str = f\"{p.experimental}\" if p.experimental else \"-\"\n",
        "    dev_str = f\"{p.deviation:.2f}\\%\" if p.deviation else \"-\"\n",
        "\n",
        "    latex_content += f\"{i} & ${p.symbol}$ & \\\\footnotesize{{{formula_tex}}} & {val_str} & {exp_str} & {dev_str} \\\\\\\\\\n\"\n",
        "\n",
        "latex_content += r\"\"\"\\bottomrule\n",
        "\\end{tabular}\n",
        "\\end{table}\n",
        "\"\"\"\n",
        "\n",
        "latex_filename = \"gift_v3_predictions.tex\"\n",
        "with open(latex_filename, \"w\", encoding=\"utf-8\") as f:\n",
        "    f.write(latex_content)\n",
        "\n",
        "print(f\"LaTeX export saved: {latex_filename}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 31,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "F8EoMSBFt-tw",
        "outputId": "5b501fff-5b43-4877-910d-473ee200afc3"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Markdown summary exported to GIFT_validation_summary.md\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# MARKDOWN SUMMARY EXPORT\n",
        "# =============================================================================\n",
        "\n",
        "md_content = f\"\"\"# GIFT v3.0 Framework Validation Summary\n",
        "\n",
        "**Generated:** {datetime.now().strftime(\"%Y-%m-%d\")}\n",
        "\n",
        "## Overview\n",
        "\n",
        "The GIFT framework yields **23 predictions**:\n",
        "- **10 structural integers** from TCS construction\n",
        "- **13 dimensionless ratios** with experimental comparison\n",
        "\n",
        "Mean deviation: {mean_dev:.4f}%\n",
        "\n",
        "## 10 Structural Integers (Topological Constants)\n",
        "\n",
        "| # | Constant | Value | Description |\n",
        "|---|----------|-------|-------------|\n",
        "| 1 | dim(E8) | {T.dim_E8} | E8 Lie algebra dimension |\n",
        "| 2 | rank(E8) | {T.rank_E8} | E8 Cartan subalgebra |\n",
        "| 3 | dim(G2) | {T.dim_G2} | G2 holonomy dimension |\n",
        "| 4 | dim(K7) | {T.dim_K7} | Internal manifold dimension |\n",
        "| 5 | b2(K7) | {T.b2} | Second Betti number |\n",
        "| 6 | b3(K7) | {T.b3} | Third Betti number |\n",
        "| 7 | H* | {T.H_star} | Effective cohomology |\n",
        "| 8 | dim(J3(O)) | {T.dim_J3O} | Jordan algebra dimension |\n",
        "| 9 | D_bulk | {T.D_bulk} | Bulk spacetime dimension |\n",
        "| 10 | Weyl | {T.Weyl} | Weyl factor |\n",
        "\n",
        "## 13 Dimensionless Predictions (with Experimental Comparison)\n",
        "\n",
        "| # | Observable | GIFT | Experimental | Deviation |\n",
        "|---|------------|------|--------------|-----------|\n",
        "\"\"\"\n",
        "\n",
        "for i, p in enumerate([p for p in predictions if p.experimental is not None], 1):\n",
        "    gift_str = f\"{p.value:.6f}\" if not isinstance(p.value, int) else str(p.value)\n",
        "    exp_str = f\"{p.experimental:.4f}\" if p.experimental else \"-\"\n",
        "    dev_str = f\"{p.deviation:.3f}%\" if p.deviation is not None else \"-\"\n",
        "    md_content += f\"| {i} | {p.name} | {gift_str} | {exp_str} | {dev_str} |\\n\"\n",
        "\n",
        "md_content += f\"\"\"\n",
        "\n",
        "## Statistical Summary\n",
        "\n",
        "| Metric | Value |\n",
        "|--------|-------|\n",
        "| Total predictions | 23 |\n",
        "| Structural integers | 10 |\n",
        "| Dimensionless ratios | 13 |\n",
        "| Mean deviation | {mean_dev:.4f}% |\n",
        "| Exact matches | {exact} |\n",
        "\n",
        "## References\n",
        "\n",
        "- Particle Data Group (2024)\n",
        "- NuFIT 5.3 (2024)\n",
        "- Planck Collaboration (2020)\n",
        "\"\"\"\n",
        "\n",
        "md_filename = \"GIFT_validation_summary.md\"\n",
        "with open(md_filename, 'w') as f:\n",
        "    f.write(md_content)\n",
        "print(f\"Markdown summary exported to {md_filename}\")\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 32,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "GSU-UcO4t-tx",
        "outputId": "2b9359cf-1a9a-40c0-dc02-07a1b86ab80e"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "GIFT v3.0 FRAMEWORK VALIDATION COMPLETE\n",
            "============================================================\n",
            "\n",
            "PREDICTION COUNT:\n",
            "  Structural integers:         10\n",
            "  Dimensionless relations:     18 (13 with exp. comparison)\n",
            "  Total predictions:           23\n",
            "\n",
            "STATISTICAL PERFORMANCE (13 testable predictions):\n",
            "  Mean deviation from experiment: 0.0873%\n",
            "  Exact matches (0.00%):         7\n",
            "  Sub-0.01% deviation:           4\n",
            "  Sub-0.1% deviation:            9\n",
            "  Sub-0.5% deviation:            15\n",
            "\n",
            "Exports generated:\n",
            "  - gift_v3_validation.json\n",
            "  - gift_v3_predictions.tex\n",
            "  - GIFT_validation_summary.md\n",
            "\n",
            "Decisive test: DUNE delta_CP measurement (2027-2028)\n",
            "  GIFT prediction: 197 degrees (exact)\n",
            "  Falsification range: outside 182-212 degrees\n"
          ]
        }
      ],
      "source": [
        "# =============================================================================\n",
        "# FINAL SUMMARY\n",
        "# =============================================================================\n",
        "\n",
        "print(\"=\" * 60)\n",
        "print(\"GIFT v3.0 FRAMEWORK VALIDATION COMPLETE\")\n",
        "print(\"=\" * 60)\n",
        "print()\n",
        "print(\"PREDICTION COUNT:\")\n",
        "print(f\"  Structural integers:         10\")\n",
        "print(f\"  Dimensionless relations:     18 (13 with exp. comparison)\")\n",
        "print(f\"  Total predictions:           23\")\n",
        "print()\n",
        "print(f\"STATISTICAL PERFORMANCE (13 testable predictions):\")\n",
        "print(f\"  Mean deviation from experiment: {mean_dev:.4f}%\")\n",
        "print(f\"  Exact matches (0.00%):         {exact}\")\n",
        "print(f\"  Sub-0.01% deviation:           {sum(1 for p in exp_predictions if 0 < p.deviation <= 0.01)}\")\n",
        "print(f\"  Sub-0.1% deviation:            {sum(1 for p in exp_predictions if p.deviation <= 0.1)}\")\n",
        "print(f\"  Sub-0.5% deviation:            {sum(1 for p in exp_predictions if p.deviation <= 0.5)}\")\n",
        "print()\n",
        "print(\"Exports generated:\")\n",
        "print(f\"  - {json_filename}\")\n",
        "print(f\"  - {latex_filename}\")\n",
        "print(f\"  - {md_filename}\")\n",
        "print()\n",
        "print(\"Decisive test: DUNE delta_CP measurement (2027-2028)\")\n",
        "print(\"  GIFT prediction: 197 degrees (exact)\")\n",
        "print(\"  Falsification range: outside 182-212 degrees\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JU_0xeCot-tx"
      },
      "source": [
        "---\n",
        "\n",
        "## References\n",
        "\n",
        "1. Joyce, D.D. (2000). *Compact Manifolds with Special Holonomy*. Oxford University Press.\n",
        "\n",
        "2. Kovalev, A. (2003). Twisted connected sums and special Riemannian holonomy. *J. Reine Angew. Math.* 565, 125-160.\n",
        "\n",
        "3. Particle Data Group (2024). Review of Particle Physics. *Phys. Rev. D* 110.\n",
        "\n",
        "4. NuFIT Collaboration (2024). Global neutrino oscillation analysis. www.nu-fit.org\n",
        "\n",
        "5. Planck Collaboration (2020). Cosmological parameters. *Astron. Astrophys.* 641, A6.\n",
        "\n",
        "6. Koide, Y. (1982). Fermion-boson two-body model. *Lett. Nuovo Cim.* 34, 201.\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.11.0"
    },
    "colab": {
      "provenance": [],
      "include_colab_link": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}