{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Computing the Elements of the Local Clifford Group\n",
    "\n",
    "From Anders&Briegel 2005 it is known, that the Local Clifford Group (LC) has 24 elements.\n",
    "Also one can disregrad a global phase. Below are the computed elements."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from itertools import product\n",
    "from functools import reduce\n",
    "from operator import iconcat\n",
    "import sympy\n",
    "i = sympy.I\n",
    "exp = sympy.exp\n",
    "M = sympy.Matrix\n",
    "simplify = sympy.simplify\n",
    "from sympy.physics.quantum.dagger import Dagger\n",
    "\n",
    "sympy.init_printing()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "I = M([[1, 0], [0, 1]])\n",
    "X = M([[0, 1], [1, 0]])\n",
    "Y = M([[0, -i], [i, 0]])\n",
    "Z = M([[1, 0], [0, -1]])\n",
    "O = M([[0, 0], [0, 0]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "H = M([[1, 1], [1, -1]]) / sympy.sqrt(2)\n",
    "S = M([[1, 0], [0, i]])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAAA/CAYAAADjVebQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAF6UlEQVR4Ae2ci5EUNxCGb68IAF8IOANwCEsGEMJBBnYRgYsQcAoXAnYG4AwgBHwZrL9/kFQa3bzVmodqp0o3kkZq9d+/WjOrx51ubm7OhM+E9Pp+uVx+TTOv6TIWOJ1OX5H8skP622dR5usoruiPJH1NlrXAPeLvkiYa5wkk4TV/JwWyk/SOy5gQ2j2Nldnjc7A9oNebMd2m4qPcv6ks2nhU3m36wCpNA++Q9V5KDgWr9taU47B9HsLln1noFTzJQlgi4y2K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w2ePVgVx2TGfRZnkSjmp+r8lRF7BVd8VzszrMmn7qgvfnDHZVEaJWnKrpIifNysTuCtEIw+VQJZeeT5JWm8uyTB9SRB+7+VIXH2Hdfgt0RNBs/bWWRNOvkgSMo7BcnrR61y1MVfeT4fPSehT0iaDZ+2lpOkmt40skDkUEocurAG27tO3gmYY8IWoTfgqRJJw9cQ/oMbYW1DWvZHlgmYXckyRta2JWeog/lGk/KWqrgs7PaUxUYaPBaAzttiKTspYrdnDwYtGiZh6thn/xjFlblsp0XzzTjvejC7YsuDKKb5s7+ITxZlBxQWBOkYafT1tgnk1TamAMGy3qE3o8IyNq5tDX22ywLXCuvYoHJnjSkjRtSPrgy+uTWddh/8vRT/el/S+M3IQk4m29on27SIiWL4z+jNsPu8vUk1SesvqE9R2fLuqXwI7f5nWT1TjKZjkepo15F8ZsMd/TKqjfsj/Wc0vitPCng4CVa9Yb9ALQnUgK/KUkoqC+7ajfs9/ASskvhNxnupKVXENevcsN+YKInUhK/iSc5BavdsN/DS8gujT9rFtxriZL6VHwyN4ZXFZ2X8+1vfS+F38nNngVv7AMZVW/YH+sEpfGH4Q7W0s31Wiu6XitZAPt/TTmg6WZ00nCkyG8duvygh4Tp+o7n1yxDC0CQfrrcdYj88j/xBryWF0SjzAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡√2   √2 ⎤\n",
       "⎢──   ── ⎥\n",
       "⎢2    2  ⎥\n",
       "⎢        ⎥\n",
       "⎢√2  -√2 ⎥\n",
       "⎢──  ────⎥\n",
       "⎣2    2  ⎦"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "H"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata":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v3vIynR95Q3alBA0Ru/UREyV5BR0mVWv0Fn91WWFJPowOgdUNyISWswGHrdMZPu15p7bx5HUvtiqtFS+2IpO/1mHJl29amxu1OvaB5tzIBtOLy4PzH+BYFD/CuL/K+XAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}1 & 0\\\\0 & i\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1  0⎤\n",
       "⎢    ⎥\n",
       "⎣0  ⅈ⎦"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "s2m = {\"H\": H, \"S\": S}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evalstr(s):\n",
    "    m = I\n",
    "    \n",
    "    for c in s:\n",
    "        m *= s2m[c]\n",
    "    \n",
    "    m.simplify()\n",
    "    \n",
    "    return m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAA/CAYAAADuS5aXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGrklEQVR4Ae2bjXHcNhCFdRoV4KiESwd20sG5A6sEyR044woyTgdOCyrBSQdWOrA7iK0Ozt+jAQxJ8Qc4LEmQOs7wiD9i9+3DLnkAsbu4uDhwfuJsH1+Px+Ov7cJzfl4L7Ha7ByS+7JB6c1UrfF1LK/mtlT9nl7HALWKvW6IrZwvk4WX/tBpkZxk1x7FOkLsba1NiPdju0evNmG65+Lj/v7YMZD+q7LJdYZVHwB19vZXyQ6eVvDn7cdg+DeHydVPqFTxvAiE3AGiH4gnELNJlMjYIf4Gm19jkq5XGk5CHou9Q8KOUdEq/dwrv3fUWEJXru/xqLnVsUjoBn2zwP+dfus/qONARtjzqx+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X1GHJsyKO/xk4a8mIz7F8grVkYlZl8gGqlt0U/YGpgV58Oqyl++qzIMw2bLkRscpeQWBg6erDrlsFVCO5T5NPS2Um7iJLCJkLkOZvcJTTmfbnYnSdq7jdsOiGtvF5W5KZRX5HTLj1scpOIlrAngiiTAuFZ12UI6jXCitwl1KVvvQy9s7A74hr46VOOILtpFSYQWpfblaZtOnm+I25O3knDPVK0+F1CHmPf9RTs6msIv7NL9C4i2meRp5ESvI/0oNdRL+LCfgbSGoEm3+33GXmqcvROwl4jrhM//YWQKbvE6E2708lzCkXtpEGQ9zgR5k+tQETF9xgwc7dB9yjszk6D+OlLgyFpFxHts8mTUHUiQsKoahvStZGXNs52uzXlwRKF3ZEnGzWwK+/xkpbnJe0ion1FXtaSEK+5m90lhIEGjyWxI1vkZS8JFb+TZpCBvMrFsV/F6g/bcv3OgzqtIJx0ED4mXbBFN4Wlfzl1jT00sRy+fJsKe58ysTaJJi+2wz6FlipH70dkZ33JVir2y6WMepabb4FozxsS5UJTzLLHUDebqJvTFibkYfViNl8UMAJms4VV2Cxm80UB5M1mCyvyBpc9CjDonCrMZguTsMnb2LPZaDI2Cua0hZXnBUw8sDVdpumjrNfz0OGKE1PbwpQ8lN1j62ex0WRsTM1hC5OwKSBeWcLG5jeaxBI3tS1MPM8Rp2WezW80iSRuFltkrSp4IJCnWe4nc4eMvEnnLb38kq5z2MLJyF5VqOwGSc9mo8nYQJnTFiFswmZ7U4jW6s7HwhaAl4c2N6hURTmFNSV+69DxG6MoLIt01J+LZrAAxOmv13WHqM8/AMxjWc93eaBGAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡√2   √2⋅ⅈ ⎤\n",
       "⎢──   ──── ⎥\n",
       "⎢2     2   ⎥\n",
       "⎢          ⎥\n",
       "⎢√2  -√2⋅ⅈ ⎥\n",
       "⎢──  ──────⎥\n",
       "⎣2     2   ⎦"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHUAAAA/CAYAAADex4e2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGc0lEQVR4Ae2cgXHcKBiFvR4XkHMJmw6Suw42Hdgl2OkgN6ngJtdB0oJLyKWD+DpIOrjEHex9T0YEsVoJCdAiaTWDBQKh/70HP1oQ3lxcXOwInwn+8X2/37/0L57TZTCw2WweseRVizW3V87FN05c0R9e+pwsi4E7zLn2TKo6pxWVXvmPVyBpkpa176sQGzZ9ZeaUD+YH7L3ps3kMbu7516+X5z3p2qWfkSPNw+6p962M7wo5nn2qOg3mz11467zUNtqemrpir75bAPju3SuyuOTJMGcXlRb7Drk+SjLiLzi9V5xj+3y6uEPwym2Y9OxPLmaBOQXuHc+F173+JA/ULRdU1Uv8Yx3XWWnCN/faEuJgsphrnC6uXLip9yehGsOzicoD1EtvakDEpeTOSau36tqr+trcz2BpYBYegzE7bp5TiZrN/RqX8wZQ7lj6lgd/FcolHkcwC+qkuKPefgGxJejNtu3Q2PnBzUDgTwR3/BRYTXIcvJ6795UUH4pZtp8C9yj3i626T6LJv7zAcDseK01ojCtuvuIcmg35Rmjc65crKY2tUZhz48a+NGMqFWm66oNLPmm9AB0dJ8nTWKrZj9kI6uEbjNkImhU3fCYTVW9btrdKKMLRXkqegD3UJBFXj93W6TmcsXcQZkfQrLixK42oxmC50aq3cj7aS8mrW6qErIPKz67HYnMQZkdQeaYas87JcVNnUlHVclWhjLWt0e91pox6dSP45eaQBkMQZiOquGlgVjo1TuqsRNUEugZ/ucuoyXTeCtVyrwmvqes758UfpWHGHol6d5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qivnIslZPLVCSd6ymHgeCeGmqycWshS0qhVS6i3JS8JBcVBYrZKFRYa5iMlxzut5iNQoWJOhkvOUTtXFIqjOgpzZmMl+TulzfCVW6Q6msdU/KSo6dafLwcaApRU2dRPx1shQuJ5OYlm6gYvkWD1W2Q6mt3U/CS3P0KVG04LmdVG6RCBc3NS/KeagTV0tqqNkgFCjoJL1GrNG1AEFUrBQfzqbTOrHO5bbaUdG0KXswzoldpDnhDvFVukDogwrswJS/W/aKyv5lJa6Xno1AG0OvR1wxTKw8pl6jI7y22/6B12WWmlvzzpRMygKD6uXjdYsLX/wHaFl8sK09oiAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2} i}{2} & - \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2     √2  ⎤\n",
       "⎢ ──     ──  ⎥\n",
       "⎢ 2      2   ⎥\n",
       "⎢            ⎥\n",
       "⎢√2⋅ⅈ  -√2⋅ⅈ ⎥\n",
       "⎢────  ──────⎥\n",
       "⎣ 2      2   ⎦"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAAA/CAYAAADjVebQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFvElEQVR4Ae2bi5EUNxCGb68IABPCkQE4hCUDCOEgA7uIwEUIOIULATsDcAYQAr4Mlu8X0lgr70MateahXVVpR9rRo//+1T0zemxubm62xE/ENHzb7XbP0z+v+TYa2Gw2X2j5xYHW3zyJ/nwVpZX8nuSv2bYauKf5Z0kXzngGkrCav5IC1VlGx+5cI/S7OVdmjffB/oDcr8/JHvBz/SctS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Z6qiLFplJDXC1PzFYAtnWCx4ydY07q0N+zBI93VqYoYm3C3xEfbboJVnZiSRHt7JwvIdzNDnmLzJDXDR3+OJFN3502/y1MVR7ChR5tTE2roVCiyJBrS/FyXpypqsXnLyj41kT4m0jzylLs7KonQLk9V1GLzBGkFQBtGTbZQ0045SYFpKhefLKCOLHDxpyrGYPMEmeNDliqSik4WeIKG/eLkNeIWeaoCuYqwRQSZ40OW8SR5wbJOFogM4qhTBcFyp74ibxa2iKAm+CxIyjpZ4DvSa+penFrxJf0haxY2T5JG+x425Uv6O1aWdpwlVS1V8FqqEdflqYolYEMGkVS9VDHZyQKEnTosBlv2xyysyqQPBu5pxntUwNRnXxhcOrZskpagzFGjIKPS0rHdZmC4FplZA9mWdEpO3MUk0/WnZGh5b258JiShoOYb1luSkNH27Pi2CIlbHr+epPpE8w3rNTJZ1p0LH/267ySrZ1LTDesIO3eYFZ+Ju2PUdr1hf258VpY0jHQesl1v2J8DnylJALiDrW437M+Fz8TdyYwCAFxDlxv258RnYkkeQLcb9ufGVzULHh5EgNCrYrcb9ufC5/utngV3POHiut6wPze+wd3BWrq5XmtF1zCRBtD/l5QDunbeSe5OiV8PyPKdEXQRB5MPYJ/8LwjSp4sWUNPw+Qf+0ryW275/jwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡√2  -√2 ⎤\n",
       "⎢──  ────⎥\n",
       "⎢2    2  ⎥\n",
       "⎢        ⎥\n",
       "⎢√2   √2 ⎥\n",
       "⎢──   ── ⎥\n",
       "⎣2    2  ⎦"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
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\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2   √2⎤\n",
       "⎢ ──   ──⎥\n",
       "⎢ 2    2 ⎥\n",
       "⎢        ⎥\n",
       "⎢-√2   √2⎥\n",
       "⎢────  ──⎥\n",
       "⎣ 2    2 ⎦"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEIAAAAzCAYAAAAjKt6MAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADb0lEQVRoBe1bi3ETMRC1GQrwQAdOBwlUgNMBoQOgAxhXwIQOAhUwuIOECjJJB6EDPO7AvHfsZnQXaXUyOtu60c7IZ31ute9pV6eT7OlkMpkhPZHtdrt5UjiCgul06sVLaA9I2066AhGTMSbgvO5gJfbrZ/ignAP01Ekf/xWP7xMYW1iBsMGqRIwPcSKi533bI7ZO0fYn0hlYPYr5AzZdiv1/cD1BuoRtv6Us6WISIRPLd2hcI71CmidpH7AxbLuD+i8AvmI3YusdrnT9ZDLM0ODII10gMY5+sMNjEID9ADtmsKshgTbRVlyYv2I+VUwiUpXtsf0F+rr39HeLsoV4h6c6XFQqEQtAYrh2Recu1idJcUT0HO0XSSygcXFEwGYFqaPvYlYvmbmFfb6XSEQfXC/7NHLblEiEjrqLQ7+rt3BdkSTFESGPSYL0ub+W5V1HJFG638Y36G7u6VI9gvVJUpxHCDou9bnS7coZCu4dr+nWB/NFEgGg34BojUfpW0Umj9V3yL/XspSr+a5BReiA7DP2dAS4nueq7hYGfcX1UMLRX8IWDZHXyL+BTbQtWaJEQDGXs0cnsGsDoz7nMqzI0MgF3tVTiRA2KhGVCDcwynzpaiPIlKuhUUOj7UrVI6pHVI9oMyC56BKb7bCez3aQ4rVi4ELY/wldnGBZHjzKjBIBJVkPUgbGHFJPAh7PQHyNTCJAgvcgBeV6kHLuU3psZfAEHgeaEntqZD9IMa05YGWMiAVs822W8hWYwvpRSDA04P66EWoB1T1Cq81B6sR+hjbD4gHhYW4iWR6hIHX0XUDqJX3Icu/b5/elgOcO2zLWsUVE7F7WJx+k9FH6v23gDXPo4IEwhfNcdHs/GBq4WUedyrqi3pJ8kNJVFMqLa/9CfYrX8ScM3LNc46qPS4ZHdEsvSAQUbWAM7fQZomVRpqlgF2H/uI8btMki93IhqLvc3PU2JRYa2Q9STGvyV3JuWCkxlvoYEdkPUixjctZJaJ1CZ/NLH+T1NcHbjUkEmMx+kOK1YpjC5hwGGFYggZMnf08alOAc4dyR9SDF0TvoVxBwAwKY+MLF34KZ80SUCCjgpBWddQdFtaNy2N77XcgMjR37L/K2SoQMWyWiEtGO4OoRwoc+NeZ4zOiyuamSp0WbthHkujgB6RF3/eMK/rjyFzozUuFUA8PIAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}1 & 0\\\\0 & - i\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1  0 ⎤\n",
       "⎢     ⎥\n",
       "⎣0  -ⅈ⎦"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAA/CAYAAADuS5aXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGiElEQVR4Ae2cjXHcNhCFJY0LcFSC0oGddCB3IJUguQNnXEHG6cBpQSU46cBKB3YHsdXB+Xs0gCEhggQOIAmShxmI+COwbx92SQIHnZ+dnV0TPxH98PVwOPzqF57y82rg/Pz8kRFf9Yx6+6JV+KaVVvKblz9ll9HAHcNeekM3xubI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{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡√2  -√2⋅ⅈ ⎤\n",
       "⎢──  ──────⎥\n",
       "⎢2     2   ⎥\n",
       "⎢          ⎥\n",
       "⎢√2   √2⋅ⅈ ⎥\n",
       "⎢──   ──── ⎥\n",
       "⎣2     2   ⎦"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSSS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHUAAAA/CAYAAADex4e2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGWklEQVR4Ae2cgXXcKBCGvX4uIOcSNh0kdx1sOrBLsNNB7qWCe7kOkhZcQi4dxNdB0sEl7mDv+2VEEJa00iINSF7ewwIBmvnnZ0ALwpuzs7Md8TMxDt/3+/3L+OYpX4YFNpvNPZq8atHm+iK4+SZIK/kjyp+yZVngBnUuI5Uq5/Sk4pX/RBVMs/S8/SGB6Lg5VGdJ5WC+Q9+rQzq34ebev3E7nvege+dxQY48ytwi962U74s5dJtLpsP8uQ9vXTZWB++pYxtOXP8aAPHwP7GI4h43G+bspNJj32HujzI56Rdc3itN2D5ezm4gvBpWXH7xlxCzwMyBe8dzsdtef8wjsjUEVXJJf6zTuipP/BbeW0MaTB5zjTPEdSxu2v0kVnN0NlJRQF56VQMiLSZ3QV7eqnuv6ntLv4KlgVl4HMZk3DynIjXb8OuGnDeACufStyj2VSjXGDowC+qkuGd9+wXElqg327agufNDWADBn4jh/CmwWgR58voetispPRazdJ8D9yzDL7rquSJN48sLFPfztfLExrwSlitN0GrJN2KjbVyvpDy6JmFOxY18mzkVQVrO+hAan7xegDrnSco0l2p1ZDGERvhGY3aEJuHGXmak6m3Me6uIInZ6KWUCdlcbibQ8dlvnl3BF31G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PvAa/vqTsLlxIRsdRT7rTfP6GMiy6mwSIeps9kxXRxCBPsaBr4QdR0atHDd+I8qPKcac9oeQFnXf3Bpqz7oHvJn33QvFdNBUjHOA1ZM/trPwsiD2J6wUqmYzifEeHpUIRY46KnWerrhfsiWlLVqSfIscRVHKpYzO0iUxNL4xma4Shx+zQ4SjeclqYUZrhJJ7d2SSjJr3sZmuIobfnmjXOUBKktcJXqq9ydeLrSEqKW35J9U/qEFJObGVSypAN9if+29ruoAlQWu4oZfOVINnCFrVQeorHAV56kOuLbWVnWAyhJX1l0aeWUcAK+dhifrzKUuycX6d+UtcDkZ2XdpntgA8lZ5gMoSlx9+YTk+jKS9zlMo1ALwdR9zhqrVCKfhV4nfW3T/Qe9qbJ+11DndymQBCNXPvcsW8V//B9ijXyxGd7JrAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡  √2     √2 ⎤\n",
       "⎢  ──     ── ⎥\n",
       "⎢  2      2  ⎥\n",
       "⎢            ⎥\n",
       "⎢-√2⋅ⅈ   √2⋅ⅈ⎥\n",
       "⎢──────  ────⎥\n",
       "⎣  2      2  ⎦"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSSH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAAA/CAYAAAAWq21gAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGfUlEQVR4Ae2bi3HcNhCGdRoV4KgEpwM76eDcgVSC7A6ccQUZpwOnBZXglGClA7uDOOrg8v00gCF5fACHBci7EDMQ8Vzsv4sFyL3V7urqak/+TO6nb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Uz9rP1cNXCZW4hjWq+6v0sRThm6R846VrgWLnPnIozr9U0fh52EdWS59zvEFqiUxuXom7rfGzEh+J8WkFfxJWvhMj+y2pJB64e53B5/bmWwPc7hU38KrmIKgZGLiHgfE6bD1/zSquN4Ko/RGGov8pblFioeKT4EqGJbMr4Y3ooohN1zasS7vMRJkeIxIK3HtPGJNnVTD/cemlicjXNRdEghLovy2Ua8j8mkjc/hzcYIzca5yLOJOoGujUKg14kUp35R3t8+PqeQbIzQbRRiemQ5002OeGeerFR+r+RIceZUSyP4tL6pJzjpyGJx+ahMI96hJ5+XzmHttEWjGFk/C5+zGOGJCrL2JxPj048sJkl5phHv0JMApAx5hZNAeDBWT9bPwueUIUtPjupnTrpCPHAmJ0eKM0eCH414d31RkeKej1LPU/A5ZUxinOKXNbMUot0cjhfK2uHhzaq/MH1iNMT8UtYuCvGulMNxpb7+/Np1eEjCJ/5IkxjnMDD/dIU4BqIixR2jo1HijpYEEB0pPgfOoh9+ovA5/r1laKP5LI939H3I2GyFSIgiIgbC7u8Lw43RFurk9jj6ZCHRkeLtuaXK8BOFT+uTJIcOPtVTeHM07rLc77wGXkTEO8IYTDXxsZaUmu1+XzRSfFCKto3V8d3E8o8GG9scGk+fPLumCXOv+oNWKXypOKIVkkrYVDsViK0F33UFrNsSCRKItpBYmpi+3pjkRlfS66DSFmz9Qw6zf80VworVgpJn0dkOqIZrD98coWbud13+xYKSrfhMpSMZlcQF7ebDsMQdYuqKhtG1pCq4zI8sdt4WbJ2xhUpYSGCHC15uFbkgtmDrIJXpQjGFoAy9YW3B1tPyP+o1P7K0glcGx9cWbH0k8ukGcwtxytiCraflPtqb5e0doopC9Pqmj8NOwlqq+qY6ixtUSuNy9LO9vUdQEfwWbH0klfiGcGShoX5gtH7r2FIBCSDrp768WaY5VXSMqPDLwLrf2e1n/Y+aA5hW0YQy9DlwO8DMl/8AODlN55mj+ckAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2   √2⋅ⅈ⎤\n",
       "⎢ ──   ────⎥\n",
       "⎢ 2     2  ⎥\n",
       "⎢          ⎥\n",
       "⎢√2⋅ⅈ   √2 ⎥\n",
       "⎢────   ── ⎥\n",
       "⎣ 2     2  ⎦"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAA/CAYAAADuS5aXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGXUlEQVR4Ae2cj3HUOBjFs5kUAClh6QDuOlg6SEpI6IAbKrjhOoAWUgLQAaED6ABIB3u/58hCVrxe2ZIs/1nNKJZsWfree9JnW1plc3Z2tiN+Ivrhx36/f+GfPOXHZWCz2dzT4suWVq8vnJOvnbSSv7z8KVuGgRuavfSargabFY9R9tkrkDRLD9ofqxAbNsfKzP06PNyB4eoYjpoLjt/8stTxoHPn/oUceRq7pd43Mqgr5mh7SnUaHj51cVBfC7HbjryQwhFlrjHKd8sR1c321qQ8ZBeP3vYWqj+IbtLPOLxTmrB9PJzdIGzlBkx+kQeXBwFMxcWOuuBvrz/JI3XLTVT1kv5Qp3VUnvjdPbfUNDgtDzV2F2sfLij7m1g9N7OJRwMadVe1kaSl2M7Ja/Tp3Mv63BKP4GvwIIwG9yAuuLcSL5vbNG7hNYa6z7o3NPxVlq8lHOBB8KO5iHrbxLAtUW+SbUHPtvfuBYT8SHSfbwKgyYAnr8PufVNP9+VBeFJxMcht0r7ukzjyAc8wxj4vlSc2fLx7XWmCZg2+Exv3+uWmnsf+KB6GcEGbaZ55VKTpm/cuyeT1InLwO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zXKZLuTb2NvX46VzJiVxBOY3snVupKgpN6osWTIapEgtie5hNtymiUNqJbjmsaefrPQPrMsCPSLVMqjT1BOGUfQXw0cCpf2046CU7TzlXUkhCvvuqVl8RF7wyaGk7sUSeJXhIabUcMxpYMk8R5EcoIald+oa081w79R4i24kHncDVFFm/nhDNYvFJkBimdsNCccJ4nxH2qamQGgkdeqF24Hb1RhSyLhFY52XKlsSYXD6azbq6YmJJFseZwm1k3V0xMvKJYc4jXuSwyMfJjzSmKNbnb5G1tNRtNSmPNMfJsb+aBrqkzTS8tfqNJCazZxAPMFtG09rf4jSalsCZ3m4i1qo0mtXC40NE31SQfeQaMlnwWv9GkNNaoVQWNMj8ASDPe+lBvhDlNOzUM78iUwmrajV5VeAINkVaz0aQ0Vus2UdPfFKK1ulMozAC63PvaYFLl2eQ2lfirxcZf9Cz7f7Zarp9OjcAAwulzSwvefvj6P1ICUiut9FTLAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2   -√2 ⎤\n",
       "⎢ ──   ────⎥\n",
       "⎢ 2     2  ⎥\n",
       "⎢          ⎥\n",
       "⎢√2⋅ⅈ  √2⋅ⅈ⎥\n",
       "⎢────  ────⎥\n",
       "⎣ 2     2  ⎦"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHSS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAA/CAYAAADuS5aXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGeklEQVR4Ae2bjXHcNhCFdRoX4KiEcwd20oHcgVWC5A6ccQUZpwO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AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\\\- \\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2   √2⋅ⅈ⎤\n",
       "⎢ ──   ────⎥\n",
       "⎢ 2     2  ⎥\n",
       "⎢          ⎥\n",
       "⎢-√2   √2⋅ⅈ⎥\n",
       "⎢────  ────⎥\n",
       "⎣ 2     2  ⎦"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSHS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHkAAAA/CAYAAADE+2c4AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFIklEQVR4Ae2cjXXTMBSFEw4DQEcIGwAjpBuUEQIbwGECTkeAFRihsEHLBjACdIPwXdc2qurGJNF7UizrHNWW/6R7r96TLeV1uVgs1uQrcpx+bbfbF/HBuVwmA8vl8oaWvRxo3ZunwcHzYF+7v6PyXCybgQ3NO4ua2BhvLzJW+y26wLxI79uOVUK7lmPXTPX8PvzA04+YB+6/1bEn8QmvMg14S13vJOKu7NWe0upJyU9vyRlAvkHceIjI0Ixiq0zGTxaR6aXvofaz6GX/GZuP2iet7jaLDR2gcTVtuapNan6yiIxi54EVX7L/rlMRgBJfb4o1v9kn52cNofC81R/zTF2y4ouuLtVNXgdlWbOOveyO1bQFdzJ+eNYf8oWrJbeuOeyltGEhK77WTu3Jip/kb9c0dEXWm/NQ0th7GZ7ASr+Qw/FXomsi5sEnQXjfqe7n4ieZu4Z4PUsiyt0+C92syuSr8Fi8z3nN2PzUtfG5KZTB5coP9TXumm1TMRymG495pl6c9ELVj/GU9UL16DjLOY3FmqGZpMARFy78wKW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Z12FCokHqFZMqgyKs8LePjf7KlSvMy662qA4a+y9u0b1bZS11junE2EA7W4i/fTzm8Yzyl1r5/UAlt/0sHv/H3LgmvlQIQwgsD479W+n43T9FyVSzpC8C/88AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2   -√2 ⎤\n",
       "⎢ ──   ────⎥\n",
       "⎢ 2     2  ⎥\n",
       "⎢          ⎥\n",
       "⎢-√2   -√2 ⎥\n",
       "⎢────  ────⎥\n",
       "⎣ 2     2  ⎦"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSHSS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH8AAAA/CAYAAADJ5Rd/AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAF90lEQVR4Ae2ci3HUMBCGcxkKgJRwdMCjg9BBUkJCBzBUwEAH0AIlAB0QOiAdENLB8f2OrPEpPtt3J61lW5pRLFk6afffh2zJm9XJyck5+Ts5TLebzeZ5eLPUp4XAarW6geIXLVRfPmncfNMoq3gX1Et1mghcQfZZQHpl7F74WPmPoEPyKlq56ZsEulZ9febaHgMf8Psd4sO497p3GjZY1SHgmrneSrhd2Yqe3OaxwMdb/gjMXyL0cKkZgYxsp9wLH5TlKZycgentUI5GET6EvoPALyLSEf3BEbx21yuYqFyTqy/qciA+wvAv+fM+YJ3TGaw3+mOSme97PRflL3VZV9XJf5r3llaG/6T4MP4/8oX5mt/UaghQuuaeFLBOnyisudf2elL3me3VEh9Ttw9jWpfeYMnNtf4t937NVpp7MHYIPvxGhiNDeQ2ul3tMV3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fKoQ7t0fhnLO/yhcsQ/uhn7/abhEFAlCjV5phTKsfin3GkSHlF6fYJwhEtDZQVe6sOf0eb+shLbOWw39Tq8COhHc0/Y8jy84vShajOxGvKoqN4x+KfeaV0Nke6HRowapRqB11WTaPy37vJg5bIrSQNVGQOnWAdlHD3ST8IyZ3/XaANwaVX+AxyzwRHf2k7hJhdjIx5f878n44JbJl7XAR6Ld+KPOdedSyppPd6pcUFc1rikI3wEbRZgGKlVvn+McMhJ7e/qKPbDt0zwyEn4ZsFKHYAn0OTGQ7ZuH2eqkswJ6pniUNOlu+tjoeeEswJGqlxyE74MLyG78UHc1rgkI3bl9nXDOP6Fh3MaYVDNpbvGDYJUJSi5ZoscTAJ1BwCNEzrpEnnCFsJL5B0735rsgwqFji4OUY/1fNwI+QSzAkaljh4t482bIKss/aSJo4AMr0J5Fp9Pie25FLlal+pEqQ7tLD8w6QAlKlVEbxem89a6P71H1aNxB0kmvZrAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\\\- \\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2   -√2⋅ⅈ ⎤\n",
       "⎢ ──   ──────⎥\n",
       "⎢ 2      2   ⎥\n",
       "⎢            ⎥\n",
       "⎢-√2   -√2⋅ⅈ ⎥\n",
       "⎢────  ──────⎥\n",
       "⎣ 2      2   ⎦"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSHSSS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIgAAAAzCAYAAABMt0DkAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFXElEQVR4Ae1dgU3cMBTNVQxAGeG6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nOgY040HZxHEWtQaAmTikrRIaeJXlPzv8Xg5Ttm5VSOYoSCIivjlMB/ZfKUZRAAtxkz8bdS+tGK1cdpzyjkcpR1BrE06am5CSnIE0d2AOWJI5mLxDcGUuQe4tIK9L6yOyB7/k0IeFo9gLB3N+KgjssPqspJnBaQBQ5lpEMCUezFwgJAIncWdGClOY4xX6NsmtM5agIgRhxVMcpEDEQeAPtzFGUQKC+Ip2CBsjcOatUjg5imOAchuuyPYQKYQS+Na4ZdJEI1SHNL5WjKAsiJa+Wny8DQQsC0zmG4xQXWqM7Bo2BbYyhk+JAee6+uEawwxETkM8dmh2CjmUsIMUWFAhMp/iNrZkCxF+g2QyNgc2uM+VcigPlXQLg4Iocy9gXKbY6xaQo4gOVCVoQcgElc4q4MbwszW91nDJE8KdUjqIEgv6LHG86PE5xqAWbFhwujkXYsjlOYX70OmvF5oGNSZy6Yttvr5sCB+oUO5YRXwo2lKmOU2RuxMCFZnHOZVFTDFQ4leOUeHy0YJsIBx8AMoqCBFuUQLrosBjjhzmjOE516x3jWAu2sXBgYL0fkqfytSu2nba5qJw7mOo4NTA6pXEUbUHajkPV1XHKI5ASOWotCN/W8v/BbGOXA9Px6jjVJcU6njtH3bHnMbrH2LSOU+3Dr7bbD7AU28e/KFAdp1pmPL9z5wj4n9C1ldW95/9Q+o3363EmRQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\\\\\frac{1}{2} - \\frac{i}{2} & \\frac{1}{2} + \\frac{i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1   ⅈ  1   ⅈ⎤\n",
       "⎢─ + ─  ─ - ─⎥\n",
       "⎢2   2  2   2⎥\n",
       "⎢            ⎥\n",
       "⎢1   ⅈ  1   ⅈ⎥\n",
       "⎢─ - ─  ─ + ─⎥\n",
       "⎣2   2  2   2⎦"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSH\") # = exp(i*pi/4) SSSHSSS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzCAYAAAA3v0BtAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACsklEQVRoBe1ai03DQAxtEANUsEHZoIUJKBtQNgBGQEyAygbABAg2KBtU7QawAYgNynvtWQrX+yR3TbBQTnKTOHf2e2cnsawWvV6vD9kaq9Xqe0upTFEUhRM7Yb5DVpY8gFRPuwDzzMJNHrM9/HCcgUBRkuuNWvcv8P7CDbRr3EJKN/qa6ParzEfuTs28TxyPIFPs0keVtbuYA/9D2HmBjOA3+qxHScHgAsbuYOyVAM3DucCRoW+MmPHzBJdfkGPIAFJpBNMPhq9gpS+EaNHsFAk+8LqpQT+QCYTPyXMdP0FSMDSBLB0G59CNzW46bv+tKkZqDHgMvz0kr3lf3fCSqhiFA3WMAMhLCvcEsESljF+i5/2ilye3fR4iVQXLYZVJbc8JkZJouDBJFPndUje8pMyrm4BdKSa6xr5TOTvlJWWMvuE4cDiQSPG+uhEjxdKEX3N7jKBYlqJp3//T6yApgH4Eui+83s8FpXnVX+D6UnTajtHaD4AZlVuQkTQ8wfUpCLsqjZ3yg09mCp9fyRbWnPQ7h/97n7MoKZNiNz4DTerhm2Va7RFMv9rWlCzoSCkJRBRGF6noFimZ0EVKSSCiMLpIRbdIyYR/GalomSSbj5priPPKDUVZl3uE39qN1CApGGQxmdRQzCXD9fCf1EgNph+LWRaVkNoNxVxSIJTcSA2SygWWuT65kaqZ1Bib4mr+fJvN4n3nUEnKPMtOwCWl9ElKqs2pSlKAJoAlKmXgEj2+xJxDKyknWEvpbaRqJSXRsHisLyWK3kaqSlL8lBg2rhQTnbeRqpKUIZTcSNVMKrmRqpYUUjC5kRqs/ZgG+GYkNRRNCuUekhqpUVKs/XKRpa43L4zajVS16Ze6EVzXkcrZvTbXdpFqc7dzfMnbb2CX+6VSJcd+o2ttzHAmJdT/+xPjD2U+4S47RBrKAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}0 & 1\\\\1 & 0\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡0  1⎤\n",
       "⎢    ⎥\n",
       "⎣1  0⎦"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSSH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzCAYAAAA3v0BtAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADHElEQVRoBe2agXHUMBBFzwwFZKCDSwcJVMClA0IHQAcwVwETOghUwJAOkg4ySQehA27SwfG+0TLGJ1mSY100Ge/Mns+yvPu/diXLe9csFosDdEe22+39TmNlDU3TeLEL5h267ek5pBa1K5gve7jF4/IZH5ITCDQd/fi3ue5P8P6HG7QtbiNVN/pMdM9T+pO7Z67fb46H6Bmj9Cvl3in64P8IOz/RY/xG53qUFAZvMPYFYxcC6CbnDUeFvhgx5+c7LjfoK3SJJslg+mH4A1YOjJAsupESwXOdlxL5QU9RzZMfOX4GSWHoFL31GLymbeVG03P5cZtipFbAU/j7Ynmt69VJkFRiFF5UxwhAQVJcM8AWlS5+i17wid7tvO/vQ6RSsLxM6bTvPkOkLBo+TBZFPbeqkyApt3QLsC/FrK3Yc+ohIxUk5YxecVx6HFikdL06iZHS1kRP874c03DbiWb/+qOeD5IC9DfQbVje3xpKt9S/4/y9tdV2jO79AKyorCFjafia8zcQ9u00JuWHT2WK5q9li/ac8nuN/68hZ1FSLsU+hwyUbMe3tmnZMph+2dYquWEmVUkgojDmSEWHqJIOc6QqCUQUxhyp6BBV0uFJRiq6TeoPPnuvT7QdsoXZS2kaf9mF1GxSEBKZtrDZJzz1OYRGFVKzSREhlZ2LC4S8hVTarZB6EgJR85waXUitmdSKSPiKP/cuQrrulaT0I+R6UVM6KPXuSMHgC5rXS2aj8xe7y+okO/1SI7V2RPQmut6xMn2DAbaodD1Y9DTQXomSYtSW3KkfBCTK81rKYsFCapQUJDZEyZZwpWDWzyr0HyMWDd+9FsVgITVKCkJtChAxqyipwlRUzCdOfClmbcGMiZLqoNdcuug47Fwq8nV0ITWJlFuNjoDeph7ntnUpwsYZHV1ITSKFk7buprnlFg7996Ko4Gt0ITXpOYWDK8hItZnVb7HF55UbsVGF1CRScgCR4F7LAZj8gE8tUtmF1NT0mxxwSYMzqZKjO6XtOVJTjmZJW7b6LVmubfvR+nMrT0nfD7bdx4zBfxye3J8Y/wBM4vwr1xGMdgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}0 & 1\\\\i & 0\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡0  1⎤\n",
       "⎢    ⎥\n",
       "⎣ⅈ  0⎦"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHSSH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzCAYAAAA3v0BtAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADFUlEQVRoBe1ai00jMRDNoisAQQe5DvhUcEkHx3UAdABKBSeuA6ACRDpIOkCkA+iAKB2E9xaP5DPjT3bXi4V2JGeTsT3znme86x2oRqPRPton2W63m0/KwhRVVanYCfMFbeu0W5Aald6AeeHgJo/FHj4oUxCorHb5oS77E3j/ww20NW4hVTb6HdH9SBmP3L0x495w/Yl2g1V6TZnb5RjguKJ/+A5mUpQUDD3D0F8YmhOg2ZzPuDL0fRMjmRoHsfgkSArALzBxXwjRCL5voKfhW7QpdX0JfDNLohLbU2ewsFKsPEE3MVFTur9WFSM1Aby1AlGeYewvTrzplxiFg9yMDA5uA6beC1LwX8xnKFICWKJi25LoeZ/o9uCW32eGyCPszFJshUilzD9MGdR0DKI0xlzuXwr3d9LdNkRKolFbdD4kinxu5ZQ1oiS3cKbgQ4ozLykYk7TTUkx0SSuXAkQbIxgQsd+m/04b5+q8pMzAJa5MAVckUuzvQ7iX5kIy5jBGipvzRDFyDN0q1YkyP1ll7n5HmFCnHn7Lkc1rI0gKoBnutRV+OSb9gf7ca7XbjnpRgWUOHMwavioFxfucsmYxKjNjkOpTtF9wop002N+pwM8Svtl4mN2YhQ76iJKCEd4wroNWMncCw05nzGD6ZcaazfxAKtvSdmx4iFTHC5rN3BCpbEvbseEhUh0vaDZz3zJS0WOSLCfOXjwp89R+bI5O0pX1Cr9yKk8upAZJwSBfBu/R+BbM0/IYrTeB/0aF1GD6MSJoZ2isjCa9SnfFGITUQirsSyHV6ypIyjurn47GhdSSSU2wdlrxh69CFParUiQps5dVwJZS6iSW6uNrkaQATQBLVGzgEj3exFQplZQK1lF6C6mlkpJoODzqnxJFbyG1SFLWw11LMdF5C6lFkjLhaVxILZlU40JqsaSQgo0LqcGzH9MAzwyuGPNYys/8I/YKv5/gOPoHMIxrI40KqVFSAM7jypeIuWHsXEgtNv3arOJAqs3q9Tl3iFSfq93Gl9z9xu5x39x52tjOPtfFDIdyhPp+/8T4DgLK/Cu7v9cMAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}0 & i\\\\1 & 0\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡0  ⅈ⎤\n",
       "⎢    ⎥\n",
       "⎣1  0⎦"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSSHS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUg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KHGQmrCxTe5XiJlWq4JJ8vptw6v++7kmRBa2XWIGRpyhXp8/8T4F+pfFzck3CXOAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}0 & i\\\\i & 0\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡0  ⅈ⎤\n",
       "⎢    ⎥\n",
       "⎣ⅈ  0⎦"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHSSHS\") # = exp(i*pi/2) HSSH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHUAAAA/CAYAAADex4e2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGcUlEQVR4Ae2cjXHbNhzFLV8GSD2CukHSbqBsYI9gZ4P0MkEv3SBZwSOk2SDuBskGTb2B+ns0gIAQSfEDgABTuIOJb/7fewBIAoI3FxcXO/xnfOi+7/f7X8PEc7wMBjabzQOWvOqw5uaFl/jGCyv4I4ifo2UxcIs5V4FJzeB0ojIq/w4KLI7Sm/bHGuG+m2NlnlM+nNyD5/oYpmO8kP9P2AZtPyrtMsyIFecGd7T1VsYN+Vj3q6Edw8nnIT5s3hI8bqQuaaSn7g0GhlN6T9GnZEC/JHRFve+DBevNzMJJElER5x28fxT3Rqj3Roetud4iXDNVmLi9qNy/+L9swnO5+pwI0wReZnGy4x5wvNefKJ72NMU0bRH+aMO6Ko7/5qetIQxmx4nlwccdgxfa+A/fPK+jikqjGqXX1mDCUnLnxTValfbKpj33K1hbnAiv4SAqL7TZiBp1+jVTyhuM9p+lb7nZV6Hoc9RTx9I31+/UvekrV2N6DyeCMsjLUk4mjVSM0Ui76xpdpH/Au943UKY1/Zp6eklSF37ZVa/kNGxexImw4cSd48XEJ3FCnenTL5XUAXTzA/JJkwGt50YoBPkajd9U1uYRFiGqq2eBA2XzS79i8yJ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NYPbeq8zPYOwmzJ2hS3NgVR1Rj8KjTXhIP33vSK+wAJcfBMQqzJ2hy3LFFVc9VL9Goc70xFMWU0ahu+bBcDXEwjMJsRBU3LcyKx8ZJm81Ijbb1xluheu4VfjUn4ErDjD0SNerW28lPewEotysS86zFB3qEppJOR17fd2tneT+R6ajYjfSaMM8StWTy/U4SM1wT5suYwM9tlcHArJE6ZDrTVPZtpiF7cuWVhDu6qJCY7SBQLsFG3qcY3Cmm32wHgUaSnatYMbhTiJp1mymXYiPuUwzu6NMvb4mrPCBVEu4UI9V1al4etGyo5bRVHZA6Ne5kogJsi5irOyBVAu7o06+GqQXGlLSqA1Kl4I4+Ug2w1R2QKgl3tF0ajVA5wGmnQAsQLVfTMlvL8JGREnAbG6Lu0jTwES/bQaCRfGcpVhJuN/2icniASfujZ1coA+j1EGqGqc0MqelXgd86bP9B71v1P9/o4KSYJATV56J+lBC6r/8DhA9fLBue/N4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2} i}{2} & - \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡√2⋅ⅈ  -√2⋅ⅈ ⎤\n",
       "⎢────  ──────⎥\n",
       "⎢ 2      2   ⎥\n",
       "⎢            ⎥\n",
       "⎢ √2     √2  ⎥\n",
       "⎢ ──     ──  ⎥\n",
       "⎣ 2      2   ⎦"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSSHSH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAA/CAYAAADuS5aXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGWklEQVR4Ae1bi3HUMBDNZSgAUsLRAZ8Oj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vAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ √2⋅ⅈ   √2⎤\n",
       "⎢ ────   ──⎥\n",
       "⎢  2     2 ⎥\n",
       "⎢          ⎥\n",
       "⎢-√2⋅ⅈ   √2⎥\n",
       "⎢──────  ──⎥\n",
       "⎣  2     2 ⎦"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSHSSH\") # = exp(-i*pi/2) SSHSSS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGQAAAA/CAYAAAAWq21gAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGeklEQVR4Ae2bi3HcNhCG7zQuwLkS5A7spINzB1IJsjtwxhVknA6cFlSCU4KVDuwOYquDy/czAIYEXwAJgOQNMQMRz8X+u1iA3FsdD4fDmfyF7Kfvl8vlld+41+dL4Hg8PkHldQel+xe1xre1soo/vPpeTSeBB0idPHKVUTiFYA1/ewNmV9kJlzEirHscG7PWfvA9wtvdGH8+Rur/+HOg9ay2G78jVZ0F3kHrvZgZyqnWK03H4PsyhM32xfDmLCRmUuDYexjyj8HBqYB8yYAT874PDlxHZzS+ELazKATBfmDxz2LACPmjYebWPB8QemWipm4fGvcv+U/bsMZnHZ/4i8Q4CunMCORz0Z8kGXoy5YoW5c+2rKfq5G/1tq2V4d/hs5jqGKZgZM5PcnUfJVUIRGUdd5ZBytLCuVaXlajttW3b0hO+G/jEu8EzCyM0KoUkPbKM6b6Fyfrd8Z7FvorrvsQ8bQq9l//G3Pu+cUu39+ATW6MYY3iPshAIa4e/69rVtH8iu50yMKZxZJ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IU93UEQ/4+YpxAoJQtGR4swRw72R8JZ2yecUHEYZvVgMxqCIfsYmU4h2gTNLytoZ7s3KFyp9AuBigSlrdy0ezwsPUThqyujEAj13XAmjLwe/zpg0CjGMBUWKs6jdTVKCzfIMj56xPoAcdfgIwmEwD2KBlhQcHNHP2KQK0eIiKCG7HeMLzYyRNTWyP26pOnwF4TAKEd4GDtUt75RlIcER/YytFJLM/c5r3lVEwi+Fg3WlkKTu9+KR4gDIkRbFMenDEG3KVDsTffLsTkqYe9EfsXLh6AMfgm+SQkII9zG1pvY14rhZk4B2Xg6HSRYyJDiOAb1dhLilh8isrq8UruQKQZLFgpILa60YrjPAOE7T/B4iWuRsQcmp+IylkxsX9KvvkBx3yKBbmoW3morgSn5ksfP2YOsZWy6HhTh2uAjlSpE7Yg+2dlIZLmRTCMq4Zek92HpY/q3e5EeWVrDK4Pjag61bIh9uSG4hRhlyqe/B1sOy7+xN5u211FGIXt/0cdhIWEtRP1Vj8QSV3LgM/aTe3go2gt+DrWdsAHdkoSE/GFq/b+wpgwSQ9ZMvb5apThUdIyr82rHuD3b7pv9RswPTKppQhj4HTh3MfP0PQGFN59x03VEAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡√2⋅ⅈ   √2 ⎤\n",
       "⎢────   ── ⎥\n",
       "⎢ 2     2  ⎥\n",
       "⎢          ⎥\n",
       "⎢ √2   √2⋅ⅈ⎥\n",
       "⎢ ──   ────⎥\n",
       "⎣ 2     2  ⎦"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSSHSHS\") # = exp(-i*pi/2) SSSHSSS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
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DTTpcbLgGAazGeYZ5DIF4WaMzgdNWxjE3itowzFja1JasAQFwbZwFc06KtcJ3c/cwytl0CmxqHKkvmBpGvLe4pLicwrsv+SBJTpC1jk3xYxhkbG88c+QrjBv+u1vURQNCX7liSxjTqdJ5Z1svHuLaMTfbXMs4h2FCWOlA5UKPsxiVOZckgphM0zEjrxYPruQWBAQuFfiLw8Az0zgo24quCxFnhrePkAHJgEPfqQK3BVvUDvzz5GeQaqVqTodNcfy3dgxoWzeUn/wFZZr956yMnZ45VIsPgFefePpV43s+ZY5XIPPmLXh1WgFaW1rY490Zi24dj1ZosEu6QzUZzTA0J8sDbGs3xwYsM/7AFBu8ekdas8sE88PG0Bd+X46QiowlGLM69ETVlgeOkIgO33Kl671ZBJNugJSvOvSChFpJznFpkNT5GX1Jgxbl3NH2qiqM5VokMlmKyjqkq+gMUypnjIw0/eIdTnHs1RHmUyZljlSXz4K5ULQzMei0ZzHhx7u0Qitt0eDnd5s5xr8hgxr2/tEAbPFhvBJB78M696NsKHfP6Sjh3jst02ZB+yQjNQK8l4wPdlFCce0OzL9rLmWOVyMBFdOdPwffQpGVsQ/piuR9e2LTTJT+kWwrG6EzCd2f88iF1sIxtCDeW++GFTSsyLtyLc+8QyQwvmy3HqukSu5/i3DtcNINq5MyxSmSSLTdFFudeSUrgdG4ca6fLDY3o/AKJ4twbWFSyuRw5VluyqvMw68W5V6oiYDpXjitLxp0i3bG2UXLnOl+ceyUpgdM5cCz1wzQoYpxVzr2cBmV4gsXaHgWhQnHulexESOfAMfrwAmrkqy4y9foPAlOW4hBH8V4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\\\\\frac{1}{2} + \\frac{i}{2} & - \\frac{1}{2} + \\frac{i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1   ⅈ   1   ⅈ ⎤\n",
       "⎢─ + ─   ─ - ─ ⎥\n",
       "⎢2   2   2   2 ⎥\n",
       "⎢              ⎥\n",
       "⎢1   ⅈ    1   ⅈ⎥\n",
       "⎢─ + ─  - ─ + ─⎥\n",
       "⎣2   2    2   2⎦"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHSH\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJQAAAA2CAYAAAAh6LAxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAHDUlEQVR4Ae2cgXHcNhBFLY8KkF2C3IGddCB3YE0qiNVBPKlAI3dglRC5A7mDJOogKiG5DpT/KOIG5IHkkgQPeydihkcQBBZ/PxYLHAjy5Onp6dWxhJOTkzPp8lY6PR6LTvvSIxd3r62AqVDHZx1/W8sUyPe76vxUoN7eKl8Sd6com2JDvXwT0pXnveIX9XUyf8hb8izMX0rWn6r7WLnrsptTkYDHOW+Rcavrq5CmhnpQ/EFC3PX+gNHr+Yi5uxPnwckE+n9gUISPUvzHc/TwfmXoKIYX/Vl6XB6eBuUQT+VOPH+MUUvOZ11fmudQcWGHcZTDq36SYm6HZIe8ASkrdwdvUDIghutrHXipR/Wc7dxP12voYWAJ7ooalBS60IGrnBxkQMGImPN9myzogArm4A11l+CuqEFJJ4an2UOUCEYGHupWceZSxx6y8AZJubkrbVC5Gh5jeqiHu19yCX0hcrJyZzIoWfG5jhsRzMIh8W86fnNEOP9QH2tMroY9YXpR3J1ajIKxVvncLRoG7LVncrlc8NK4M3mo0HDreWVgiIFBDyWXPfj0WL3wpK8iyWAYYqxuh7ck6P52VT7KwJyo1+vkwBbVlz06F99SvKHoXGxdZA0a1JCxdAmO0yUjZTAoxaOcc93/Gue3xnNgs9Y1Jd9cfEvxhi5zsXXxsQ55Xcys6ZMYGPRQSJUnYd2Df3iE8+fTq19l5Zs6XuzkGRukeMa3BDaTQY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dr4RIjYDgyLxCmMKsOhp5ZMtpy+3CLy6qz1/W2iyavTR5qoZ6RBDQxcaiXTRSbp5gaBHyNZ3x5JJukmOc/CWl4wq5Okshu9FBL9IwkmomJfb1sosjsxYTxiuFKx3WNN3sdKYHUm0ofShNOdg8wocfzmsOxDHlmhUtmVON8UUPNnjPuSYc/xhoTuAYNSgSs3zYYaEELR7EI5Y8v3cZTOGVkveAHDWpIgIUNyUi6XQE+im8b5ODIwuMh5DFNyg9BkRWjDwYGPRQw5UkY95nxE8J6yvptg2c+9vbruR0CCSaDUubs78AHABnOnrFlUK8hwr2u1iEv+zvwDZrmXXjGNk+z3dLudbUaFJPq9dsGuw287xTP7VBxYRry9C9m/bbBvk0nUd+C7ZCobVqSyaBi0ZoYso9n/bZBTEqBeM52yAnfOuRVdUoJ/uHxoHP9tkHOVhgpy3M7BA/FVojGIwG518YznKCE0qvNWrrGU81+z2wkl8nsnrElAc9I9KKrcDTsRSptr9k8xeOV+OBdLr4fVB26h2diGylGFA62m7LddpuvRFwY3GLLzYcnXYUFe4hthvg9r5fr3B9kjeu3Dfop2stdz+0QCPgf9rjJjd42f9sAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} + \\frac{i}{2}\\\\\\frac{1}{2} + \\frac{i}{2} & \\frac{i \\left(-1 + i\\right)}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1   ⅈ    1   ⅈ   ⎤\n",
       "⎢─ + ─    ─ + ─   ⎥\n",
       "⎢2   2    2   2   ⎥\n",
       "⎢                 ⎥\n",
       "⎢1   ⅈ  ⅈ⋅(-1 + ⅈ)⎥\n",
       "⎢─ + ─  ──────────⎥\n",
       "⎣2   2      2     ⎦"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHSHS\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 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yjXxlkA91z0r3Dfu/uZZmwhCjY2jkWWzAwijy1uqVxGwbgu++tDYo6ymrH5yKtZjlhs/Ob4B/EKb49zfYRO6Et3WCcNdXZ+s6yXz3GvGZuPvFrkAA6O8wcH6VBsqLdxiRNZMijTETpmpPXih+u5BgUDFm4ejiw8/AZ6owUb8dmBA0jiERsO0rYclTw9ycEvOx9cH2OxidZkIIXrr6UhrGHRbCL7TIMMtf+8TZlDkZJh8Ipzb+TbM2UORUoWyW/26rAStLK0tsW5N5DtnByK1mSBuPdZLdjxdJ8glfeVjcPBKxnewAUG7xaR1qzywVQ+nrrg5eawVyWjiUYszr096xzWi9XLydMDnocmDb0qGSThTjV6twpFZRu0ZMW5FySEhJwc9q1kIXy01aGCFefeNmbkedk4FCkZtHy0jqfyMYgrOWUODyTUcc5GObUHncC3Ar6d7nMSOXOWmTKHIkuWk/zS9vgZ6LRkMPPFuTdSDxJxyM1NlBNxmxgpsLW1a+d1KhnMfPSfFmiDW+NGgICDd+5tCNWSkYhDLgmi/0auw0uBrd5m/b5Ml3VGyn1yBjotGXuExaGp5i8gDIu3S3HuNTyILlPmUKRkYDHKuVM0CuGFNGOzpdKMMzs2/hm7xNzMHwBbI55z8b8tgzStGfNOXHUk+ajPNdm1pKyrjMGRHJurv9B8zThzYUO7/GT4JF2TceFenHtBQkSYLIei6RJvb3HujdAuVs3IYSSy/NhESmZLgQUsfw4szr02KZ7plBx6dt1ZPAc26XS5AQcAXIsV597OoXIXmCKHYktWkQOzX5x73Tq088lUOawsGf+yoLvWNtpsGXKKc69Nimd6Chza+sM0KGKcVc69nAbt8ACLtf0UhArFuddmJyA9BQ4h4xOoWdboef4PUz+W4jFS3NIAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & - \\frac{1}{2} + \\frac{i}{2}\\\\\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1   ⅈ    1   ⅈ⎤\n",
       "⎢─ + ─  - ─ + ─⎥\n",
       "⎢2   2    2   2⎥\n",
       "⎢              ⎥\n",
       "⎢1   ⅈ   1   ⅈ ⎥\n",
       "⎢─ + ─   ─ - ─ ⎥\n",
       "⎣2   2   2   2 ⎦"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SHSHSS\") # = SHSH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKkAAAAzCAYAAADsKCgKAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFrklEQVR4Ae1cgVHcMBD8z1AASQmfDsKkA+gAJhUEOkgmFTCkA2iBEkI6SOgglJB8B2T3kX+E7PdbupN8AmlG87ZfOu+t1idZtrVcLBaHyL30+Pi47h2s/MByuaSv7+DbQ+WumIUv4djV7fn2Bkd+I/8L8lWv5IQDPAnyOTJtWkzfAOrUIrApmCrgl25IOL5F/VCLtweOnBNElzu3nfQDAj+g4rGrPBidkwwrVoKPXxXNFTVVA78kRMIx6p74pMLnc+yfdSL1/0vaxgnuUfEehquNVEmOF6r0mvlVE2mhtko6DS4cRnhG+o9o7LMkI63SKAM5OeaY9DUkdiM3yKcg0+RQ5AU0QjaOX7xIIcoVBHCJzGj6gEj64mYt5hZ4bo5Ni5RdCDIHz8kJouyEeQEj18mGWsWdDOTm2LRIwQq7ZnH3DKHTBiPpDbY5Nm1JmYGcHFsXqRaVFOi96+o/aRltdp4xkI1jNZHiSloh8yEAJ3O5fY385Zkb8+1wDvjB4amyywd2y/yyZbNxfKClG45LYMvkZLmLoFVPPVnmlxrKybFaJNUSe7PTGAgZUImk6IoeQ8PhPq60ZXis20d9dsEc04TpHQ/gf96Zh4ljzNHoKMUVnnCufQ0/YIM3jz+RY25Ez8AxnyTuTBrYdhp3f6iIdEyA+wD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+IRSdqbVikTv9NOvqeUFFsxkfp+YCDNF4zb4hE+KYrbWvwqQtqaSsFWsrvfAAVI3tm3xSO2zaa7YZVfepmKrWgk7UAi/LfFI3S1ubFmlV9foClt30VSvqHEz423WZtDR2BbPEKbWGfPKr+eQPe2va8/bqPu5l3hbnEIdsF+uoHiBx9F+oVitnHS6hePiPG3dFmr/JKHqdhQ7geKHwfc3f0HCdAl4eABvw4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\\\- \\frac{1}{2} + \\frac{i}{2} & - \\frac{1}{2} - \\frac{i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡ 1   ⅈ    1   ⅈ ⎤\n",
       "⎢ ─ + ─    ─ - ─ ⎥\n",
       "⎢ 2   2    2   2 ⎥\n",
       "⎢                ⎥\n",
       "⎢  1   ⅈ    1   ⅈ⎥\n",
       "⎢- ─ + ─  - ─ - ─⎥\n",
       "⎣  2   2    2   2⎦"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"SSHSH\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the string representation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "LC = [\"H\", \"S\", \"SS\", \"HH\", \"HS\", \"SH\", \"HSS\", \"SSH\", \"SSS\", \"HSSS\", \"SSSH\",\n",
    "     \"SHS\", \"SHSS\", \"SSHS\", \"SSHSS\", \"SSHSSS\", \"HSH\", \"HSSH\", \"SHSSH\",\n",
    "     \"HSSHS\", \"HSSHSH\", \"SHSH\", \"SHSHS\", \"SSHSH\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABMAAAAOCAYAAADNGCeJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABOElEQVQ4EX2TjU0DMQxGL0xwYoSyARIblA2Q2AA2aGfoCLBCR6ArdAS6QrvB8d7JiZLcUUtWnM//sTNM0zRAG/gr+Mz5Az+ru8fa6JNtkOdAxwx4QgdYYVvjvYz+Fy6+yMMRHlcMr+DXHs93dDu4CfYAsNUppTRy1nTiMoL7BA2B2d4tuOgMptOFjCrXqE+izTv23wvjXHZ/YmgLwO0QwGxvIw45rPJmVragaMP29rUyWr4R6FLjRe4zR0arKiPPNmCHLIfd/crI7r6dMP4sGRHAPzjU/UtNm+HgQ/WBbNn1WW8vwqco18xvYC/cyzuBGUTybBLM6DDo4xbMGzF/Fy7uTfMekcTJLRZaXehd7DLNxMWs/kWj1/TIxf/5VIO1TOXuh+/7mnEnIrjG51xFfWLrIGo/i9n9ATCSR9TdYl8YAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle 24$"
      ],
      "text/plain": [
       "24"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(LC)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 25176 characters]\n",
      "text/latex": [
       "$\\displaystyle \\left[ \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}1 & 0\\\\0 & i\\end{matrix}\\right], \\  \\left[\\begin{matrix}1 & 0\\\\0 & -1\\end{matrix}\\right], \\  \\left[\\begin{matrix}1 & 0\\\\0 & 1\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2} i}{2} & - \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}1 & 0\\\\0 & - i\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2} i}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\\\- \\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\\\- \\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\\\- \\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2} i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\\\\\frac{1}{2} - \\frac{i}{2} & \\frac{1}{2} + \\frac{i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}0 & 1\\\\1 & 0\\end{matrix}\\right], \\  \\left[\\begin{matrix}0 & 1\\\\i & 0\\end{matrix}\\right], \\  \\left[\\begin{matrix}0 & i\\\\1 & 0\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{\\sqrt{2} i}{2} & - \\frac{\\sqrt{2} i}{2}\\\\\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\\\\\frac{1}{2} + \\frac{i}{2} & - \\frac{1}{2} + \\frac{i}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} + \\frac{i}{2}\\\\\\frac{1}{2} + \\frac{i}{2} & \\frac{i \\left(-1 + i\\right)}{2}\\end{matrix}\\right], \\  \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} - \\frac{i}{2}\\\\- \\frac{1}{2} + \\frac{i}{2} & - \\frac{1}{2} - \\frac{i}{2}\\end{matrix}\\right]\\right]$"
      ],
      "text/plain": [
       "⎡⎡√2   √2 ⎤                           ⎡√2   √2⋅ⅈ ⎤  ⎡ √2     √2  ⎤  ⎡√2  -√2 ⎤\n",
       "⎢⎢──   ── ⎥                           ⎢──   ──── ⎥  ⎢ ──     ──  ⎥  ⎢──  ────⎥\n",
       "⎢⎢2    2  ⎥  ⎡1  0⎤  ⎡1  0 ⎤  ⎡1  0⎤  ⎢2     2   ⎥  ⎢ 2      2   ⎥  ⎢2    2  ⎥\n",
       "⎢⎢        ⎥, ⎢    ⎥, ⎢     ⎥, ⎢    ⎥, ⎢          ⎥, ⎢            ⎥, ⎢        ⎥\n",
       "⎢⎢√2  -√2 ⎥  ⎣0  ⅈ⎦  ⎣0  -1⎦  ⎣0  1⎦  ⎢√2  -√2⋅ⅈ ⎥  ⎢√2⋅ⅈ  -√2⋅ⅈ ⎥  ⎢√2   √2 ⎥\n",
       "⎢⎢──  ────⎥                           ⎢──  ──────⎥  ⎢────  ──────⎥  ⎢──   ── ⎥\n",
       "⎣⎣2    2  ⎦                           ⎣2     2   ⎦  ⎣ 2      2   ⎦  ⎣2    2  ⎦\n",
       "\n",
       "  ⎡ √2   √2⎤           ⎡√2  -√2⋅ⅈ ⎤  ⎡  √2     √2 ⎤  ⎡ √2   √2⋅ⅈ⎤  ⎡ √2   -√2 \n",
       "  ⎢ ──   ──⎥           ⎢──  ──────⎥  ⎢  ──     ── ⎥  ⎢ ──   ────⎥  ⎢ ──   ────\n",
       "  ⎢ 2    2 ⎥  ⎡1  0 ⎤  ⎢2     2   ⎥  ⎢  2      2  ⎥  ⎢ 2     2  ⎥  ⎢ 2     2  \n",
       ", ⎢        ⎥, ⎢     ⎥, ⎢          ⎥, ⎢            ⎥, ⎢          ⎥, ⎢          \n",
       "  ⎢-√2   √2⎥  ⎣0  -ⅈ⎦  ⎢√2   √2⋅ⅈ ⎥  ⎢-√2⋅ⅈ   √2⋅ⅈ⎥  ⎢√2⋅ⅈ   √2 ⎥  ⎢√2⋅ⅈ  √2⋅ⅈ\n",
       "  ⎢────  ──⎥           ⎢──   ──── ⎥  ⎢──────  ────⎥  ⎢────   ── ⎥  ⎢────  ────\n",
       "  ⎣ 2    2 ⎦           ⎣2     2   ⎦  ⎣  2      2  ⎦  ⎣ 2     2  ⎦  ⎣ 2     2  \n",
       "\n",
       "⎤  ⎡ √2   √2⋅ⅈ⎤  ⎡ √2   -√2 ⎤  ⎡ √2   -√2⋅ⅈ ⎤  ⎡1   ⅈ  1   ⅈ⎤                 \n",
       "⎥  ⎢ ──   ────⎥  ⎢ ──   ────⎥  ⎢ ──   ──────⎥  ⎢─ + ─  ─ - ─⎥                 \n",
       "⎥  ⎢ 2     2  ⎥  ⎢ 2     2  ⎥  ⎢ 2      2   ⎥  ⎢2   2  2   2⎥  ⎡0  1⎤  ⎡0  1⎤ \n",
       "⎥, ⎢          ⎥, ⎢          ⎥, ⎢            ⎥, ⎢            ⎥, ⎢    ⎥, ⎢    ⎥,\n",
       "⎥  ⎢-√2   √2⋅ⅈ⎥  ⎢-√2   -√2 ⎥  ⎢-√2   -√2⋅ⅈ ⎥  ⎢1   ⅈ  1   ⅈ⎥  ⎣1  0⎦  ⎣ⅈ  0⎦ \n",
       "⎥  ⎢────  ────⎥  ⎢────  ────⎥  ⎢────  ──────⎥  ⎢─ - ─  ─ + ─⎥                 \n",
       "⎦  ⎣ 2     2  ⎦  ⎣ 2     2  ⎦  ⎣ 2      2   ⎦  ⎣2   2  2   2⎦                 \n",
       "\n",
       "         ⎡√2⋅ⅈ  -√2⋅ⅈ ⎤  ⎡1   ⅈ   1   ⅈ ⎤  ⎡1   ⅈ    1   ⅈ   ⎤  ⎡ 1   ⅈ    1  \n",
       "         ⎢────  ──────⎥  ⎢─ + ─   ─ - ─ ⎥  ⎢─ + ─    ─ + ─   ⎥  ⎢ ─ + ─    ─ -\n",
       " ⎡0  ⅈ⎤  ⎢ 2      2   ⎥  ⎢2   2   2   2 ⎥  ⎢2   2    2   2   ⎥  ⎢ 2   2    2  \n",
       " ⎢    ⎥, ⎢            ⎥, ⎢              ⎥, ⎢                 ⎥, ⎢             \n",
       " ⎣1  0⎦  ⎢ √2     √2  ⎥  ⎢1   ⅈ    1   ⅈ⎥  ⎢1   ⅈ  ⅈ⋅(-1 + ⅈ)⎥  ⎢  1   ⅈ    1 \n",
       "         ⎢ ──     ──  ⎥  ⎢─ + ─  - ─ + ─⎥  ⎢─ + ─  ──────────⎥  ⎢- ─ + ─  - ─ \n",
       "         ⎣ 2      2   ⎦  ⎣2   2    2   2⎦  ⎣2   2      2     ⎦  ⎣  2   2    2 \n",
       "\n",
       " ⅈ ⎤⎤\n",
       " ─ ⎥⎥\n",
       " 2 ⎥⎥\n",
       "   ⎥⎥\n",
       "  ⅈ⎥⎥\n",
       "- ─⎥⎥\n",
       "  2⎦⎦"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[simplify(evalstr(c)) for c in LC]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAzCAYAAAA3v0BtAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADFUlEQVRoBe1ai00jMRDNoisAQQe5DvhUcEkHx3UAdABKBSeuA6ACRDpIOkCkA+iAKB2E9xaP5DPjT3bXi4V2JGeTsT3znme86x2oRqPRPton2W63m0/KwhRVVanYCfMFbeu0W5Aald6AeeHgJo/FHj4oUxCorHb5oS77E3j/ww20NW4hVTb6HdH9SBmP3L0x495w/Yl2g1V6TZnb5RjguKJ/+A5mUpQUDD3D0F8YmhOg2ZzPuDL0fRMjmRoHsfgkSArALzBxXwjRCL5voKfhW7QpdX0JfDNLohLbU2ewsFKsPEE3MVFTur9WFSM1Aby1AlGeYewvTrzplxiFg9yMDA5uA6beC1LwX8xnKFICWKJi25LoeZ/o9uCW32eGyCPszFJshUilzD9MGdR0DKI0xlzuXwr3d9LdNkRKolFbdD4kinxu5ZQ1oiS3cKbgQ4ozLykYk7TTUkx0SSuXAkQbIxgQsd+m/04b5+q8pMzAJa5MAVckUuzvQ7iX5kIy5jBGipvzRDFyDN0q1YkyP1ll7n5HmFCnHn7Lkc1rI0gKoBnutRV+OSb9gf7ca7XbjnpRgWUOHMwavioFxfucsmYxKjNjkOpTtF9wop002N+pwM8Svtl4mN2YhQ76iJKCEd4wroNWMncCw05nzGD6ZcaazfxAKtvSdmx4iFTHC5rN3BCpbEvbseEhUh0vaDZz3zJS0WOSLCfOXjwp89R+bI5O0pX1Cr9yKk8upAZJwSBfBu/R+BbM0/IYrTeB/0aF1GD6MSJoZ2isjCa9SnfFGITUQirsSyHV6ypIyjurn47GhdSSSU2wdlrxh69CFParUiQps5dVwJZS6iSW6uNrkaQATQBLVGzgEj3exFQplZQK1lF6C6mlkpJoODzqnxJFbyG1SFLWw11LMdF5C6lFkjLhaVxILZlU40JqsaSQgo0LqcGzH9MAzwyuGPNYys/8I/YKv5/gOPoHMIxrI40KqVFSAM7jypeIuWHsXEgtNv3arOJAqs3q9Tl3iFSfq93Gl9z9xu5x39x52tjOPtfFDIdyhPp+/8T4DgLK/Cu7v9cMAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}0 & i\\\\1 & 0\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡0  ⅈ⎤\n",
       "⎢    ⎥\n",
       "⎣1  0⎦"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[simplify(evalstr(c)) for c in LC][19]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_table = []\n",
    "row = []\n",
    "\n",
    "for i,p in enumerate(product(LC, LC)):\n",
    "    if(i % 24 == 0):\n",
    "        product_table.append(row)\n",
    "        row = []\n",
    "    row.append(p[0] + p[1])\n",
    "    \n",
    "product_table = product_table[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "def simplify_str(s):\n",
    "    # Start with removing obvious identities.\n",
    "    s = s.replace(\"HH\", \"\").replace(\"SSSS\", \"\").replace(\"HH\", \"\")\n",
    "    # We precomputed some other stuff. Use that now:\n",
    "    s = s.replace(\"SSSHSSS\", \"HSH\")\n",
    "    s = s.replace(\"SHSSHS\", \"HSSH\")\n",
    "    s = s.replace(\"HSSHSHS\", \"HSH\")\n",
    "    \n",
    "    # Check for identities again:\n",
    "    s = s.replace(\"HH\", \"\").replace(\"SSSS\", \"\").replace(\"HH\", \"\")\n",
    "    s = s.replace(\"HH\", \"\").replace(\"SSSS\", \"\").replace(\"HH\", \"\")\n",
    "    return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_table = [[simplify_str(s) for s in row] for row in product_table]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['',\n",
       "  'HS',\n",
       "  'HSS',\n",
       "  'H',\n",
       "  'S',\n",
       "  'HSH',\n",
       "  'SS',\n",
       "  'HSSH',\n",
       "  'HSSS',\n",
       "  'SSS',\n",
       "  'HSSSH',\n",
       "  'HSHS',\n",
       "  'HSHSS',\n",
       "  'HSSHS',\n",
       "  'HSSHSS',\n",
       "  'HSSHSSS',\n",
       "  'SH',\n",
       "  'SSH',\n",
       "  'HSHSSH',\n",
       "  'SSHS',\n",
       "  'SSHSH',\n",
       "  'HSHSH',\n",
       "  'HSHSHS',\n",
       "  'HSSHSH'],\n",
       " ['SH',\n",
       "  'SS',\n",
       "  'SSS',\n",
       "  'S',\n",
       "  'SHS',\n",
       "  'SSH',\n",
       "  'SHSS',\n",
       "  'SSSH',\n",
       "  '',\n",
       "  'SHSSS',\n",
       "  'H',\n",
       "  'SSHS',\n",
       "  'SSHSS',\n",
       "  'SSSHS',\n",
       "  'SSSHSS',\n",
       "  'HSH',\n",
       "  'SHSH',\n",
       "  'SHSSH',\n",
       "  'SSHSSH',\n",
       "  'HSSH',\n",
       "  'HSS',\n",
       "  'SSHSH',\n",
       "  'SSHSHS',\n",
       "  'SSSHSH'],\n",
       " ['SSH',\n",
       "  'SSS',\n",
       "  '',\n",
       "  'SS',\n",
       "  'SSHS',\n",
       "  'SSSH',\n",
       "  'SSHSS',\n",
       "  'H',\n",
       "  'S',\n",
       "  'SSHSSS',\n",
       "  'SH',\n",
       "  'SSSHS',\n",
       "  'SSSHSS',\n",
       "  'HS',\n",
       "  'HSS',\n",
       "  'HSSS',\n",
       "  'SSHSH',\n",
       "  'SSHSSH',\n",
       "  'SSSHSSH',\n",
       "  'SHSSH',\n",
       "  'SHSS',\n",
       "  'SSSHSH',\n",
       "  'SSSHSHS',\n",
       "  'HSH'],\n",
       " ['H',\n",
       "  'S',\n",
       "  'SS',\n",
       "  '',\n",
       "  'HS',\n",
       "  'SH',\n",
       "  'HSS',\n",
       "  'SSH',\n",
       "  'SSS',\n",
       "  'HSSS',\n",
       "  'SSSH',\n",
       "  'SHS',\n",
       "  'SHSS',\n",
       "  'SSHS',\n",
       "  'SSHSS',\n",
       "  'SSHSSS',\n",
       "  'HSH',\n",
       "  'HSSH',\n",
       "  'SHSSH',\n",
       "  'HSSHS',\n",
       "  'HSSHSH',\n",
       "  'SHSH',\n",
       "  'SHSHS',\n",
       "  'SSHSH'],\n",
       " ['HSH',\n",
       "  'HSS',\n",
       "  'HSSS',\n",
       "  'HS',\n",
       "  'HSHS',\n",
       "  'HSSH',\n",
       "  'HSHSS',\n",
       "  'HSSSH',\n",
       "  'H',\n",
       "  'HSHSSS',\n",
       "  '',\n",
       "  'HSSHS',\n",
       "  'HSSHSS',\n",
       "  'HSSSHS',\n",
       "  'HSSSHSS',\n",
       "  'SH',\n",
       "  'HSHSH',\n",
       "  'HSHSSH',\n",
       "  'HSSHSSH',\n",
       "  'SSH',\n",
       "  'SS',\n",
       "  'HSSHSH',\n",
       "  'HSH',\n",
       "  'HSSSHSH'],\n",
       " ['S',\n",
       "  'SHS',\n",
       "  'SHSS',\n",
       "  'SH',\n",
       "  'SS',\n",
       "  'SHSH',\n",
       "  'SSS',\n",
       "  'SHSSH',\n",
       "  'SHSSS',\n",
       "  '',\n",
       "  'SHSSSH',\n",
       "  'SHSHS',\n",
       "  'SHSHSS',\n",
       "  'HSSH',\n",
       "  'HSSHS',\n",
       "  'HSSHSS',\n",
       "  'SSH',\n",
       "  'SSSH',\n",
       "  'SHSHSSH',\n",
       "  'SSSHS',\n",
       "  'SSSHSH',\n",
       "  'SHSHSH',\n",
       "  'SHSHSHS',\n",
       "  'HSS'],\n",
       " ['HSSH',\n",
       "  'HSSS',\n",
       "  'H',\n",
       "  'HSS',\n",
       "  'HSSHS',\n",
       "  'HSSSH',\n",
       "  'HSSHSS',\n",
       "  '',\n",
       "  'HS',\n",
       "  'HSSHSSS',\n",
       "  'HSH',\n",
       "  'HSSSHS',\n",
       "  'HSSSHSS',\n",
       "  'S',\n",
       "  'SS',\n",
       "  'SSS',\n",
       "  'HSSHSH',\n",
       "  'HSSHSSH',\n",
       "  'HSSSHSSH',\n",
       "  'HSHSSH',\n",
       "  'HSHSS',\n",
       "  'HSSSHSH',\n",
       "  'HSSSHSHS',\n",
       "  'SH'],\n",
       " ['SS',\n",
       "  'SSHS',\n",
       "  'SSHSS',\n",
       "  'SSH',\n",
       "  'SSS',\n",
       "  'SSHSH',\n",
       "  '',\n",
       "  'SSHSSH',\n",
       "  'SSHSSS',\n",
       "  'S',\n",
       "  'SSHSSSH',\n",
       "  'SSHSHS',\n",
       "  'SSHSHSS',\n",
       "  'SHSSH',\n",
       "  'SHSSHS',\n",
       "  'SHSSHSS',\n",
       "  'SSSH',\n",
       "  'H',\n",
       "  'SSHSHSSH',\n",
       "  'HS',\n",
       "  'HSH',\n",
       "  'SSHSHSH',\n",
       "  'SSHSHSHS',\n",
       "  'SHSS'],\n",
       " ['SSSH',\n",
       "  '',\n",
       "  'S',\n",
       "  'SSS',\n",
       "  'SSSHS',\n",
       "  'H',\n",
       "  'SSSHSS',\n",
       "  'SH',\n",
       "  'SS',\n",
       "  'HSH',\n",
       "  'SSH',\n",
       "  'HS',\n",
       "  'HSS',\n",
       "  'SHS',\n",
       "  'SHSS',\n",
       "  'SHSSS',\n",
       "  'SSSHSH',\n",
       "  'SSSHSSH',\n",
       "  'HSSH',\n",
       "  'SSHSSH',\n",
       "  'SSHSS',\n",
       "  'HSH',\n",
       "  'HSHS',\n",
       "  'SHSH'],\n",
       " ['HSSSH',\n",
       "  'H',\n",
       "  'HS',\n",
       "  'HSSS',\n",
       "  'HSSSHS',\n",
       "  '',\n",
       "  'HSSSHSS',\n",
       "  'HSH',\n",
       "  'HSS',\n",
       "  'SH',\n",
       "  'HSSH',\n",
       "  'S',\n",
       "  'SS',\n",
       "  'HSHS',\n",
       "  'HSHSS',\n",
       "  'HSHSSS',\n",
       "  'HSSSHSH',\n",
       "  'HSSSHSSH',\n",
       "  'SSH',\n",
       "  'HSSHSSH',\n",
       "  'HSSHSS',\n",
       "  'SH',\n",
       "  'SHS',\n",
       "  'HSHSH'],\n",
       " ['SSS',\n",
       "  'SSSHS',\n",
       "  'SSSHSS',\n",
       "  'SSSH',\n",
       "  '',\n",
       "  'SSSHSH',\n",
       "  'S',\n",
       "  'SSSHSSH',\n",
       "  'HSH',\n",
       "  'SS',\n",
       "  'HS',\n",
       "  'SSSHSHS',\n",
       "  'SSSHSHSS',\n",
       "  'SSHSSH',\n",
       "  'SSHSSHS',\n",
       "  'SSHSSHSS',\n",
       "  'H',\n",
       "  'SH',\n",
       "  'SSSHSHSSH',\n",
       "  'SHS',\n",
       "  'SHSH',\n",
       "  'SSSHSHSH',\n",
       "  'SSSHSHSHS',\n",
       "  'SSHSS'],\n",
       " ['SHSH',\n",
       "  'SHSS',\n",
       "  'SHSSS',\n",
       "  'SHS',\n",
       "  'SHSHS',\n",
       "  'SHSSH',\n",
       "  'SHSHSS',\n",
       "  'SHSSSH',\n",
       "  'SH',\n",
       "  'SHSHSSS',\n",
       "  'S',\n",
       "  'HSSH',\n",
       "  'HSSHS',\n",
       "  'SHSSSHS',\n",
       "  'SHSSSHSS',\n",
       "  'SSH',\n",
       "  'SHSHSH',\n",
       "  'SHSHSSH',\n",
       "  'HSSHSH',\n",
       "  'SSSH',\n",
       "  'SSS',\n",
       "  'HSS',\n",
       "  'HSSS',\n",
       "  'SHSSSHSH'],\n",
       " ['SHSSH',\n",
       "  'SHSSS',\n",
       "  'SH',\n",
       "  'SHSS',\n",
       "  'HSSH',\n",
       "  'SHSSSH',\n",
       "  'HSSHS',\n",
       "  'S',\n",
       "  'SHS',\n",
       "  'HSSHSS',\n",
       "  'SHSH',\n",
       "  'SHSSSHS',\n",
       "  'SHSSSHSS',\n",
       "  'SS',\n",
       "  'SSS',\n",
       "  '',\n",
       "  'HSS',\n",
       "  'HSSHSH',\n",
       "  'SHSSSHSSH',\n",
       "  'HSH',\n",
       "  'HS',\n",
       "  'SHSSSHSH',\n",
       "  'SHSSSHSHS',\n",
       "  'SSH'],\n",
       " ['SSHSH',\n",
       "  'SSHSS',\n",
       "  'SSHSSS',\n",
       "  'SSHS',\n",
       "  'SSHSHS',\n",
       "  'SSHSSH',\n",
       "  'SSHSHSS',\n",
       "  'SSHSSSH',\n",
       "  'SSH',\n",
       "  'SSHSHSSS',\n",
       "  'SS',\n",
       "  'SHSSH',\n",
       "  'SHSSHS',\n",
       "  'SSHSSSHS',\n",
       "  'SSHSSSHSS',\n",
       "  'SSSH',\n",
       "  'SSHSHSH',\n",
       "  'SSHSHSSH',\n",
       "  'SHSSHSH',\n",
       "  'H',\n",
       "  '',\n",
       "  'SHSS',\n",
       "  'SHSSS',\n",
       "  'SSHSSSHSH'],\n",
       " ['SSHSSH',\n",
       "  'SSHSSS',\n",
       "  'SSH',\n",
       "  'SSHSS',\n",
       "  'SHSSH',\n",
       "  'SSHSSSH',\n",
       "  'SHSSHS',\n",
       "  'SS',\n",
       "  'SSHS',\n",
       "  'SHSSHSS',\n",
       "  'SSHSH',\n",
       "  'SSHSSSHS',\n",
       "  'SSHSSSHSS',\n",
       "  'SSS',\n",
       "  '',\n",
       "  'S',\n",
       "  'SHSS',\n",
       "  'SHSSHSH',\n",
       "  'SSHSSSHSSH',\n",
       "  'SHSH',\n",
       "  'SHS',\n",
       "  'SSHSSSHSH',\n",
       "  'SSHSSSHSHS',\n",
       "  'SSSH'],\n",
       " ['SSHSSSH',\n",
       "  'SSH',\n",
       "  'SSHS',\n",
       "  'SSHSSS',\n",
       "  'SSHSSSHS',\n",
       "  'SS',\n",
       "  'SSHSSSHSS',\n",
       "  'SSHSH',\n",
       "  'SSHSS',\n",
       "  'SSSH',\n",
       "  'SSHSSH',\n",
       "  'SSS',\n",
       "  '',\n",
       "  'SSHSHS',\n",
       "  'SSHSHSS',\n",
       "  'SSHSHSSS',\n",
       "  'SSHSSSHSH',\n",
       "  'SSHSSSHSSH',\n",
       "  'H',\n",
       "  'SSHSSHSSH',\n",
       "  'SSHSSHSS',\n",
       "  'SSSH',\n",
       "  'SSSHS',\n",
       "  'SSHSHSH'],\n",
       " ['HS',\n",
       "  'HSHS',\n",
       "  'HSHSS',\n",
       "  'HSH',\n",
       "  'HSS',\n",
       "  'HSHSH',\n",
       "  'HSSS',\n",
       "  'HSHSSH',\n",
       "  'HSHSSS',\n",
       "  'H',\n",
       "  'HSHSSSH',\n",
       "  'HSHSHS',\n",
       "  'HSHSHSS',\n",
       "  'SSH',\n",
       "  'SSHS',\n",
       "  'SSHSS',\n",
       "  'HSSH',\n",
       "  'HSSSH',\n",
       "  'HSHSHSSH',\n",
       "  'HSSSHS',\n",
       "  'HSSSHSH',\n",
       "  'HSHSHSH',\n",
       "  'HSHSHSHS',\n",
       "  'SS'],\n",
       " ['HSS',\n",
       "  'HSSHS',\n",
       "  'HSSHSS',\n",
       "  'HSSH',\n",
       "  'HSSS',\n",
       "  'HSSHSH',\n",
       "  'H',\n",
       "  'HSSHSSH',\n",
       "  'HSSHSSS',\n",
       "  'HS',\n",
       "  'HSSHSSSH',\n",
       "  'HSH',\n",
       "  'HSHS',\n",
       "  'HSHSSH',\n",
       "  'HSHSSHS',\n",
       "  'HSHSSHSS',\n",
       "  'HSSSH',\n",
       "  '',\n",
       "  'HSHSH',\n",
       "  'S',\n",
       "  'SH',\n",
       "  'HS',\n",
       "  'HSS',\n",
       "  'HSHSS'],\n",
       " ['SHSS',\n",
       "  'HSSH',\n",
       "  'HSSHS',\n",
       "  'SHSSH',\n",
       "  'SHSSS',\n",
       "  'HSS',\n",
       "  'SH',\n",
       "  'HSSHSH',\n",
       "  'HSSHSS',\n",
       "  'SHS',\n",
       "  'HSSHSSH',\n",
       "  'HSSS',\n",
       "  'H',\n",
       "  'HSH',\n",
       "  'HSHS',\n",
       "  'HSHSS',\n",
       "  'SHSSSH',\n",
       "  'S',\n",
       "  '',\n",
       "  'SS',\n",
       "  'SSH',\n",
       "  'HSSSH',\n",
       "  'HSSSHS',\n",
       "  'HS'],\n",
       " ['HSSHSH',\n",
       "  'HSSHSS',\n",
       "  'HSSHSSS',\n",
       "  'HSSHS',\n",
       "  'HSH',\n",
       "  'HSSHSSH',\n",
       "  'HSHS',\n",
       "  'HSSHSSSH',\n",
       "  'HSSH',\n",
       "  'HSHSS',\n",
       "  'HSS',\n",
       "  'HSHSSH',\n",
       "  'HSHSSHS',\n",
       "  'HSSHSSSHS',\n",
       "  'HSSHSSSHSS',\n",
       "  'HSSSH',\n",
       "  'HS',\n",
       "  'HSHSH',\n",
       "  'HSHSSHSH',\n",
       "  '',\n",
       "  'H',\n",
       "  'HSHSS',\n",
       "  'HSHSSS',\n",
       "  'HSSHSSSHSH'],\n",
       " ['HSSHS',\n",
       "  'HSH',\n",
       "  'HSHS',\n",
       "  'HSSHSH',\n",
       "  'HSSHSS',\n",
       "  'HS',\n",
       "  'HSSHSSS',\n",
       "  'HSHSH',\n",
       "  'HSHSS',\n",
       "  'HSSH',\n",
       "  'HSHSSH',\n",
       "  'HSS',\n",
       "  'HSSS',\n",
       "  '',\n",
       "  'S',\n",
       "  'SS',\n",
       "  'HSSHSSH',\n",
       "  'HSSHSSSH',\n",
       "  'HSSSH',\n",
       "  'HSSHSSSHS',\n",
       "  'HSSHSSSHSH',\n",
       "  'HSSH',\n",
       "  'HSSHS',\n",
       "  'H'],\n",
       " ['SHS',\n",
       "  'SHSHS',\n",
       "  'SHSHSS',\n",
       "  'SHSH',\n",
       "  'SHSS',\n",
       "  'SHSHSH',\n",
       "  'SHSSS',\n",
       "  'SHSHSSH',\n",
       "  'SHSHSSS',\n",
       "  'SH',\n",
       "  'SHSHSSSH',\n",
       "  'SHSHSHS',\n",
       "  'SHSHSHSS',\n",
       "  'SSSH',\n",
       "  'SSSHS',\n",
       "  'SSSHSS',\n",
       "  'SHSSH',\n",
       "  'SHSSSH',\n",
       "  'SHSHSHSSH',\n",
       "  'SHSSSHS',\n",
       "  'SHSSSHSH',\n",
       "  'SHSHSHSH',\n",
       "  'SHSHSHSHS',\n",
       "  'SSS'],\n",
       " ['SHSHSH',\n",
       "  'SHSHSS',\n",
       "  'SHSHSSS',\n",
       "  'SHSHS',\n",
       "  'SHSHSHS',\n",
       "  'SHSHSSH',\n",
       "  'SHSHSHSS',\n",
       "  'SHSHSSSH',\n",
       "  'SHSH',\n",
       "  'SHSHSHSSS',\n",
       "  'SHS',\n",
       "  'SSSH',\n",
       "  'SSSHS',\n",
       "  'SHSHSSSHS',\n",
       "  'SHSHSSSHSS',\n",
       "  'SHSSH',\n",
       "  'SHSHSHSH',\n",
       "  'SHSHSHSSH',\n",
       "  'SSSHSH',\n",
       "  'SHSSSH',\n",
       "  'SHSSS',\n",
       "  'SSS',\n",
       "  '',\n",
       "  'SHSHSSSHSH']]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "product_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'H': 0,\n",
       " 'S': 1,\n",
       " 'SS': 2,\n",
       " 'HH': 3,\n",
       " 'HS': 4,\n",
       " 'SH': 5,\n",
       " 'HSS': 6,\n",
       " 'SSH': 7,\n",
       " 'SSS': 8,\n",
       " 'HSSS': 9,\n",
       " 'SSSH': 10,\n",
       " 'SHS': 11,\n",
       " 'SHSS': 12,\n",
       " 'SSHS': 13,\n",
       " 'SSHSS': 14,\n",
       " 'SSHSSS': 15,\n",
       " 'HSH': 16,\n",
       " 'HSSH': 17,\n",
       " 'SHSSH': 18,\n",
       " 'HSSHS': 19,\n",
       " 'HSSHSH': 20,\n",
       " 'SHSH': 21,\n",
       " 'SHSHS': 22,\n",
       " 'SSHSH': 23,\n",
       " '': 3}"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LC_indices = {c:i for i,c in enumerate(LC)}\n",
    "LC_indices[\"\"] = 3\n",
    "\n",
    "LC_indices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_table = [[LC_indices[p] if p in LC_indices else p for p in row] for row in product_table]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we have to compute the missing elements manually. But at first flatten the list and remove duplicates."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['HSHS',\n",
       " 'SSSHS',\n",
       " 'HSHSS',\n",
       " 'HSSSH',\n",
       " 'SHSSS',\n",
       " 'HSHSH',\n",
       " 'SHSHSH',\n",
       " 'HSHSSS',\n",
       " 'HSHSSH',\n",
       " 'HSHSHS',\n",
       " 'SSSHSH',\n",
       " 'SSHSSH',\n",
       " 'HSSSHS',\n",
       " 'SHSHSS',\n",
       " 'HSSHSS',\n",
       " 'SHSSSH',\n",
       " 'SHSSHS',\n",
       " 'SSSHSS',\n",
       " 'SSHSHS',\n",
       " 'HSSSHSH',\n",
       " 'SSSHSSH',\n",
       " 'HSHSSSH',\n",
       " 'SHSHSSH',\n",
       " 'HSHSSHS',\n",
       " 'HSHSHSH',\n",
       " 'SSSHSHS',\n",
       " 'HSHSHSS',\n",
       " 'SHSSHSS',\n",
       " 'SHSHSSS',\n",
       " 'HSSHSSS',\n",
       " 'HSSSHSS',\n",
       " 'SSHSHSS',\n",
       " 'SHSSHSH',\n",
       " 'SSHSHSH',\n",
       " 'SSHSSHS',\n",
       " 'HSSHSSH',\n",
       " 'SHSSSHS',\n",
       " 'SHSHSHS',\n",
       " 'SSHSSSH',\n",
       " 'SHSSSHSS',\n",
       " 'HSHSSHSS',\n",
       " 'SHSHSHSS',\n",
       " 'SSHSHSSS',\n",
       " 'HSSSHSSH',\n",
       " 'HSHSHSHS',\n",
       " 'HSHSHSSH',\n",
       " 'HSSSHSHS',\n",
       " 'SSHSHSSH',\n",
       " 'SHSSSHSH',\n",
       " 'SSSHSHSH',\n",
       " 'SSHSHSHS',\n",
       " 'HSSHSSSH',\n",
       " 'SHSHSSSH',\n",
       " 'SSHSSHSS',\n",
       " 'SSSHSHSS',\n",
       " 'HSHSSHSH',\n",
       " 'SHSHSHSH',\n",
       " 'SSHSSSHS',\n",
       " 'SSSHSHSHS',\n",
       " 'SSHSSHSSH',\n",
       " 'SSHSSSHSH',\n",
       " 'SHSHSHSSS',\n",
       " 'SSSHSHSSH',\n",
       " 'SHSHSHSHS',\n",
       " 'HSSHSSSHS',\n",
       " 'SSHSSSHSS',\n",
       " 'SHSSSHSHS',\n",
       " 'SHSSSHSSH',\n",
       " 'SHSHSHSSH',\n",
       " 'SHSHSSSHS',\n",
       " 'SHSHSSSHSS',\n",
       " 'SHSHSSSHSH',\n",
       " 'SSHSSSHSSH',\n",
       " 'HSSHSSSHSS',\n",
       " 'HSSHSSSHSH',\n",
       " 'SSHSSSHSHS']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unresolved_products = [[p for p in row if not isinstance(p, int)] for row in product_table]\n",
    "unresolved_products = reduce(iconcat, unresolved_products)\n",
    "unresolved_products = list(sorted(set(unresolved_products), key=lambda x: len(x)))\n",
    "unresolved_products"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we can now add new identities, which will allow us to reduce the re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJkAAAAzCAYAAACE26oyAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFeElEQVR4Ae1bgVHcMBD8z1AAUMKnA5h08HQAkwoCHcCkAoZ0AC1QAtBBQgehhOQ7+Ow+EqPI7/fZ0r3PtjSjsSzL8mq1Psmybj6bzQ4RK2G9Xq8qmcYz5vM523IM7G/GoZqFl8Khu7fStk/I+YX4N4p3cUlWgHiJyPJWw3cAO7cKbgIcPoL7WEuPB65DzvD2P9d1Dsg5wbWlu77V8tXdu898tOFmn89r86wpcAj+z0JO0OZLnF94kYXXKmnc/IrMV9xk1kpUQBvLmDKHIpEZ668KHIifVpbW9gs686JSoGQ0MqDJIedkYwg00w+I5yDL7HBunGg1DgcvMohqgc67RaQ1e4MlG9xXcd/i0+awV5HRRCNyctg5QFReWFeo5L5zRQO9cQgc9ioy9CuHtuThDUSzDlqyB6Q5N5tSMM9h3yLLJQYK7NUNlV9zVTqxetQ4FIkM1mGByAVaLnYyfY94bagTuMb35jCZHDKBbbIcHkiEwnkPypld6HQWzPTSxZQ5FFkyiRBLmcJAHQONlgxmfl13s8/HWzr36W1H1MEhjGN+HI6Zgev8MowD51g7rVMObPFDNc5z4Bwyh40iaxKQpFNQxzYRUVz8TbXA9R+SeuIyObDFdWqc58A5ZA7LcKmhqlLnfww0WjKWhsXhWgy/LBkW74fZN7xdK5fu7WAZW0iKZZza2EQiA1l3obkGKM6xuK/sc0hkT2nL2EJKLONUxSYdLrlZMZy4c82M6z4WVtctYwtFZhmnKjapyDhx/xkyZihtGVtIk2WcqthEwyWGSm6jCQNB8cc0NzOmBM7pkuZ1ithS2lW5VxGneQ5FIgsZc0Mklx5Ow/wuaRBfu+W7S305sXV5vvSenDiHwKF0uNzwB3L4Zcn52Ckal2SBpB0iLWcZW9gGyzi1sIktmQcAcW2cBXDOSf8K5727n1nGtk1gU+NQZMlcJ3LZ4pbicgLjvOxPSGIfacvYQj4s49TGxn+OvxGv8HbVzo8Agr50hyFpTOOenf8s4/Ia55axhe21jLMNNpSlDkQO1Ci7cYkTWTKI6QgVM9J68cf13ILAgIVCPwrw8B/ojRVsxOdDiNPjjXGyA9kxiHt1oJZg8+3AkX9+WrlGiuZkaDTnX0v3oIpFc/m9H0CW2T1vTeSMmWORyNB5xbm3SSWJ18fMsUhkifyp3w4rQCtLa1uce5XYTuFYNCdTwp2zWjXH1JwgB15XZ44HLzK8YQt03i0irZn3wRx4f9qCn8rx4EWGuYwXFr98uZZXQsAAhznEXh2oBy8y8gkS+cVLSzZF515SsCuQm+QVgRSORyEykEiBFefeXVJLv9aZY5HIoOLJOqam942shjFzfCChgPMelDO70Al8K+Db6T4naWefZcbMsciS9Ul+efbwGWi0ZDDjOZx7OfF8QWwzAb3A271z520ObKldCAzJbcvRDtTBL2vOm+JwzAxc59d3HPbiQN0oMnR08k4LN5wl76SNGcqBLa6z7XmOtuVoB+rYJiITDtRluGyrqlK+NQONlow1uiGBWzwYFu+H4tzreMhyGDPHIpGBRVXnz8ResoytTdMstyMZG3fGLjGmcwPg1ojrnPx/lEGa1ox5J3X37Cvf4TCJrQ0HWu1AvdxgeN0GS1y2Kzbcx99ZT9I5GSeVxbkXJCiG0XIsGi6hbC3n3uQ+s4ytTeMU28GFasbOIRWbSGQhOkxQuTkwi3NvWG+OtGVsbdqXsx0QSK2DUBtMvmwXbNLhcvMMPIBzseLc6xlXOI6RY7El843Hm1GcexXExSrHyrG3ZNxlQXesjxjy6BrP3xbFuTckJmN6DByH+mEa9DDOvHMvh8EwPMBiffymwA3FuTdkRyE9Bo7RhidQs4zoef4HSJuW4sfu9v0AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} + \\frac{i}{2} & \\frac{1}{2} + \\frac{i}{2}\\\\\\frac{1}{2} - \\frac{i}{2} & - \\frac{1}{2} + \\frac{i}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "⎡1   ⅈ   1   ⅈ ⎤\n",
       "⎢─ + ─   ─ + ─ ⎥\n",
       "⎢2   2   2   2 ⎥\n",
       "⎢              ⎥\n",
       "⎢1   ⅈ    1   ⅈ⎥\n",
       "⎢─ - ─  - ─ + ─⎥\n",
       "⎣2   2    2   2⎦"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evalstr(\"HSHS\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
