<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Oregon Curriculum Network](http://www.4dsolutions.net/ocn) <br />\n",
    "[Discovering Math with Python](Introduction.ipynb)\n",
    "\n",
    "\n",
    "# Quadrays and Graphene\n",
    "\n",
    "\"Graphene\" refers to an hexagonal grid of cells, the vertexes being carbon atoms.  However any hexagonal mesh, such as for game boards, might be referred to as a \"graphene pattern\".\n",
    "\n",
    "![quadrays](https://upload.wikimedia.org/wikipedia/commons/9/99/Quadray.gif)\n",
    "\n",
    "Quadrays are explained [in other Notebooks](Polyhedrons%20101.ipynb).  Four basis vectors emanate to the corners of a volume 1 tetrahedron of edges 2R or 1D, in the canonical version, where R and D refer respectively to the Radius and Diameter of imaginary spheres packed together, giving this home base tetrahedron.\n",
    "\n",
    "<a data-flickr-embed=\"true\"  href=\"https://www.flickr.com/photos/kirbyurner/4949799682/in/photolist-QrfReH-P6io19-rjBnbH-qAgksK-r4ZbJn-fwsLq7-fwsE89-fwdt8t-fwsARu-bStzCF-aLJQHM-aGEtcc-aGEsgV-av2K9p-av5qkq-av2J8D-aqh2KP-8ryECF-8pNQJf-8pKEmB-8teEm2-7tqppn-7jL9N8-9BgiDc-9f5Bg7-8xp1ZQ-8tm3iL-8teDJ4-8thDyL-8thDHW-8iYwQE-8dD6VR-88zTZp-7Pz6gD-7L5wXD-7ioGLf-7eY1if-6CyHE6-6oVyku-5UeC8d-5QFhfS-5sWMh2-5rFZdz-5rFZ9z-5G8Sf5-7k4Em5-7k4Ejf-7jZLhp-7jZLgD-7k4EkC\" title=\"Tetrahedron\"><img src=\"https://farm5.staticflickr.com/4143/4949799682_327b33e8d5.jpg\" width=\"375\" height=\"500\" alt=\"Tetrahedron\"></a><script async src=\"//embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>\n",
    "\n",
    "The Quadrays {2, 1, 1, 0}, meaning all 12 permutations of those numbers, fan out from (0,0,0,0) to the corners of a cuboctahedron.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1, 1, 2), (1, 0, 1, 2), (2, 0, 1, 1), (0, 2, 1, 1), (0, 1, 2, 1), (1, 2, 1, 0), (1, 1, 2, 0), (2, 1, 1, 0), (1, 0, 2, 1), (1, 2, 0, 1), (2, 1, 0, 1), (1, 1, 0, 2)}\n"
     ]
    }
   ],
   "source": [
    "from itertools import permutations\n",
    "g = permutations((2,1,1,0))\n",
    "unique = {p for p in g}  # set comprehension\n",
    "print(unique)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I have [elsewhere](Generating%20the%20FCC.ipynb) used this fact to algorithmically generate consecutive shells of 12, 42, 92, 162... spheres (balls) respectively; a growing cuboctahedron of $10 S^{2} + 2$ balls.\n",
    "\n",
    "![Image of Cubocta](http://www.4dsolutions.net/ocn/graphics/cubanim.gif)\n",
    "\n",
    "However suppose we don't want to grow the grid omni-directionally, but only in a plane?  Each ball will be surrounded by six neighbors meaning at the center of a hexagon.\n",
    "\n",
    "## The Algorithm\n",
    "One algorithm would be to use a planar subset of the vectors {2, 1, 1, 0} to compute the six vertexes surrounding (0,0,0,0).  \n",
    "\n",
    "Then hop to neighboring hexagon centers using an additional set of vectors, and compute the six surrounding vertexes again, some of which will have already been found.  Filter to keep only unique vertexes.  \n",
    "\n",
    "Keep track of hexagon centers, a dual mesh, in a separate set.  \n",
    "\n",
    "(0,0,0,0) will be the first center (ring0)\n",
    "\n",
    "If qrays r, s are 60 degrees apart on the same hexagon, then r + s will be the \"hop\" vector over the fence (edge) to the neighboring \"yard\" (face).  \n",
    "\n",
    "Once we have six vertex vectors from a center, computing the six hop vectors (for jumping over the fences) will be a matter of summing pairs of adjacent (60 degree separated) vectors.\n",
    "\n",
    "What about edges?\n",
    "\n",
    "As we go around a hexagon in 60 degree increments, say in a clockwise direction, we will be finding edges in terms of adjacent ball pairs.  \n",
    "\n",
    "To avoid redundancy, (ball_a, ball_b) -- any edge -- will be sorted.  Any two quadrays may be ordered as 4-tuples e.g. (2, 1, 1, 0) is \"greater than\" (2, 1, 0, 1).  \n",
    "\n",
    "With unique representations of any edge, in the form of sorted tuples of qray namedtuples, we will be able to employ the same general technique employed with vertexes and face centers:  check the existing database for uniqueness and throw away anything already in the database.\n",
    "\n",
    "The first step is to isolate six of the twelve from {2, 1, 1, 0} that define a hexagon."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<table class=\"multicol\" role=\"presentation\" style=\"border-collapse: collapse; padding: 0; border: 0; background:transparent; width:100%;\"><tbody><tr>\n",
    "<td style=\"text-align: left; vertical-align: top;\">\n",
    "<table class=\"wikitable\">\n",
    "\n",
    "<tbody><tr>\n",
    "<th>Shape\n",
    "</th>\n",
    "<th>Volume\n",
    "</th>\n",
    "<th>Vertex Inventory (sum of Quadrays)\n",
    "</th></tr>\n",
    "<tr>\n",
    "<td>Tetrahedron\n",
    "</td>\n",
    "<td>1\n",
    "</td>\n",
    "<td>A,B,C,D\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Inverse Tetrahedron\n",
    "</td>\n",
    "<td>1\n",
    "</td>\n",
    "<td>E,F,G,H = B+C+D, A+C+D, A+B+D, A+B+C\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Duo-Tet Cube\n",
    "</td>\n",
    "<td>3\n",
    "</td>\n",
    "<td>A through H\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Octahedron\n",
    "</td>\n",
    "<td>4\n",
    "</td>\n",
    "<td>I,J,K,L,M,N = A+B, A+C, A+D, B+C, B+D, C+D\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Rhombic Dodecahedron\n",
    "</td>\n",
    "<td>6\n",
    "</td>\n",
    "<td>A through N\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Cuboctahedron\n",
    "</td>\n",
    "<td>20\n",
    "</td>\n",
    "<td>O,P,Q,R,S,T = I+J, I+K, I+L, I+M, N+J, N+K; U,V,W,X,Y,Z = N+L, N+M, J+L, L+M, M+K, K+J\n",
    "</td></tr></tbody></table>\n",
    "<p>&#32;\n",
    "</p>\n",
    "</td>\n",
    "<td style=\"text-align: left; vertical-align: top;\">\n",
    "<p><a href=\"/wiki/File:Povlabels.gif\" class=\"image\" title=\"Points A-Z\"><img alt=\"Points A-Z\" src=\"//upload.wikimedia.org/wikipedia/commons/d/dc/Povlabels.gif\" width=\"320\" height=\"240\" data-file-width=\"320\" data-file-height=\"240\" /></a>\n",
    "&#32;\n",
    "</p>\n",
    "</td></tr></tbody></table>"
   ]
  },
  {
   "cell_type": "markdown",<commit_msg>fixing link to wikipedia<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Oregon Curriculum Network](http://www.4dsolutions.net/ocn) <br />\n",
    "[Discovering Math with Python](Introduction.ipynb)\n",
    "\n",
    "\n",
    "# Quadrays and Graphene\n",
    "\n",
    "\"Graphene\" refers to an hexagonal grid of cells, the vertexes being carbon atoms.  However any hexagonal mesh, such as for game boards, might be referred to as a \"graphene pattern\".\n",
    "\n",
    "![quadrays](https://upload.wikimedia.org/wikipedia/commons/9/99/Quadray.gif)\n",
    "\n",
    "Quadrays are explained [in other Notebooks](Polyhedrons%20101.ipynb).  Four basis vectors emanate to the corners of a volume 1 tetrahedron of edges 2R or 1D, in the canonical version, where R and D refer respectively to the Radius and Diameter of imaginary spheres packed together, giving this home base tetrahedron.\n",
    "\n",
    "<a data-flickr-embed=\"true\"  href=\"https://www.flickr.com/photos/kirbyurner/4949799682/in/photolist-QrfReH-P6io19-rjBnbH-qAgksK-r4ZbJn-fwsLq7-fwsE89-fwdt8t-fwsARu-bStzCF-aLJQHM-aGEtcc-aGEsgV-av2K9p-av5qkq-av2J8D-aqh2KP-8ryECF-8pNQJf-8pKEmB-8teEm2-7tqppn-7jL9N8-9BgiDc-9f5Bg7-8xp1ZQ-8tm3iL-8teDJ4-8thDyL-8thDHW-8iYwQE-8dD6VR-88zTZp-7Pz6gD-7L5wXD-7ioGLf-7eY1if-6CyHE6-6oVyku-5UeC8d-5QFhfS-5sWMh2-5rFZdz-5rFZ9z-5G8Sf5-7k4Em5-7k4Ejf-7jZLhp-7jZLgD-7k4EkC\" title=\"Tetrahedron\"><img src=\"https://farm5.staticflickr.com/4143/4949799682_327b33e8d5.jpg\" width=\"375\" height=\"500\" alt=\"Tetrahedron\"></a><script async src=\"//embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>\n",
    "\n",
    "The Quadrays {2, 1, 1, 0}, meaning all 12 permutations of those numbers, fan out from (0,0,0,0) to the corners of a cuboctahedron.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1, 1, 2), (1, 0, 1, 2), (2, 0, 1, 1), (0, 2, 1, 1), (0, 1, 2, 1), (1, 2, 1, 0), (1, 1, 2, 0), (2, 1, 1, 0), (1, 0, 2, 1), (1, 2, 0, 1), (2, 1, 0, 1), (1, 1, 0, 2)}\n"
     ]
    }
   ],
   "source": [
    "from itertools import permutations\n",
    "g = permutations((2,1,1,0))\n",
    "unique = {p for p in g}  # set comprehension\n",
    "print(unique)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I have [elsewhere](Generating%20the%20FCC.ipynb) used this fact to algorithmically generate consecutive shells of 12, 42, 92, 162... spheres (balls) respectively; a growing cuboctahedron of $10 S^{2} + 2$ balls.\n",
    "\n",
    "![Image of Cubocta](http://www.4dsolutions.net/ocn/graphics/cubanim.gif)\n",
    "\n",
    "However suppose we don't want to grow the grid omni-directionally, but only in a plane?  Each ball will be surrounded by six neighbors meaning at the center of a hexagon.\n",
    "\n",
    "## The Algorithm\n",
    "One algorithm would be to use a planar subset of the vectors {2, 1, 1, 0} to compute the six vertexes surrounding (0,0,0,0).  \n",
    "\n",
    "Then hop to neighboring hexagon centers using an additional set of vectors, and compute the six surrounding vertexes again, some of which will have already been found.  Filter to keep only unique vertexes.  \n",
    "\n",
    "Keep track of hexagon centers, a dual mesh, in a separate set.  \n",
    "\n",
    "(0,0,0,0) will be the first center (ring0)\n",
    "\n",
    "If qrays r, s are 60 degrees apart on the same hexagon, then r + s will be the \"hop\" vector over the fence (edge) to the neighboring \"yard\" (face).  \n",
    "\n",
    "Once we have six vertex vectors from a center, computing the six hop vectors (for jumping over the fences) will be a matter of summing pairs of adjacent (60 degree separated) vectors.\n",
    "\n",
    "What about edges?\n",
    "\n",
    "As we go around a hexagon in 60 degree increments, say in a clockwise direction, we will be finding edges in terms of adjacent ball pairs.  \n",
    "\n",
    "To avoid redundancy, (ball_a, ball_b) -- any edge -- will be sorted.  Any two quadrays may be ordered as 4-tuples e.g. (2, 1, 1, 0) is \"greater than\" (2, 1, 0, 1).  \n",
    "\n",
    "With unique representations of any edge, in the form of sorted tuples of qray namedtuples, we will be able to employ the same general technique employed with vertexes and face centers:  check the existing database for uniqueness and throw away anything already in the database.\n",
    "\n",
    "The first step is to isolate six of the twelve from {2, 1, 1, 0} that define a hexagon."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<table class=\"multicol\" role=\"presentation\" style=\"border-collapse: collapse; padding: 0; border: 0; background:transparent; width:100%;\"><tbody><tr>\n",
    "<td style=\"text-align: left; vertical-align: top;\">\n",
    "<table class=\"wikitable\">\n",
    "\n",
    "<tbody><tr>\n",
    "<th>Shape\n",
    "</th>\n",
    "<th>Volume\n",
    "</th>\n",
    "<th>Vertex Inventory (sum of Quadrays)\n",
    "</th></tr>\n",
    "<tr>\n",
    "<td>Tetrahedron\n",
    "</td>\n",
    "<td>1\n",
    "</td>\n",
    "<td>A,B,C,D\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Inverse Tetrahedron\n",
    "</td>\n",
    "<td>1\n",
    "</td>\n",
    "<td>E,F,G,H = B+C+D, A+C+D, A+B+D, A+B+C\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Duo-Tet Cube\n",
    "</td>\n",
    "<td>3\n",
    "</td>\n",
    "<td>A through H\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Octahedron\n",
    "</td>\n",
    "<td>4\n",
    "</td>\n",
    "<td>I,J,K,L,M,N = A+B, A+C, A+D, B+C, B+D, C+D\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Rhombic Dodecahedron\n",
    "</td>\n",
    "<td>6\n",
    "</td>\n",
    "<td>A through N\n",
    "</td></tr>\n",
    "<tr>\n",
    "<td>Cuboctahedron\n",
    "</td>\n",
    "<td>20\n",
    "</td>\n",
    "<td>O,P,Q,R,S,T = I+J, I+K, I+L, I+M, N+J, N+K; U,V,W,X,Y,Z = N+L, N+M, J+L, L+M, M+K, K+J\n",
    "</td></tr></tbody></table>\n",
    "<p>&#32;\n",
    "</p>\n",
    "</td>\n",
    "<td style=\"text-align: left; vertical-align: top;\">\n",
    "<p><a href=\"https://upload.wikimedia.org/wikipedia/commons/d/dc/Povlabels.gif\" class=\"image\" title=\"Points A-Z\"><img alt=\"Points A-Z\" src=\"//upload.wikimedia.org/wikipedia/commons/d/dc/Povlabels.gif\" width=\"320\" height=\"240\" data-file-width=\"320\" data-file-height=\"240\" /></a>\n",
    "&#32;\n",
    "</p>\n",
    "</td></tr></tbody></table>"
   ]
  },
  {
   "cell_type": "markdown",
{'fraction_non_alphanumeric': 0.20916274122473788, 'fraction_numerical': 0.039811578787418325, 'mean_word_length': 2.9564171926660654, 'pattern_counts': {'":': 38, '<': 169, '<?xml version=': 0, '>': 169, 'https://': 7, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '775687', 'n_tokens_mistral': 5585, 'n_tokens_neox': 5271, 'n_words': 1382}