{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},
  "language_info": {"name": "python", "version": "3.8.0"}
 },
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# D3 Framework — Jupyter Notebook Examples\n",
    "\n",
    "**Black hole information geometry** based on the D3 research series by Bharat Sharma (2026).\n",
    "\n",
    "- Web calculator: https://phenex-d3.vercel.app\n",
    "- Documentation: https://phenex-d3.vercel.app/docs.html\n",
    "- GitHub: https://github.com/bsharma173860-oss/d3-research\n",
    "- DOI: 10.5281/zenodo.20502577"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install the library\n",
    "!pip install d3framework matplotlib numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from d3framework import blackhole, compute, papers, get_paper\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "print('D3 Framework loaded successfully')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 1. Basic black hole calculation\n", "Paper 3: R_total = r_s (all constants cancel)"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Schwarzschild black hole (chi=q=0)\n",
    "bh = blackhole(mass_solar=1.0)\n",
    "print(bh)\n",
    "print()\n",
    "print(f'R_total == r_s: {abs(bh.R_total_m - bh.r_s_m) < 1e-6}')\n",
    "print(f'h(0,0) = {bh.h_chi_q} (should be exactly 1.0)')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 2. LIGO gravitational wave events\n", "Compute D3 invariants for real detected black holes"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "events = {\n",
    "    'GW150914': (65,  0.67, 0),\n",
    "    'GW170814': (53,  0.81, 0),\n",
    "    'GW190521': (150, 0.69, 0),\n",
    "    'Sgr A*':   (4e6, 0.90, 0),\n",
    "    'M87*':     (6.5e9, 0.90, 0),\n",
    "}\n",
    "\n",
    "print(f'{\"Event\":<12} {\"M [Msun]\":<12} {\"chi\":<6} {\"r_s [m]\":<14} {\"R_total [m]\":<14} {\"h(chi,q)\"}')\n",
    "print('-'*70)\n",
    "for name, (M, chi, q) in events.items():\n",
    "    bh = blackhole(M, chi=chi, q=q)\n",
    "    print(f'{name:<12} {M:<12.2e} {chi:<6.2f} {bh.r_s_m:<14.4e} {bh.R_total_m:<14.4e} {bh.h_chi_q:.6f}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 3. Spin suppression f(chi) — Paper 2"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "chis = np.linspace(0, 0.999, 200)\n",
    "f_vals = [blackhole(10, chi=c).f_chi for c in chis]\n",
    "h_vals = [blackhole(10, chi=c).h_chi_q for c in chis]\n",
    "\n",
    "plt.figure(figsize=(9, 5))\n",
    "plt.plot(chis, f_vals, 'b-', lw=2, label=r'$f(\\chi) = 2\\sqrt{1-\\chi^2}/(1+\\sqrt{1-\\chi^2})$  [Paper 2]')\n",
    "plt.axhline(1.0, color='gray', lw=1, ls='--', alpha=0.5, label='Schwarzschild: f=1')\n",
    "plt.axhline(0.0, color='red', lw=1, ls='--', alpha=0.5, label='Extremal: f→0')\n",
    "plt.xlabel('Spin parameter χ', fontsize=12)\n",
    "plt.ylabel('Suppression factor f(χ) = R_total/r_s', fontsize=12)\n",
    "plt.title('D3 Kerr spin suppression — Paper 2\\nR_total = f(χ)·r_s', fontsize=12)\n",
    "plt.legend(fontsize=10)\n",
    "plt.grid(alpha=0.2)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 4. KN master formula h(chi,q) — Paper 7\n", "Full parameter space scan"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2D contour plot of h(chi,q)\n",
    "n = 80\n",
    "chis = np.linspace(0, 0.99, n)\n",
    "qs   = np.linspace(0, 0.99, n)\n",
    "H = np.zeros((n, n))\n",
    "\n",
    "for i, chi in enumerate(chis):\n",
    "    for j, q in enumerate(qs):\n",
    "        if chi**2 + q**2 < 0.999:\n",
    "            H[j, i] = blackhole(10, chi=chi, q=q).h_chi_q\n",
    "        else:\n",
    "            H[j, i] = np.nan\n",
    "\n",
    "plt.figure(figsize=(8, 7))\n",
    "cf = plt.contourf(chis, qs, H, levels=20, cmap='Blues_r')\n",
    "plt.colorbar(cf, label='h(χ,q) = R_total/r_s')\n",
    "\n",
    "# Draw extremal boundary chi^2+q^2=1\n",
    "theta = np.linspace(0, np.pi/2, 100)\n",
    "plt.plot(np.cos(theta), np.sin(theta), 'r--', lw=1.5, label='Extremal: χ²+q²=1')\n",
    "\n",
    "plt.xlabel('Spin χ', fontsize=12)\n",
    "plt.ylabel('Charge q', fontsize=12)\n",
    "plt.title('KN master formula h(χ,q) — Paper 7\\nh(χ,q) = 4σ/(2(1+σ)−q²), σ=√(1−χ²−q²)', fontsize=11)\n",
    "plt.legend(fontsize=10)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 5. QG boundary power law — Paper 5\n", "D3/r_s = (M_QG/M)² — quantum gravity enters below M_QG"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "masses = np.logspace(-8, 35, 200)  # Planck mass to supermassive BH\n",
    "M_sun = 1.989e30\n",
    "\n",
    "ratios = [blackhole(m/M_sun).D3_over_rs for m in masses]\n",
    "M_QG = blackhole(1.0).M_QG_kg\n",
    "\n",
    "plt.figure(figsize=(9, 5))\n",
    "plt.loglog(masses, ratios, 'b-', lw=2, label=r'$D3/r_s = (M_{QG}/M)^2$  [Paper 5]')\n",
    "plt.axvline(M_QG, color='red', lw=1.5, ls='--', label=f'M_QG = {M_QG:.3e} kg')\n",
    "plt.axvline(M_sun, color='green', lw=1, ls=':', alpha=0.7, label='1 solar mass')\n",
    "plt.axhline(1.0, color='gray', lw=1, ls='--', alpha=0.5, label='D3/r_s = 1 (QG regime)')\n",
    "plt.xlabel('Black hole mass M [kg]', fontsize=12)\n",
    "plt.ylabel('D3/r_s = (M_QG/M)²', fontsize=12)\n",
    "plt.title('Quantum gravity boundary — Paper 5\\nQG effects dominate when M < M_QG', fontsize=11)\n",
    "plt.legend(fontsize=10)\n",
    "plt.grid(alpha=0.15)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 6. Computation limits — Landauer and D3\n", "Two fundamental limits on any computation"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "systems = {\n",
    "    'Room temp chip (300K)':    compute(300,    1e9),\n",
    "    'Cryo classical (77K)':     compute(77,     1e10),\n",
    "    'Quantum chip (15mK)':      compute(0.015,  1e6),\n",
    "    'Fusion plasma (150MK)':    compute(1.5e8,  1e15),\n",
    "    'LHC collision (5.5TK)':    compute(5.5e12, 1e18),\n",
    "}\n",
    "\n",
    "print(f'{\"System\":<28} {\"Landauer [J/bit]\":<20} {\"D3 [m/bit]\":<20} {\"Ratio [m/J]\"}')\n",
    "print('-'*85)\n",
    "for name, r in systems.items():\n",
    "    print(f'{name:<28} {r.landauer_J_per_bit:<20.4e} {r.D3_m_per_bit:<20.4e} {r.ratio_universal_m_per_J:.4e}')\n",
    "\n",
    "print()\n",
    "print('Note: ratio_universal = 2G/c^4 = 1.6525e-44 m/J for ALL systems')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 7. AdS correction — Paper 9\n", "R_total(AdS) = r_s*(1+(r_s/L)^2), phi(1)=2 at Hawking-Page"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# phi(x) = 1 + x^2 where x = r_s/L\n",
    "x = np.linspace(0, 3, 300)\n",
    "phi = 1 + x**2\n",
    "\n",
    "plt.figure(figsize=(8, 5))\n",
    "plt.plot(x, phi, 'b-', lw=2.5, label=r'$\\phi(x) = 1 + (r_s/L)^2$  [Paper 9]')\n",
    "plt.axhline(1, color='gray', lw=1, ls='--', alpha=0.5, label='Flat space: φ=1 (Paper 3)')\n",
    "plt.axvline(1, color='red', lw=1.2, ls='-.', alpha=0.6, label='Hawking-Page: r_s=L, φ=2')\n",
    "plt.scatter([1, np.sqrt(2), 2], [2, 3, 5], s=80, zorder=5,\n",
    "    color=['red','purple','green'],\n",
    "    label='Integer values: φ(1)=2, φ(√2)=3, φ(2)=5')\n",
    "plt.xlabel(r'$x = r_s/L$', fontsize=12)\n",
    "plt.ylabel(r'$\\phi(x) = R_{\\rm total}/r_s$', fontsize=12)\n",
    "plt.title('AdS correction factor — Paper 9', fontsize=12)\n",
    "plt.legend(fontsize=9)\n",
    "plt.grid(alpha=0.15)\n",
    "plt.ylim(0, 11)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 8. Export for your paper\n", "LaTeX table and BibTeX citation"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# LaTeX table ready to paste into your paper\n",
    "bh = blackhole(30, chi=0.67)\n",
    "print('=== LaTeX table ===')\n",
    "print(bh.to_latex())\n",
    "print()\n",
    "\n",
    "# BibTeX citation\n",
    "p3 = get_paper(3)\n",
    "print('=== BibTeX ===')\n",
    "print(p3.bibtex())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Links\n",
    "- **Web calculator**: https://phenex-d3.vercel.app\n",
    "- **Documentation**: https://phenex-d3.vercel.app/docs.html\n",
    "- **REST API**: https://phenex-d3.vercel.app/api/blackhole\n",
    "- **GitHub**: https://github.com/bsharma173860-oss/d3-research\n",
    "- **Contact**: bsharma173860@gmail.com"
   ]
  }
 ]
}
