From 58bfc4f50ee08bf10df464c7d886a646f4a03377 Mon Sep 17 00:00:00 2001
From: Luke Naylor <l.naylor@sms.ed.ac.uk>
Date: Wed, 21 Jun 2023 21:41:12 +0100
Subject: [PATCH] generate table for third recurring ex (via lua)

---
 main.tex              | 79 +++++++++++++++++++++++++++++++++++++++++++
 plot_playground.ipynb | 35 +++++++------------
 2 files changed, 92 insertions(+), 22 deletions(-)

diff --git a/main.tex b/main.tex
index a0ce7aa..634c090 100644
--- a/main.tex
+++ b/main.tex
@@ -1690,6 +1690,85 @@ Using the above theorem \ref{thm:rmax_with_eps1},
 TODO fill in values
 \end{example}
 
+\begin{sagesilent}
+import numpy as np
+
+def bound_comparisons(example):
+    n = example.b.denominator()
+    a_v = example.b.numerator()
+
+    def theorem_bound(v_twisted, q_val, k):
+      return int(min(
+        n^2*q_val^2/k
+      ,
+        v_twisted.ch[0]
+        + n^2*(v_twisted.ch[1] - q_val)^2/k
+      ))
+
+    def k_1(n, a_v, b_q):
+      n = int(n)
+      a_v = int(a_v)
+      b_q = int(b_q)
+      k = -a_v*b_q % n
+      return k if k > 0 else k + n
+
+    def k_2(n, a_v, b_q):
+      n = int(n)
+      a_v = int(a_v)
+      b_q = int(b_q)
+      a_v_inv = inverse_mod(a_v, n)
+      modulo = n*gcd(n, a_v^2)
+      k = (a_v^2*a_v_inv*b_q - 2*a_v*b_q) % modulo
+      return k if k > 0 else k + modulo
+
+    b_qs = list(range(example.twisted.ch[1]*n+1))
+    qs = list(map(lambda x: x/n,b_qs))
+    k_1s = list(map(lambda b_q: k_1(n, a_v, b_q), b_qs))
+    k_2s = list(map(lambda b_q: k_2(n, a_v, b_q), b_qs))
+    theorem2_bounds = [
+        theorem_bound(example.twisted, q_val, 1)
+        for q_val in qs
+    ]
+    theorem31_bounds = [
+        theorem_bound(example.twisted, q_val, k)
+        for q_val, k in zip(qs,k_1s)
+    ]
+    theorem32_bounds = [
+        theorem_bound(example.twisted, q_val, k)
+        for q_val, k in zip(qs,k_2s)
+    ]
+    return qs, theorem2_bounds, theorem31_bounds, theorem32_bounds
+
+qs, theorem2_bounds, theorem31_bounds, theorem32_bounds = bound_comparisons(recurring)
+\end{sagesilent}
+
+\directlua{ table_width = 3*4+1 }
+\directlua{ table_width = 3*4+1 }\begin{tabular}{l\directlua{for i=0,table_width-1 do tex.sprint([[|c]]) end}}
+	$q=\chern_1^\beta(u)$
+\directlua{for i=0,table_width-1 do
+	local cell = [[&$\noexpand\sage{qs[]] .. i .. "]}$"
+  tex.sprint(cell)
+end}
+	\\ \hline
+	Thm \ref{thm:rmax_with_uniform_eps}
+\directlua{for i=0,table_width-1 do
+	local cell = [[&$\noexpand\sage{theorem2_bounds[]] .. i .. "]}$"
+  tex.sprint(cell)
+end}
+	\\
+	Thm \ref{thm:rmax_with_eps1} (i=1)
+\directlua{for i=0,table_width-1 do
+	local cell = [[&$\noexpand\sage{theorem31_bounds[]] .. i .. "]}$"
+  tex.sprint(cell)
+end}
+	\\
+	Thm \ref{thm:rmax_with_eps1} (i=2)
+\directlua{for i=0,table_width-1 do
+	local cell = [[&$\noexpand\sage{theorem32_bounds[]] .. i .. "]}$"
+  tex.sprint(cell)
+end}
+\end{tabular}
+
 \minorheading{Irrational $\beta$}
 
 \egroup % end scope where beta redefined to beta_{-}
diff --git a/plot_playground.ipynb b/plot_playground.ipynb
index 9980c61..ee71a14 100644
--- a/plot_playground.ipynb
+++ b/plot_playground.ipynb
@@ -26,7 +26,7 @@
        "$\\displaystyle \\text{Chern Character:} \\\\ \\begin{array}{l} \\mathrm{ch}_{0} = 3 \\\\ \\mathrm{ch}_{1} = 2 \\ell^{1} \\\\ \\mathrm{ch}_{2} = -2 \\ell^{2} \\end{array}$"
       ],
       "text/plain": [
-       "<pseudowalls.chern_character.Chern_Char object at 0x7f470ae36ed0>"
+       "<pseudowalls.chern_character.Chern_Char object at 0x7f92a8a20dd0>"
       ]
      },
      "execution_count": 2,
@@ -109,7 +109,7 @@
        "$\\displaystyle \\text{ Twisted Chern Character for $\\beta={ -\\frac{2}{3} }$ } \\\\ \\begin{array}{l} \\mathrm{ch}_{0} = 3 \\\\ \\mathrm{ch}_{1} = 4 \\ell^{1} \\\\ \\mathrm{ch}_{2} = 0 \\ell^{2} \\end{array}$"
       ],
       "text/plain": [
-       "<pseudowalls.chern_character.Twisted_Chern_Char object at 0x7f470084cf10>"
+       "<pseudowalls.chern_character.Twisted_Chern_Char object at 0x7f929e8cf290>"
       ]
      },
      "execution_count": 5,
@@ -136,7 +136,7 @@
        "$\\displaystyle \\text{Chern Character:} \\\\ \\begin{array}{l} \\mathrm{ch}_{0} = 1 \\\\ \\mathrm{ch}_{1} = 0 \\ell^{1} \\\\ \\mathrm{ch}_{2} = 0 \\ell^{2} \\end{array}$"
       ],
       "text/plain": [
-       "<pseudowalls.chern_character.Chern_Char object at 0x7f47007c9ad0>"
+       "<pseudowalls.chern_character.Chern_Char object at 0x7f929e953810>"
       ]
      },
      "execution_count": 6,
@@ -275,7 +275,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 16,
    "id": "3013a646",
    "metadata": {},
    "outputs": [
@@ -310,18 +310,11 @@
     "recurring.b = beta_minus(recurring.chern)\n",
     "recurring.twisted = recurring.chern.twist(recurring.b)\n",
     "\n",
-    "def bound_comparisons():\n",
-    "    n = recurring.b.denominator()\n",
-    "    a_v = recurring.b.numerator()\n",
+    "def bound_comparisons(example):\n",
+    "    n = example.b.denominator()\n",
+    "    a_v = example.b.numerator()\n",
     "\n",
-    "    def theorem2_bound(v_twisted, q_val):\n",
-    "      return min(\n",
-    "        n^2*q_val^2\n",
-    "      ,\n",
-    "        n^2*(v_twisted.ch[1]-q_val)^2 + v_twisted.ch[0]\n",
-    "      )\n",
-    "\n",
-    "    def theorem3_bound(v_twisted, q_val, k):\n",
+    "    def theorem_bound(v_twisted, q_val, k):\n",
     "      return min(\n",
     "        n^2*q_val^2/k\n",
     "      ,\n",
@@ -345,27 +338,25 @@
     "      k = (a_v^2*a_v_inv*b_q - 2*a_v*b_q) % modulo\n",
     "      return k if k > 0 else k + modulo\n",
     "\n",
-    "    b_qs = list(range(recurring.twisted.ch[1]*n+1))\n",
+    "    b_qs = list(range(example.twisted.ch[1]*n+1))\n",
     "    qs = list(map(lambda x: x/n,b_qs))\n",
     "    k_1s = list(map(lambda b_q: k_1(n, a_v, b_q), b_qs))\n",
     "    k_2s = list(map(lambda b_q: k_2(n, a_v, b_q), b_qs))\n",
     "    theorem2_bounds = [\n",
-    "        theorem2_bound(recurring.twisted, q_val)\n",
+    "        theorem_bound(example.twisted, q_val, 1)\n",
     "        for q_val in qs\n",
     "    ]\n",
     "    theorem31_bounds = [\n",
-    "        theorem3_bound(recurring.twisted, q_val, k)\n",
+    "        theorem_bound(example.twisted, q_val, k)\n",
     "        for q_val, k in zip(qs,k_1s)\n",
     "    ]\n",
     "    theorem32_bounds = [\n",
-    "        theorem3_bound(recurring.twisted, q_val, k)\n",
+    "        theorem_bound(example.twisted, q_val, k)\n",
     "        for q_val, k in zip(qs,k_2s)\n",
     "    ]\n",
     "    return qs, theorem2_bounds, theorem31_bounds, theorem32_bounds\n",
     "\n",
-    "qs, theorem2_bounds, theorem31_bounds, theorem32_bounds = bound_comparisons()\n",
-    "\n",
-    "print(np.array([qs, theorem2_bounds, theorem31_bounds, theorem32_bounds]))"
+    "print(np.array(list(bound_comparisons(recurring))))"
    ]
   },
   {
-- 
GitLab