{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(octahedral:oct-sym)=\n",
    "# Octahedral Symmetry\n",
    "\n",
    "The six vertices of the octahedron can be taken as identical to the six edge\n",
    "midpoints of the tetrahedron. As such they have $t(u,v)$ as their polynomial\n",
    "invariant.\n",
    "\n",
    "The octahedral symmetry group is generated by transformations $I$ and $II$\n",
    "above, along with\n",
    "\n",
    "$$\n",
    "III: \\quad u'=e^{i\\pi/4}\\, u \\,,\\quad v' = e^{-i\\pi/4} \\,v \\,.\n",
    "$$\n",
    "\n",
    "Under transformation $III$ with $A=e^{i\\pi/4} = D^*$, $B=C=0$, we find  that\n",
    "\n",
    "$$\n",
    "\n",
    "\\begin{align*}\n",
    "t(u',v') &= AA^*\\,uv(A^2\\,u^2-A^{*2}\\,v^2)(A^2\\,u^2+A^{*2}\\,v^2) \\\\\n",
    "&= -t(u,v) \\,.\n",
    "\\end{align*}\n",
    "\n",
    "$$\n",
    "\n",
    "Therefore, only $t^2(u,v)$ is an absolute invariant under the octahedral\n",
    "symmetry group."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The 8  face centers of the octahedron are formed by combining the 8 tetrahedral\n",
    "roots $\\{k_i, \\bar{k}_i\\}$ found before. As such, the octahedral polynomial\n",
    "invariant for the face centers is given by\n",
    "\n",
    "$$\n",
    "\n",
    "W(u, v) := \\Phi(u,v)\\, \\Psi(u,v)  = u^8 + 14\\,u^4v^4+v^8\\,.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{8} + 14 u^{4} v^{4} + v^{8}$"
      ],
      "text/plain": [
       "u**8 + 14*u**4*v**4 + v**8"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check of the above:\n",
    "from sympy import I, diff, simplify, sqrt, symbols\n",
    "from tetra import Phi, Psi, t\n",
    "from functools import reduce\n",
    "\n",
    "u, v = symbols(\"u v\")\n",
    "W = simplify(Phi * Psi)\n",
    "W"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In order to work out the transformation properties of $W(u,v)$, it is useful to\n",
    "note that $t$ and $W$ are inter-related as follows:\n",
    "\n",
    "$$\n",
    "\n",
    "{\\rm Hess}[t] := \\det\\left[\\begin{matrix}\\frac{\\partial^2t}{\\partial u^2} & \\frac{\\partial^2t}{\\partial u\\partial v} \\\\[6pt] \\frac{\\partial^2t}{\\partial v \\partial u} & \\frac{\\partial^2t}{\\partial v^2}\\end{matrix}\\right] = -25\\,W(u,v)\\,.\n",
    "\n",
    "$$\n",
    "\n",
    "In other words, $W(u,v)$ is the *Hessian* of $t(u,v)$. As such, since $t \\to -t$\n",
    "under transformation $III$ (and since $W \\sim t^2$), $W(u,v)$ is clearly\n",
    "invariant under all three octahedral symmetry generators."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check of the above:\n",
    "def hessian(f, u, v):\n",
    "    du2 = diff(diff(f, u), u)\n",
    "    dudv = diff(diff(f, u), v)\n",
    "    dv2 = diff(diff(f, v), v)\n",
    "    return du2 * dv2 - dudv**2\n",
    "\n",
    "\n",
    "hessian(t, u, v).equals(-25 * Phi * Psi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The edge midpoints of the octahedron form a polynomial invariant, $\\chi(u,v)$,\n",
    "which we will compute next.\n",
    "\n",
    "The edge midpoints can be labeled as follows:\n",
    "\n",
    "$$\n",
    "\\begin{matrix}\n",
    "{\\bf X}_1 = \\tfrac{1}{\\sqrt{2}}(1,1,0) \\quad &\n",
    "{\\bf X}_2 = \\tfrac{1}{\\sqrt{2}}(-1,1,0) \\quad &\n",
    "{\\bf X}_3 = \\tfrac{1}{\\sqrt{2}}(-1,-1,0) \\quad &\n",
    "{\\bf X}_4 = \\tfrac{1}{\\sqrt{2}}(1,-1,0) \\\\\n",
    "{\\bf X}_5 = \\tfrac{1}{\\sqrt{2}}(1,0,1) \\quad &\n",
    "{\\bf X}_6 = \\tfrac{1}{\\sqrt{2}}(0,1,1) \\quad &\n",
    "{\\bf X}_7 = \\tfrac{1}{\\sqrt{2}}(-1,0,1) \\quad &\n",
    "{\\bf X}_8 = \\tfrac{1}{\\sqrt{2}}(0,-1,1) \\\\\n",
    "{\\bf X}_9 = \\tfrac{1}{\\sqrt{2}}(1,0,-1) \\quad &\n",
    "{\\bf X}_{10} = \\tfrac{1}{\\sqrt{2}}(0,1,-1) \\quad &\n",
    "{\\bf X}_{11} = \\tfrac{1}{\\sqrt{2}}(-1,0,-1) \\quad &\n",
    "{\\bf X}_{12} = \\tfrac{1}{\\sqrt{2}}(0,-1,-1)\n",
    "\\end{matrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The corresponding stereographically-projected points in the complex plane are\n",
    "given by \n",
    "\n",
    "$$\n",
    "\\begin{matrix}\n",
    "l_1 = \\tfrac{1}{\\sqrt{2}}(1 + i) \\quad &\n",
    "l_2 = \\tfrac{1}{\\sqrt{2}}(-1 + i) \\quad &\n",
    "l_3 = \\tfrac{1}{\\sqrt{2}}(-1 - i) \\quad &\n",
    "l_4 = \\tfrac{1}{\\sqrt{2}}(1 - i) \\\\\n",
    "l_5 = 1 + \\sqrt{2} \\quad &\n",
    "l_6 = i(1 + \\sqrt{2}) \\quad &\n",
    "l_7 = -1 - \\sqrt{2} \\quad &\n",
    "l_8 = -i(1 + \\sqrt{2}) \\\\\n",
    "l_9 = -1 + \\sqrt{2} \\quad &\n",
    "l_{10} = i(-1 + \\sqrt{2}) \\quad &\n",
    "l_{11} = 1 - \\sqrt{2} \\quad &\n",
    "l_{12} = i(1 - \\sqrt{2})\n",
    "\\end{matrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "One way to compute $\\chi(u,v)$ is to blindly multiply together. Doing so gives\n",
    "\n",
    "$$\n",
    "\n",
    "\\chi(u,v)  := \\prod_{i=1}^{12}\\left(u-l_i\\,v\\right) = u^{12} - 33\\left(u^8\\,v^4+u^4\\,v^8\\right) + v^{12} \\,.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{12} - 33 u^{8} v^{4} - 33 u^{4} v^{8} + v^{12}$"
      ],
      "text/plain": [
       "u**12 - 33*u**8*v**4 - 33*u**4*v**8 + v**12"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check of the above:\n",
    "def stereo(v1, v2, v3):\n",
    "    return (v1 + I * v2) / (1 - v3)\n",
    "\n",
    "\n",
    "ls = []\n",
    "\n",
    "ls.append(stereo(1 / sqrt(2), 1 / sqrt(2), 0))\n",
    "ls.append(stereo(1 / sqrt(2), -1 / sqrt(2), 0))\n",
    "ls.append(stereo(-1 / sqrt(2), 1 / sqrt(2), 0))\n",
    "ls.append(stereo(-1 / sqrt(2), -1 / sqrt(2), 0))\n",
    "ls.append(stereo(0, 1 / sqrt(2), 1 / sqrt(2)))\n",
    "ls.append(stereo(0, 1 / sqrt(2), -1 / sqrt(2)))\n",
    "ls.append(stereo(0, -1 / sqrt(2), 1 / sqrt(2)))\n",
    "ls.append(stereo(0, -1 / sqrt(2), -1 / sqrt(2)))\n",
    "ls.append(stereo(1 / sqrt(2), 0, 1 / sqrt(2)))\n",
    "ls.append(stereo(1 / sqrt(2), 0, -1 / sqrt(2)))\n",
    "ls.append(stereo(-1 / sqrt(2), 0, 1 / sqrt(2)))\n",
    "ls.append(stereo(-1 / sqrt(2), 0, -1 / sqrt(2)))\n",
    "\n",
    "chi = reduce(lambda x, y: x * y, [u - x * v for x in ls])\n",
    "simplify(chi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alternatively, we can make use of the four-fold symmetry relating the midpoints\n",
    "\n",
    "$$\n",
    "\n",
    "(l_1, l_2=i\\,l_1, l_3=i^2\\,l_1, l_4=i^3\\,l_1)\n",
    "\n",
    "$$\n",
    "\n",
    "and similarly for $(l_5, l_6, l_7, l_8)$, $(l_9, l_{10}, l_{11}, l_{12})$. Grouping in this way, we can write\n",
    "\n",
    "$$\n",
    "\n",
    "\\chi(u,v) = \\chi_{\\rm part}(u,v, l_1) \\, \\chi_{\\rm part}(u,v, l_5) \\, \\chi_{\\rm part}(u,v, l_9)\n",
    "\n",
    "$$\n",
    "\n",
    "where each $\\chi_{\\rm part}(u,v,x)$ is given by\n",
    "\n",
    "$$\n",
    "\n",
    "\\chi_{\\rm part}(u,v,x) = \\prod_{k=1}^4\\left(u-i^k\\,x\\,v\\right) = u^4-x^4\\,v^4 \\,.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{4} - v^{4} x^{4}$"
      ],
      "text/plain": [
       "u**4 - v**4*x**4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check of the above\n",
    "x = symbols(\"x\")\n",
    "\n",
    "\n",
    "def reduce_multiply(any_list):\n",
    "    return reduce(lambda x, y: x * y, any_list)\n",
    "\n",
    "\n",
    "expr = reduce_multiply([u - x * I**k * v for k in range(4)])\n",
    "simplify(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{4} + v^{4}$"
      ],
      "text/plain": [
       "u**4 + v**4"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chi_part1 = expr.subs(x, 1 / sqrt(2) * (1 + I)).expand()\n",
    "chi_part1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{4} - 17 v^{4} - 12 \\sqrt{2} v^{4}$"
      ],
      "text/plain": [
       "u**4 - 17*v**4 - 12*sqrt(2)*v**4"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chi_part5 = expr.subs(x, 1 + sqrt(2)).expand()\n",
    "chi_part5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{4} - 17 v^{4} + 12 \\sqrt{2} v^{4}$"
      ],
      "text/plain": [
       "u**4 - 17*v**4 + 12*sqrt(2)*v**4"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chi_part9 = expr.subs(x, -1 + sqrt(2)).expand()\n",
    "chi_part9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle u^{12} - 33 u^{8} v^{4} - 33 u^{4} v^{8} + v^{12}$"
      ],
      "text/plain": [
       "u**12 - 33*u**8*v**4 - 33*u**4*v**8 + v**12"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chi = (chi_part1 * chi_part5 * chi_part9).expand()\n",
    "chi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As it turns out, $\\chi(u,v)$ is also related to $t(u,v)$ and $W(u,v)$: $\\chi$ is\n",
    "proportional to the *Jacobian* of ${\\bf V}(u,v) := [t(u,v), W(u,v)]$:\n",
    "\n",
    "$$\n",
    "\n",
    "{\\textrm Jac}[{\\bf V}](u,v) := \\det \\left[\\begin{matrix} \\frac{\\partial t}{\\partial u} & \\frac{\\partial t}{\\partial v} \\\\[6pt] \\frac{\\partial W}{\\partial u} & \\frac{\\partial W}{\\partial v} \\end{matrix}\\right] = -8\\,\\chi(u,v) \\,.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check of the above:\n",
    "def jacobian(f, g, u, v):\n",
    "    return diff(f, u) * diff(g, v) - diff(f, v) * diff(g, u)\n",
    "\n",
    "\n",
    "jacobian(t, W, u, v).equals(-8 * chi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since $\\chi \\sim t$, and since $t\\to-t$ under transformation $III$, we deduce\n",
    "that $\\chi^2$ is an absolute invariant of the octahedral symmetry group. \n",
    "\n",
    "Lastly,\n",
    "by direct computation we can verify that the absolute invariants $\\chi^2$,\n",
    "$W^3$, and $t^4$ (all sharing the same order of homogeneity) are inter-related:\n",
    "\n",
    "$$\n",
    "\n",
    "\\chi^2 - W^3 + 108\\, t^4 = 0 \\,.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - 108 u^{4} v^{4} \\left(u - v\\right)^{4} \\left(u + v\\right)^{4} \\left(u^{2} + v^{2}\\right)^{4}$"
      ],
      "text/plain": [
       "-108*u**4*v**4*(u - v)**4*(u + v)**4*(u**2 + v**2)**4"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check of the above:\n",
    "simplify(chi**2 - W**3).factor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Second check:\n",
    "(chi**2 - W**3).equals(-108 * t**4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ag_notes",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}