{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Cf. [\"Bananas, Lenses, & Barbed Wire\"](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.41.125)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# [Hylomorphism](https://en.wikipedia.org/wiki/Hylomorphism_%28computer_science%29)\n",
    "A [hylomorphism](https://en.wikipedia.org/wiki/Hylomorphism_%28computer_science%29) `H :: A -> B` converts a value of type A into a value of type B by means of:\n",
    "\n",
    "- A generator `G :: A -> (A, B)`\n",
    "- A combiner `F :: (B, B) -> B`\n",
    "- A predicate `P :: A -> Bool` to detect the base case\n",
    "- A base case value `c :: B`\n",
    "- Recursive calls (zero or more); it has a \"call stack in the form of a cons list\".\n",
    "\n",
    "It may be helpful to see this function implemented in imperative Python code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def hylomorphism(c, F, P, G):\n",
    "    '''Return a hylomorphism function H.'''\n",
    "\n",
    "    def H(a):\n",
    "        if P(a):\n",
    "            result = c\n",
    "        else:\n",
    "            b, aa = G(a)\n",
    "            result = F(b, H(aa))\n",
    "        return result\n",
    "\n",
    "    return H"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Finding [Triangular Numbers](https://en.wikipedia.org/wiki/Triangular_number)\n",
    "As a concrete example let's use a function that, given a positive integer, returns the sum of all positive integers less than that one.  (In this case the types A and B are both `int`.)\n",
    "### With `range()` and `sum()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = range(10)\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range_sum = lambda n: sum(range(n))\n",
    "range_sum(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### As a hylomorphism"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "G = lambda n: (n - 1, n - 1)\n",
    "F = lambda a, b: a + b\n",
    "P = lambda n: n <= 1\n",
    "\n",
    "H = hylomorphism(0, F, P, G)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "H(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you were to run the above code in a debugger and check out the call stack you would find that the variable `b` in each call to `H()` is storing the intermediate values as `H()` recurses.  This is what was meant by \"call stack in the form of a cons list\"."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Joy Preamble"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from notebook_preamble import D, DefinitionWrapper, J, V, define"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Hylomorphism in Joy\n",
    "We can define a combinator `hylomorphism` that will make a hylomorphism combinator `H` from constituent parts.\n",
    "\n",
    "    H == c [F] [P] [G] hylomorphism\n",
    "\n",
    "The function `H` is recursive, so we start with `ifte` and set the else-part to\n",
    "some function `J` that will contain a quoted copy of `H`.  (The then-part just\n",
    "discards the leftover `a` and replaces it with the base case value `c`.)\n",
    "\n",
    "    H == [P] [pop c] [J] ifte\n",
    "\n",
    "The else-part `J` gets just the argument `a` on the stack.\n",
    "\n",
    "    a J\n",
    "    a G              The first thing to do is use the generator G\n",
    "    aa b             which produces b and a new aa\n",
    "    aa b [H] dip     we recur with H on the new aa\n",
    "    aa H b F         and run F on the result.\n",
    "\n",
    "This gives us a definition for `J`.\n",
    "\n",
    "    J == G [H] dip F\n",
    "\n",
    "Plug it in and convert to genrec.\n",
    "\n",
    "    H == [P] [pop c] [G [H] dip F] ifte\n",
    "    H == [P] [pop c] [G]   [dip F] genrec\n",
    "\n",
    "This is the form of a hylomorphism in Joy, which nicely illustrates that\n",
    "it is a simple specialization of the general recursion combinator.\n",
    "\n",
    "    H == [P] [pop c] [G] [dip F] genrec"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Derivation of `hylomorphism`\n",
    "\n",
    "Now we just need to derive a definition that builds the `genrec` arguments\n",
    "out of the pieces given to the `hylomorphism` combinator.\n",
    "\n",
    "    H == [P] [pop c]              [G]                  [dip F] genrec\n",
    "         [P] [c]    [pop] swoncat [G]        [F] [dip] swoncat genrec\n",
    "         [P] c unit [pop] swoncat [G]        [F] [dip] swoncat genrec\n",
    "         [P] c [G] [F] [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
    "\n",
    "Working in reverse:\n",
    "- Use `swoncat` twice to decouple `[c]` and `[F]`.\n",
    "- Use `unit` to dequote `c`.\n",
    "- Use `dipd` to untangle `[unit [pop] swoncat]` from the givens.\n",
    "\n",
    "At this point all of the arguments (givens) to the hylomorphism are to the left so we have\n",
    "a definition for `hylomorphism`:\n",
    "\n",
    "    hylomorphism == [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
    "\n",
    "The order of parameters is different than the one we started with but\n",
    "that hardly matters, you can rearrange them or just supply them in the\n",
    "expected order.\n",
    "\n",
    "    [P] c [G] [F] hylomorphism == H\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "define('hylomorphism == [unit [pop] swoncat] dipd [dip] swoncat genrec')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Demonstrate summing a range of integers from 0 to n-1.\n",
    "\n",
    "- `[P]` is `[0 <=]`\n",
    "- `c` is `0`\n",
    "- `[G]` is `[1 - dup]`\n",
    "- `[F]` is `[+]`\n",
    "\n",
    "So to sum the positive integers less than five we can do this."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                                               . 5 [0 <=] 0 [1 - dup] [+] hylomorphism\n",
      "                                                                             5 . [0 <=] 0 [1 - dup] [+] hylomorphism\n",
      "                                                                      5 [0 <=] . 0 [1 - dup] [+] hylomorphism\n",
      "                                                                    5 [0 <=] 0 . [1 - dup] [+] hylomorphism\n",
      "                                                          5 [0 <=] 0 [1 - dup] . [+] hylomorphism\n",
      "                                                      5 [0 <=] 0 [1 - dup] [+] . hylomorphism\n",
      "                                                      5 [0 <=] 0 [1 - dup] [+] . [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
      "                                 5 [0 <=] 0 [1 - dup] [+] [unit [pop] swoncat] . dipd [dip] swoncat genrec\n",
      "                                                                    5 [0 <=] 0 . unit [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                                    5 [0 <=] 0 . [] cons [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                                 5 [0 <=] 0 [] . cons [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                                  5 [0 <=] [0] . [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                            5 [0 <=] [0] [pop] . swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                            5 [0 <=] [0] [pop] . swap concat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                            5 [0 <=] [pop] [0] . concat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                              5 [0 <=] [pop 0] . [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                    5 [0 <=] [pop 0] [1 - dup] . [+] [dip] swoncat genrec\n",
      "                                                5 [0 <=] [pop 0] [1 - dup] [+] . [dip] swoncat genrec\n",
      "                                          5 [0 <=] [pop 0] [1 - dup] [+] [dip] . swoncat genrec\n",
      "                                          5 [0 <=] [pop 0] [1 - dup] [+] [dip] . swap concat genrec\n",
      "                                          5 [0 <=] [pop 0] [1 - dup] [dip] [+] . concat genrec\n",
      "                                            5 [0 <=] [pop 0] [1 - dup] [dip +] . genrec\n",
      "    5 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte\n",
      "5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [5] [0 <=] . infra first choice i\n",
      "                                                                             5 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] swaack first choice i\n",
      "                                                                           5 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] swaack first choice i\n",
      "                                                                         False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] swaack first choice i\n",
      "   False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] . swaack first choice i\n",
      "   5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i\n",
      "     5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i\n",
      "                   5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i\n",
      "                                                                             5 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                                                           5 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                                                             4 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                                                           4 4 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                 4 4 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip +\n",
      "                                                                             4 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 4 +\n",
      "                                                                      4 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 4 +\n",
      "                                                              4 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 4 +\n",
      "                                                    4 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 4 +\n",
      "                                            4 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 4 +\n",
      "    4 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 4 +\n",
      "4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [4] [0 <=] . infra first choice i 4 +\n",
      "                                                                             4 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] swaack first choice i 4 +\n",
      "                                                                           4 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] swaack first choice i 4 +\n",
      "                                                                         False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] swaack first choice i 4 +\n",
      "   False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] . swaack first choice i 4 +\n",
      "   4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 4 +\n",
      "     4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 4 +\n",
      "                   4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 4 +\n",
      "                                                                             4 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 +\n",
      "                                                                           4 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 +\n",
      "                                                                             3 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 +\n",
      "                                                                           3 3 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 +\n",
      "                                 3 3 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 4 +\n",
      "                                                                             3 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 3 + 4 +\n",
      "                                                                      3 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 3 + 4 +\n",
      "                                                              3 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 3 + 4 +\n",
      "                                                    3 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 3 + 4 +\n",
      "                                            3 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 3 + 4 +\n",
      "    3 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 3 + 4 +\n",
      "3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [3] [0 <=] . infra first choice i 3 + 4 +\n",
      "                                                                             3 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] swaack first choice i 3 + 4 +\n",
      "                                                                           3 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] swaack first choice i 3 + 4 +\n",
      "                                                                         False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] swaack first choice i 3 + 4 +\n",
      "   False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] . swaack first choice i 3 + 4 +\n",
      "   3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 3 + 4 +\n",
      "     3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 3 + 4 +\n",
      "                   3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 3 + 4 +\n",
      "                                                                             3 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 +\n",
      "                                                                           3 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 +\n",
      "                                                                             2 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 +\n",
      "                                                                           2 2 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 +\n",
      "                                 2 2 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 3 + 4 +\n",
      "                                                                             2 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 2 + 3 + 4 +\n",
      "                                                                      2 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 2 + 3 + 4 +\n",
      "                                                              2 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 2 + 3 + 4 +\n",
      "                                                    2 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 2 + 3 + 4 +\n",
      "                                            2 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 2 + 3 + 4 +\n",
      "    2 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 2 + 3 + 4 +\n",
      "2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [2] [0 <=] . infra first choice i 2 + 3 + 4 +\n",
      "                                                                             2 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] swaack first choice i 2 + 3 + 4 +\n",
      "                                                                           2 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] swaack first choice i 2 + 3 + 4 +\n",
      "                                                                         False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] swaack first choice i 2 + 3 + 4 +\n",
      "   False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] . swaack first choice i 2 + 3 + 4 +\n",
      "   2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 2 + 3 + 4 +\n",
      "     2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 2 + 3 + 4 +\n",
      "                   2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 2 + 3 + 4 +\n",
      "                                                                             2 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 +\n",
      "                                                                           2 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 +\n",
      "                                                                             1 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 +\n",
      "                                                                           1 1 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 +\n",
      "                                 1 1 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 2 + 3 + 4 +\n",
      "                                                                             1 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 1 + 2 + 3 + 4 +\n",
      "                                                                      1 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 1 + 2 + 3 + 4 +\n",
      "                                                              1 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 1 + 2 + 3 + 4 +\n",
      "                                                    1 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 1 + 2 + 3 + 4 +\n",
      "                                            1 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 1 + 2 + 3 + 4 +\n",
      "    1 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 1 + 2 + 3 + 4 +\n",
      "1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [1] [0 <=] . infra first choice i 1 + 2 + 3 + 4 +\n",
      "                                                                             1 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] swaack first choice i 1 + 2 + 3 + 4 +\n",
      "                                                                           1 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] swaack first choice i 1 + 2 + 3 + 4 +\n",
      "                                                                         False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] swaack first choice i 1 + 2 + 3 + 4 +\n",
      "   False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] . swaack first choice i 1 + 2 + 3 + 4 +\n",
      "   1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 1 + 2 + 3 + 4 +\n",
      "     1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 1 + 2 + 3 + 4 +\n",
      "                   1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 1 + 2 + 3 + 4 +\n",
      "                                                                             1 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 +\n",
      "                                                                           1 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 +\n",
      "                                                                             0 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 +\n",
      "                                                                           0 0 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 +\n",
      "                                 0 0 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 1 + 2 + 3 + 4 +\n",
      "                                                                             0 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                      0 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 0 + 1 + 2 + 3 + 4 +\n",
      "                                                              0 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 0 + 1 + 2 + 3 + 4 +\n",
      "                                                    0 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 0 + 1 + 2 + 3 + 4 +\n",
      "                                            0 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 0 + 1 + 2 + 3 + 4 +\n",
      "    0 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 0 + 1 + 2 + 3 + 4 +\n",
      "0 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [0] [0 <=] . infra first choice i 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                             0 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] swaack first choice i 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                           0 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] swaack first choice i 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                          True . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] swaack first choice i 0 + 1 + 2 + 3 + 4 +\n",
      "    True [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] . swaack first choice i 0 + 1 + 2 + 3 + 4 +\n",
      "    0 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [True] . first choice i 0 + 1 + 2 + 3 + 4 +\n",
      "      0 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] True . choice i 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                     0 [pop 0] . i 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                             0 . pop 0 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                               . 0 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                             0 . 0 + 1 + 2 + 3 + 4 +\n",
      "                                                                           0 0 . + 1 + 2 + 3 + 4 +\n",
      "                                                                             0 . 1 + 2 + 3 + 4 +\n",
      "                                                                           0 1 . + 2 + 3 + 4 +\n",
      "                                                                             1 . 2 + 3 + 4 +\n",
      "                                                                           1 2 . + 3 + 4 +\n",
      "                                                                             3 . 3 + 4 +\n",
      "                                                                           3 3 . + 4 +\n",
      "                                                                             6 . 4 +\n",
      "                                                                           6 4 . +\n",
      "                                                                            10 . \n"
     ]
    }
   ],
   "source": [
    "V('5 [0 <=] 0 [1 - dup] [+] hylomorphism')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Anamorphism\n",
    "An anamorphism can be defined as a hylomorphism that uses `[]` for `c` and\n",
    "`swons` for `F`.\n",
    "\n",
    "    [P] [G] anamorphism == [P] [] [G] [swons] hylomorphism == A\n",
    "\n",
    "This allows us to define an anamorphism combinator in terms of\n",
    "the hylomorphism combinator.\n",
    "\n",
    "    [] swap [swons] hylomorphism == anamorphism\n",
    "\n",
    "Partial evaluation gives us a \"pre-cooked\" form.\n",
    "\n",
    "    [P] [G] . anamorphism\n",
    "    [P] [G] . [] swap [swons] hylomorphism\n",
    "    [P] [G] [] . swap [swons] hylomorphism\n",
    "    [P] [] [G] . [swons] hylomorphism\n",
    "    [P] [] [G] [swons] . hylomorphism\n",
    "    [P] [] [G] [swons] . [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
    "    [P] [] [G] [swons] [unit [pop] swoncat] . dipd [dip] swoncat genrec\n",
    "    [P] [] . unit [pop] swoncat [G] [swons] [dip] swoncat genrec\n",
    "    [P] [[]] [pop] . swoncat [G] [swons] [dip] swoncat genrec\n",
    "    [P] [pop []] [G] [swons] [dip] . swoncat genrec\n",
    "\n",
    "    [P] [pop []] [G] [dip swons] genrec\n",
    "\n",
    "(We could also have just substituted for `c` and `F` in the definition of `H`.)\n",
    "\n",
    "    H == [P] [pop c ] [G] [dip F    ] genrec\n",
    "    A == [P] [pop []] [G] [dip swons] genrec\n",
    "\n",
    "The partial evaluation is overkill in this case but it serves as a\n",
    "reminder that this sort of program specialization can, in many cases, be\n",
    "carried out automatically.)\n",
    "\n",
    "Untangle `[G]` from `[pop []]` using `swap`.\n",
    "\n",
    "    [P] [G] [pop []] swap [dip swons] genrec\n",
    "\n",
    "All of the arguments to `anamorphism` are to the left, so we have a definition for it.\n",
    "\n",
    "    anamorphism == [pop []] swap [dip swons] genrec\n",
    "\n",
    "An example of an anamorphism is the range function.\n",
    "\n",
    "    range == [0 <=] [1 - dup] anamorphism\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Catamorphism\n",
    "A catamorphism can be defined as a hylomorphism that uses `[uncons swap]` for `[G]`\n",
    "and `[[] =]` for the predicate `[P]`.\n",
    "\n",
    "    c [F] catamorphism == [[] =] c [uncons swap] [F] hylomorphism == C\n",
    "\n",
    "This allows us to define a `catamorphism` combinator in terms of\n",
    "the `hylomorphism` combinator.\n",
    "\n",
    "    [[] =] roll> [uncons swap] swap hylomorphism == catamorphism\n",
    " \n",
    "Partial evaluation doesn't help much.\n",
    "\n",
    "    c [F] . catamorphism\n",
    "    c [F] . [[] =] roll> [uncons swap] swap hylomorphism\n",
    "    c [F] [[] =] . roll> [uncons swap] swap hylomorphism\n",
    "    [[] =] c [F] [uncons swap] . swap hylomorphism\n",
    "    [[] =] c [uncons swap] [F] . hylomorphism\n",
    "    [[] =] c [uncons swap] [F] [unit [pop] swoncat] . dipd [dip] swoncat genrec\n",
    "    [[] =] c . unit [pop] swoncat [uncons swap] [F] [dip] swoncat genrec\n",
    "    [[] =] [c] [pop] . swoncat [uncons swap] [F] [dip] swoncat genrec\n",
    "    [[] =] [pop c] [uncons swap] [F] [dip] . swoncat genrec\n",
    "    [[] =] [pop c] [uncons swap] [dip F] genrec\n",
    "\n",
    "Because the arguments to catamorphism have to be prepared (unlike the arguments\n",
    "to anamorphism, which only need to be rearranged slightly) there isn't much point\n",
    "to \"pre-cooking\" the definition.\n",
    "\n",
    "    catamorphism == [[] =] roll> [uncons swap] swap hylomorphism\n",
    "\n",
    "An example of a catamorphism is the sum function.\n",
    "\n",
    "    sum == 0 [+] catamorphism"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### \"Fusion Law\" for catas (UNFINISHED!!!)\n",
    "\n",
    "I'm not sure exactly how to translate the \"Fusion Law\" for catamorphisms into Joy.\n",
    "\n",
    "I know that a `map` composed with a cata can be expressed as a new cata:\n",
    "\n",
    "    [F] map b [B] cata == b [F B] cata\n",
    "\n",
    "But this isn't the one described in \"Bananas...\".  That's more like:\n",
    "\n",
    "A cata composed with some function can be expressed as some other cata:\n",
    "\n",
    "    b [B] catamorphism F == c [C] catamorphism\n",
    "\n",
    "Given:\n",
    "\n",
    "    b F == c\n",
    "\n",
    "    ...\n",
    "\n",
    "    B F == [F] dip C\n",
    "\n",
    "    ...\n",
    "\n",
    "    b[B]cata F == c[C]cata\n",
    "\n",
    "    F(B(head, tail)) == C(head, F(tail))\n",
    "\n",
    "    1 [2 3] B F         1 [2 3] F C\n",
    "\n",
    "\n",
    "    b F == c\n",
    "    B F == F C\n",
    "\n",
    "    b [B] catamorphism F == c [C] catamorphism\n",
    "    b [B] catamorphism F == b F [C] catamorphism\n",
    "\n",
    "    ...\n",
    "\n",
    "Or maybe,\n",
    "\n",
    "    [F] map b [B] cata == c [C] cata     ???\n",
    "\n",
    "    [F] map b [B] cata == b [F B] cata    I think this is generally true, unless F consumes stack items\n",
    "                                            instead of just transforming TOS.  Of course, there's always [F] unary.\n",
    "    b [F] unary [[F] unary B] cata\n",
    "\n",
    "    [10 *] map 0 swap [+] step == 0 swap [10 * +] step\n",
    "\n",
    "\n",
    "For example:\n",
    "\n",
    "    F == 10 *\n",
    "    b == 0\n",
    "    B == +\n",
    "    c == 0\n",
    "    C == F +\n",
    "    \n",
    "    b F    == c\n",
    "    0 10 * == 0\n",
    "\n",
    "    B F    == [F]    dip C\n",
    "    + 10 * == [10 *] dip F +\n",
    "    + 10 * == [10 *] dip 10 * +\n",
    "\n",
    "    n m + 10 * == 10(n+m)\n",
    "\n",
    "    n m [10 *] dip 10 * +\n",
    "    n 10 * m 10 * +\n",
    "    10n m 10 * +\n",
    "    10n 10m +\n",
    "    10n+10m\n",
    "\n",
    "    10n+10m = 10(n+m)\n",
    "\n",
    "Ergo:\n",
    "\n",
    "    0 [+] catamorphism 10 * == 0 [10 * +] catamorphism"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The `step` combinator will usually be better to use than `catamorphism`.\n",
    "\n",
    "    sum == 0 swap [+] step\n",
    "    sum == 0 [+] catamorphism"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# anamorphism catamorphism == hylomorphism\n",
    "Here is (part of) the payoff.\n",
    "\n",
    "An anamorphism followed by (composed with) a\n",
    "catamorphism is a hylomorphism, with the advantage that the hylomorphism \n",
    "does not create the intermediate list structure.  The values are stored in\n",
    "either the call stack, for those implementations that use one, or in the pending\n",
    "expression (\"continuation\") for the Joypy interpreter.  They still have to \n",
    "be somewhere, converting from an anamorphism and catamorphism to a hylomorphism\n",
    "just prevents using additional storage and doing additional processing.\n",
    "\n",
    "        range == [0 <=] [1 - dup] anamorphism\n",
    "          sum == 0 [+] catamorphism\n",
    "\n",
    "    range sum == [0 <=] [1 - dup] anamorphism 0 [+] catamorphism\n",
    "              == [0 <=] 0 [1 - dup] [+] hylomorphism\n",
    "\n",
    "We can let the `hylomorphism` combinator build `range_sum` for us or just\n",
    "substitute ourselves.\n",
    "\n",
    "            H == [P]    [pop c] [G]       [dip F] genrec\n",
    "    range_sum == [0 <=] [pop 0] [1 - dup] [dip +] genrec\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "defs = '''\n",
    "anamorphism == [pop []] swap [dip swons] genrec\n",
    "hylomorphism == [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
    "catamorphism == [[] =] roll> [uncons swap] swap hylomorphism\n",
    "range == [0 <=] [1 - dup] anamorphism\n",
    "sum == 0 [+] catamorphism\n",
    "range_sum == [0 <=] 0 [1 - dup] [+] hylomorphism\n",
    "'''\n",
    "\n",
    "DefinitionWrapper.add_definitions(defs, D)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9 8 7 6 5 4 3 2 1 0]\n"
     ]
    }
   ],
   "source": [
    "J('10 range')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45\n"
     ]
    }
   ],
   "source": [
    "J('[9 8 7 6 5 4 3 2 1 0] sum')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                                                                                               . 10 range sum\n",
      "                                                                                                                            10 . range sum\n",
      "                                                                                                                            10 . [0 <=] [1 - dup] anamorphism sum\n",
      "                                                                                                                     10 [0 <=] . [1 - dup] anamorphism sum\n",
      "                                                                                                           10 [0 <=] [1 - dup] . anamorphism sum\n",
      "                                                                                                           10 [0 <=] [1 - dup] . [pop []] swap [dip swons] genrec sum\n",
      "                                                                                                  10 [0 <=] [1 - dup] [pop []] . swap [dip swons] genrec sum\n",
      "                                                                                                  10 [0 <=] [pop []] [1 - dup] . [dip swons] genrec sum\n",
      "                                                                                      10 [0 <=] [pop []] [1 - dup] [dip swons] . genrec sum\n",
      "                                         10 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte sum\n",
      "                                    10 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [10] [0 <=] . infra first choice i sum\n",
      "                                                                                                                            10 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 10] swaack first choice i sum\n",
      "                                                                                                                          10 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 10] swaack first choice i sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 10] swaack first choice i sum\n",
      "                                        False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 10] . swaack first choice i sum\n",
      "                                        10 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i sum\n",
      "                                          10 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i sum\n",
      "                                                         10 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i sum\n",
      "                                                                                                                            10 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons sum\n",
      "                                                                                                                          10 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons sum\n",
      "                                                                                                                             9 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons sum\n",
      "                                                                                                                           9 9 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons sum\n",
      "                                                                            9 9 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons sum\n",
      "                                                                                                                             9 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 9 swons sum\n",
      "                                                                                                                      9 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 9 swons sum\n",
      "                                                                                                             9 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 9 swons sum\n",
      "                                                                                                   9 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 9 swons sum\n",
      "                                                                                       9 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 9 swons sum\n",
      "                                          9 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 9 swons sum\n",
      "                                      9 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [9] [0 <=] . infra first choice i 9 swons sum\n",
      "                                                                                                                             9 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 9] swaack first choice i 9 swons sum\n",
      "                                                                                                                           9 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 9] swaack first choice i 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 9] swaack first choice i 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 9] . swaack first choice i 9 swons sum\n",
      "                                         9 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 9 swons sum\n",
      "                                           9 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 9 swons sum\n",
      "                                                          9 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 9 swons sum\n",
      "                                                                                                                             9 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 9 swons sum\n",
      "                                                                                                                           9 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 9 swons sum\n",
      "                                                                                                                             8 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 9 swons sum\n",
      "                                                                                                                           8 8 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 9 swons sum\n",
      "                                                                            8 8 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 9 swons sum\n",
      "                                                                                                                             8 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 8 swons 9 swons sum\n",
      "                                                                                                                      8 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 8 swons 9 swons sum\n",
      "                                                                                                             8 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 8 swons 9 swons sum\n",
      "                                                                                                   8 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 8 swons 9 swons sum\n",
      "                                                                                       8 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 8 swons 9 swons sum\n",
      "                                          8 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 8 swons 9 swons sum\n",
      "                                      8 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [8] [0 <=] . infra first choice i 8 swons 9 swons sum\n",
      "                                                                                                                             8 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 8] swaack first choice i 8 swons 9 swons sum\n",
      "                                                                                                                           8 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 8] swaack first choice i 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 8] swaack first choice i 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 8] . swaack first choice i 8 swons 9 swons sum\n",
      "                                         8 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 8 swons 9 swons sum\n",
      "                                           8 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 8 swons 9 swons sum\n",
      "                                                          8 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 8 swons 9 swons sum\n",
      "                                                                                                                             8 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 8 swons 9 swons sum\n",
      "                                                                                                                           8 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 8 swons 9 swons sum\n",
      "                                                                                                                             7 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 8 swons 9 swons sum\n",
      "                                                                                                                           7 7 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 8 swons 9 swons sum\n",
      "                                                                            7 7 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 8 swons 9 swons sum\n",
      "                                                                                                                             7 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      7 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             7 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   7 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 7 swons 8 swons 9 swons sum\n",
      "                                                                                       7 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 7 swons 8 swons 9 swons sum\n",
      "                                          7 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 7 swons 8 swons 9 swons sum\n",
      "                                      7 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [7] [0 <=] . infra first choice i 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             7 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 7] swaack first choice i 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           7 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 7] swaack first choice i 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 7] swaack first choice i 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 7] . swaack first choice i 7 swons 8 swons 9 swons sum\n",
      "                                         7 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 7 swons 8 swons 9 swons sum\n",
      "                                           7 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 7 swons 8 swons 9 swons sum\n",
      "                                                          7 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             7 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           7 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             6 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           6 6 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            6 6 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             6 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      6 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             6 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   6 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       6 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          6 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      6 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [6] [0 <=] . infra first choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             6 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 6] swaack first choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           6 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 6] swaack first choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 6] swaack first choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 6] . swaack first choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         6 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                           6 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                          6 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             6 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           6 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             5 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           5 5 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            5 5 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             5 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      5 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             5 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   5 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       5 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          5 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      5 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [5] [0 <=] . infra first choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             5 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 5] swaack first choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           5 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 5] swaack first choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 5] swaack first choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 5] . swaack first choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         5 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                           5 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                          5 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             5 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           5 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             4 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           4 4 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            4 4 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             4 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      4 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             4 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   4 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       4 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          4 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      4 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [4] [0 <=] . infra first choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             4 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           4 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 4] . swaack first choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         4 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                           4 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                          4 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             4 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           4 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             3 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           3 3 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            3 3 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             3 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      3 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             3 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   3 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       3 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          3 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      3 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [3] [0 <=] . infra first choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             3 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           3 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 3] . swaack first choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         3 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                           3 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                          3 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             3 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           3 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             2 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           2 2 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            2 2 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             2 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      2 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             2 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   2 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       2 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          2 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      2 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [2] [0 <=] . infra first choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             2 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           2 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 2] . swaack first choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         2 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                           2 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                          2 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             2 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           2 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             1 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           1 1 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            1 1 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             1 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      1 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             1 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   1 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       1 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          1 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      1 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [1] [0 <=] . infra first choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             1 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           1 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         False . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         False [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 1] . swaack first choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                         1 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                           1 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] False . choice i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                          1 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . i 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             1 . 1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           1 1 . - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             0 . dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           0 0 . [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                            0 0 [[0 <=] [pop []] [1 - dup] [dip swons] genrec] . dip swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             0 . [0 <=] [pop []] [1 - dup] [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                      0 [0 <=] . [pop []] [1 - dup] [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             0 [0 <=] [pop []] . [1 - dup] [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                   0 [0 <=] [pop []] [1 - dup] . [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                       0 [0 <=] [pop []] [1 - dup] [dip swons] . genrec 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          0 [0 <=] [pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] . ifte 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                      0 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [0] [0 <=] . infra first choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             0 . 0 <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           0 0 . <= [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                          True . [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          True [[pop []] [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] 0] . swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                          0 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] [True] . first choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                            0 [1 - dup [[0 <=] [pop []] [1 - dup] [dip swons] genrec] dip swons] [pop []] True . choice i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                    0 [pop []] . i 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                             0 . pop [] 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                               . [] 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                            [] . 0 swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                          [] 0 . swons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                          [] 0 . swap cons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                          0 [] . cons 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                           [0] . 1 swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         [0] 1 . swons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         [0] 1 . swap cons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         1 [0] . cons 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                         [1 0] . 2 swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                       [1 0] 2 . swons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                       [1 0] 2 . swap cons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                       2 [1 0] . cons 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                       [2 1 0] . 3 swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                     [2 1 0] 3 . swons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                     [2 1 0] 3 . swap cons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                     3 [2 1 0] . cons 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                     [3 2 1 0] . 4 swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                   [3 2 1 0] 4 . swons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                   [3 2 1 0] 4 . swap cons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                   4 [3 2 1 0] . cons 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                   [4 3 2 1 0] . 5 swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                 [4 3 2 1 0] 5 . swons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                 [4 3 2 1 0] 5 . swap cons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                 5 [4 3 2 1 0] . cons 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                                 [5 4 3 2 1 0] . 6 swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                               [5 4 3 2 1 0] 6 . swons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                               [5 4 3 2 1 0] 6 . swap cons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                               6 [5 4 3 2 1 0] . cons 7 swons 8 swons 9 swons sum\n",
      "                                                                                                               [6 5 4 3 2 1 0] . 7 swons 8 swons 9 swons sum\n",
      "                                                                                                             [6 5 4 3 2 1 0] 7 . swons 8 swons 9 swons sum\n",
      "                                                                                                             [6 5 4 3 2 1 0] 7 . swap cons 8 swons 9 swons sum\n",
      "                                                                                                             7 [6 5 4 3 2 1 0] . cons 8 swons 9 swons sum\n",
      "                                                                                                             [7 6 5 4 3 2 1 0] . 8 swons 9 swons sum\n",
      "                                                                                                           [7 6 5 4 3 2 1 0] 8 . swons 9 swons sum\n",
      "                                                                                                           [7 6 5 4 3 2 1 0] 8 . swap cons 9 swons sum\n",
      "                                                                                                           8 [7 6 5 4 3 2 1 0] . cons 9 swons sum\n",
      "                                                                                                           [8 7 6 5 4 3 2 1 0] . 9 swons sum\n",
      "                                                                                                         [8 7 6 5 4 3 2 1 0] 9 . swons sum\n",
      "                                                                                                         [8 7 6 5 4 3 2 1 0] 9 . swap cons sum\n",
      "                                                                                                         9 [8 7 6 5 4 3 2 1 0] . cons sum\n",
      "                                                                                                         [9 8 7 6 5 4 3 2 1 0] . sum\n",
      "                                                                                                         [9 8 7 6 5 4 3 2 1 0] . 0 [+] catamorphism\n",
      "                                                                                                       [9 8 7 6 5 4 3 2 1 0] 0 . [+] catamorphism\n",
      "                                                                                                   [9 8 7 6 5 4 3 2 1 0] 0 [+] . catamorphism\n",
      "                                                                                                   [9 8 7 6 5 4 3 2 1 0] 0 [+] . [[] =] roll> [uncons swap] swap hylomorphism\n",
      "                                                                                            [9 8 7 6 5 4 3 2 1 0] 0 [+] [[] =] . roll> [uncons swap] swap hylomorphism\n",
      "                                                                                            [9 8 7 6 5 4 3 2 1 0] [[] =] 0 [+] . [uncons swap] swap hylomorphism\n",
      "                                                                              [9 8 7 6 5 4 3 2 1 0] [[] =] 0 [+] [uncons swap] . swap hylomorphism\n",
      "                                                                              [9 8 7 6 5 4 3 2 1 0] [[] =] 0 [uncons swap] [+] . hylomorphism\n",
      "                                                                              [9 8 7 6 5 4 3 2 1 0] [[] =] 0 [uncons swap] [+] . [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
      "                                                         [9 8 7 6 5 4 3 2 1 0] [[] =] 0 [uncons swap] [+] [unit [pop] swoncat] . dipd [dip] swoncat genrec\n",
      "                                                                                                [9 8 7 6 5 4 3 2 1 0] [[] =] 0 . unit [pop] swoncat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                                [9 8 7 6 5 4 3 2 1 0] [[] =] 0 . [] cons [pop] swoncat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                             [9 8 7 6 5 4 3 2 1 0] [[] =] 0 [] . cons [pop] swoncat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                              [9 8 7 6 5 4 3 2 1 0] [[] =] [0] . [pop] swoncat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                        [9 8 7 6 5 4 3 2 1 0] [[] =] [0] [pop] . swoncat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                        [9 8 7 6 5 4 3 2 1 0] [[] =] [0] [pop] . swap concat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                        [9 8 7 6 5 4 3 2 1 0] [[] =] [pop] [0] . concat [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                                          [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] . [uncons swap] [+] [dip] swoncat genrec\n",
      "                                                                            [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] . [+] [dip] swoncat genrec\n",
      "                                                                        [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [+] . [dip] swoncat genrec\n",
      "                                                                  [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [+] [dip] . swoncat genrec\n",
      "                                                                  [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [+] [dip] . swap concat genrec\n",
      "                                                                  [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip] [+] . concat genrec\n",
      "                                                                    [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec\n",
      "                        [9 8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte\n",
      "[9 8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[9 8 7 6 5 4 3 2 1 0]] [[] =] . infra first choice i\n",
      "                                                                                                         [9 8 7 6 5 4 3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [9 8 7 6 5 4 3 2 1 0]] swaack first choice i\n",
      "                                                                                                      [9 8 7 6 5 4 3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [9 8 7 6 5 4 3 2 1 0]] swaack first choice i\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [9 8 7 6 5 4 3 2 1 0]] swaack first choice i\n",
      "                       False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [9 8 7 6 5 4 3 2 1 0]] . swaack first choice i\n",
      "                       [9 8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i\n",
      "                         [9 8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i\n",
      "                                       [9 8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i\n",
      "                                                                                                         [9 8 7 6 5 4 3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +\n",
      "                                                                                                         9 [8 7 6 5 4 3 2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +\n",
      "                                                                                                         [8 7 6 5 4 3 2 1 0] 9 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +\n",
      "                                                           [8 7 6 5 4 3 2 1 0] 9 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip +\n",
      "                                                                                                           [8 7 6 5 4 3 2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 9 +\n",
      "                                                                                                    [8 7 6 5 4 3 2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 9 +\n",
      "                                                                                            [8 7 6 5 4 3 2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 9 +\n",
      "                                                                              [8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 9 +\n",
      "                                                                      [8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 9 +\n",
      "                          [8 7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 9 +\n",
      "    [8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[8 7 6 5 4 3 2 1 0]] [[] =] . infra first choice i 9 +\n",
      "                                                                                                           [8 7 6 5 4 3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [8 7 6 5 4 3 2 1 0]] swaack first choice i 9 +\n",
      "                                                                                                        [8 7 6 5 4 3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [8 7 6 5 4 3 2 1 0]] swaack first choice i 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [8 7 6 5 4 3 2 1 0]] swaack first choice i 9 +\n",
      "                         False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [8 7 6 5 4 3 2 1 0]] . swaack first choice i 9 +\n",
      "                         [8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 9 +\n",
      "                           [8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 9 +\n",
      "                                         [8 7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 9 +\n",
      "                                                                                                           [8 7 6 5 4 3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 9 +\n",
      "                                                                                                           8 [7 6 5 4 3 2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 9 +\n",
      "                                                                                                           [7 6 5 4 3 2 1 0] 8 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 9 +\n",
      "                                                             [7 6 5 4 3 2 1 0] 8 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 9 +\n",
      "                                                                                                             [7 6 5 4 3 2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 8 + 9 +\n",
      "                                                                                                      [7 6 5 4 3 2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 8 + 9 +\n",
      "                                                                                              [7 6 5 4 3 2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 8 + 9 +\n",
      "                                                                                [7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 8 + 9 +\n",
      "                                                                        [7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 8 + 9 +\n",
      "                            [7 6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 8 + 9 +\n",
      "        [7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[7 6 5 4 3 2 1 0]] [[] =] . infra first choice i 8 + 9 +\n",
      "                                                                                                             [7 6 5 4 3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [7 6 5 4 3 2 1 0]] swaack first choice i 8 + 9 +\n",
      "                                                                                                          [7 6 5 4 3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [7 6 5 4 3 2 1 0]] swaack first choice i 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [7 6 5 4 3 2 1 0]] swaack first choice i 8 + 9 +\n",
      "                           False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [7 6 5 4 3 2 1 0]] . swaack first choice i 8 + 9 +\n",
      "                           [7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 8 + 9 +\n",
      "                             [7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 8 + 9 +\n",
      "                                           [7 6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 8 + 9 +\n",
      "                                                                                                             [7 6 5 4 3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 8 + 9 +\n",
      "                                                                                                             7 [6 5 4 3 2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 8 + 9 +\n",
      "                                                                                                             [6 5 4 3 2 1 0] 7 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 8 + 9 +\n",
      "                                                               [6 5 4 3 2 1 0] 7 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 8 + 9 +\n",
      "                                                                                                               [6 5 4 3 2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 7 + 8 + 9 +\n",
      "                                                                                                        [6 5 4 3 2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 7 + 8 + 9 +\n",
      "                                                                                                [6 5 4 3 2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 7 + 8 + 9 +\n",
      "                                                                                  [6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 7 + 8 + 9 +\n",
      "                                                                          [6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 7 + 8 + 9 +\n",
      "                              [6 5 4 3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 7 + 8 + 9 +\n",
      "            [6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[6 5 4 3 2 1 0]] [[] =] . infra first choice i 7 + 8 + 9 +\n",
      "                                                                                                               [6 5 4 3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [6 5 4 3 2 1 0]] swaack first choice i 7 + 8 + 9 +\n",
      "                                                                                                            [6 5 4 3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [6 5 4 3 2 1 0]] swaack first choice i 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [6 5 4 3 2 1 0]] swaack first choice i 7 + 8 + 9 +\n",
      "                             False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [6 5 4 3 2 1 0]] . swaack first choice i 7 + 8 + 9 +\n",
      "                             [6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 7 + 8 + 9 +\n",
      "                               [6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 7 + 8 + 9 +\n",
      "                                             [6 5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 7 + 8 + 9 +\n",
      "                                                                                                               [6 5 4 3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                                                                                               6 [5 4 3 2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                                                                                               [5 4 3 2 1 0] 6 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                                                 [5 4 3 2 1 0] 6 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 7 + 8 + 9 +\n",
      "                                                                                                                 [5 4 3 2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                                                                          [5 4 3 2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                                                                  [5 4 3 2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                                                    [5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                                            [5 4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 6 + 7 + 8 + 9 +\n",
      "                                [5 4 3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 6 + 7 + 8 + 9 +\n",
      "                [5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[5 4 3 2 1 0]] [[] =] . infra first choice i 6 + 7 + 8 + 9 +\n",
      "                                                                                                                 [5 4 3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [5 4 3 2 1 0]] swaack first choice i 6 + 7 + 8 + 9 +\n",
      "                                                                                                              [5 4 3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [5 4 3 2 1 0]] swaack first choice i 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [5 4 3 2 1 0]] swaack first choice i 6 + 7 + 8 + 9 +\n",
      "                               False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [5 4 3 2 1 0]] . swaack first choice i 6 + 7 + 8 + 9 +\n",
      "                               [5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 6 + 7 + 8 + 9 +\n",
      "                                 [5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 6 + 7 + 8 + 9 +\n",
      "                                               [5 4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 6 + 7 + 8 + 9 +\n",
      "                                                                                                                 [5 4 3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                 5 [4 3 2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                 [4 3 2 1 0] 5 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                                                   [4 3 2 1 0] 5 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                   [4 3 2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                            [4 3 2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                    [4 3 2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                      [4 3 2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                              [4 3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                  [4 3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 5 + 6 + 7 + 8 + 9 +\n",
      "                    [4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[4 3 2 1 0]] [[] =] . infra first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                   [4 3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [4 3 2 1 0]] swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                [4 3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [4 3 2 1 0]] swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [4 3 2 1 0]] swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                 False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [4 3 2 1 0]] . swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                 [4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                   [4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                 [4 3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                   [4 3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                   4 [3 2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                   [3 2 1 0] 4 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                     [3 2 1 0] 4 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                     [3 2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                              [3 2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                      [3 2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                        [3 2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                [3 2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                    [3 2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                        [3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[3 2 1 0]] [[] =] . infra first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                     [3 2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [3 2 1 0]] swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                  [3 2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [3 2 1 0]] swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [3 2 1 0]] swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [3 2 1 0]] . swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   [3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                     [3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                   [3 2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                     [3 2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                     3 [2 1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                     [2 1 0] 3 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                       [2 1 0] 3 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                       [2 1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                [2 1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                        [2 1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                          [2 1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                  [2 1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                      [2 1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                            [2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[2 1 0]] [[] =] . infra first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                       [2 1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [2 1 0]] swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                    [2 1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [2 1 0]] swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [2 1 0]] swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                     False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [2 1 0]] . swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                     [2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                       [2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                     [2 1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                       [2 1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                       2 [1 0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                       [1 0] 2 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                         [1 0] 2 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         [1 0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                  [1 0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                          [1 0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                            [1 0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                    [1 0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                        [1 0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                [1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[1 0]] [[] =] . infra first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         [1 0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [1 0]] swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                      [1 0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [1 0]] swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [1 0]] swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                       False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [1 0]] . swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                       [1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                         [1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                       [1 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         [1 0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         1 [0] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         [0] 1 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                           [0] 1 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           [0] . [[] =] [pop 0] [uncons swap] [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                    [0] [[] =] . [pop 0] [uncons swap] [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                            [0] [[] =] [pop 0] . [uncons swap] [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                              [0] [[] =] [pop 0] [uncons swap] . [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                      [0] [[] =] [pop 0] [uncons swap] [dip +] . genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                          [0] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                    [0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[0]] [[] =] . infra first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           [0] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [0]] swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                        [0] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [0]] swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         False . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [0]] swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                         False [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [0]] . swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                         [0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [False] . first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                           [0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] False . choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                         [0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           [0] . uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                          0 [] . swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                          [] 0 . [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                            [] 0 [[[] =] [pop 0] [uncons swap] [dip +] genrec] . dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                            [] . [[] =] [pop 0] [uncons swap] [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                     [] [[] =] . [pop 0] [uncons swap] [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                             [] [[] =] [pop 0] . [uncons swap] [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                               [] [[] =] [pop 0] [uncons swap] . [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                       [] [[] =] [pop 0] [uncons swap] [dip +] . genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                           [] [[] =] [pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] . ifte 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                      [] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [[]] [[] =] . infra first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                            [] . [] = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] []] swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                         [] [] . = [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] []] swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                          True . [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] []] swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                           True [[pop 0] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] []] . swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                           [] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] [True] . first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                             [] [uncons swap [[[] =] [pop 0] [uncons swap] [dip +] genrec] dip +] [pop 0] True . choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                    [] [pop 0] . i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                            [] . pop 0 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                               . 0 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                             0 . 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           0 0 . + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                             0 . 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           0 1 . + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                             1 . 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           1 2 . + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                             3 . 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           3 3 . + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                             6 . 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                           6 4 . + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                            10 . 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                          10 5 . + 6 + 7 + 8 + 9 +\n",
      "                                                                                                                            15 . 6 + 7 + 8 + 9 +\n",
      "                                                                                                                          15 6 . + 7 + 8 + 9 +\n",
      "                                                                                                                            21 . 7 + 8 + 9 +\n",
      "                                                                                                                          21 7 . + 8 + 9 +\n",
      "                                                                                                                            28 . 8 + 9 +\n",
      "                                                                                                                          28 8 . + 9 +\n",
      "                                                                                                                            36 . 9 +\n",
      "                                                                                                                          36 9 . +\n",
      "                                                                                                                            45 . \n"
     ]
    }
   ],
   "source": [
    "V('10 range sum')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                                                 . 10 range_sum\n",
      "                                                                              10 . range_sum\n",
      "                                                                              10 . [0 <=] 0 [1 - dup] [+] hylomorphism\n",
      "                                                                       10 [0 <=] . 0 [1 - dup] [+] hylomorphism\n",
      "                                                                     10 [0 <=] 0 . [1 - dup] [+] hylomorphism\n",
      "                                                           10 [0 <=] 0 [1 - dup] . [+] hylomorphism\n",
      "                                                       10 [0 <=] 0 [1 - dup] [+] . hylomorphism\n",
      "                                                       10 [0 <=] 0 [1 - dup] [+] . [unit [pop] swoncat] dipd [dip] swoncat genrec\n",
      "                                  10 [0 <=] 0 [1 - dup] [+] [unit [pop] swoncat] . dipd [dip] swoncat genrec\n",
      "                                                                     10 [0 <=] 0 . unit [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                                     10 [0 <=] 0 . [] cons [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                                  10 [0 <=] 0 [] . cons [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                                   10 [0 <=] [0] . [pop] swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                             10 [0 <=] [0] [pop] . swoncat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                             10 [0 <=] [0] [pop] . swap concat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                             10 [0 <=] [pop] [0] . concat [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                               10 [0 <=] [pop 0] . [1 - dup] [+] [dip] swoncat genrec\n",
      "                                                     10 [0 <=] [pop 0] [1 - dup] . [+] [dip] swoncat genrec\n",
      "                                                 10 [0 <=] [pop 0] [1 - dup] [+] . [dip] swoncat genrec\n",
      "                                           10 [0 <=] [pop 0] [1 - dup] [+] [dip] . swoncat genrec\n",
      "                                           10 [0 <=] [pop 0] [1 - dup] [+] [dip] . swap concat genrec\n",
      "                                           10 [0 <=] [pop 0] [1 - dup] [dip] [+] . concat genrec\n",
      "                                             10 [0 <=] [pop 0] [1 - dup] [dip +] . genrec\n",
      "     10 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte\n",
      "10 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [10] [0 <=] . infra first choice i\n",
      "                                                                              10 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 10] swaack first choice i\n",
      "                                                                            10 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 10] swaack first choice i\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 10] swaack first choice i\n",
      "    False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 10] . swaack first choice i\n",
      "    10 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i\n",
      "      10 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i\n",
      "                    10 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i\n",
      "                                                                              10 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                                                            10 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                                                               9 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                                                             9 9 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +\n",
      "                                   9 9 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip +\n",
      "                                                                               9 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 9 +\n",
      "                                                                        9 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 9 +\n",
      "                                                                9 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 9 +\n",
      "                                                      9 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 9 +\n",
      "                                              9 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 9 +\n",
      "      9 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 9 +\n",
      "  9 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [9] [0 <=] . infra first choice i 9 +\n",
      "                                                                               9 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 9] swaack first choice i 9 +\n",
      "                                                                             9 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 9] swaack first choice i 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 9] swaack first choice i 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 9] . swaack first choice i 9 +\n",
      "     9 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 9 +\n",
      "       9 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 9 +\n",
      "                     9 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 9 +\n",
      "                                                                               9 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 9 +\n",
      "                                                                             9 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 9 +\n",
      "                                                                               8 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 9 +\n",
      "                                                                             8 8 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 9 +\n",
      "                                   8 8 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 9 +\n",
      "                                                                               8 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 8 + 9 +\n",
      "                                                                        8 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 8 + 9 +\n",
      "                                                                8 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 8 + 9 +\n",
      "                                                      8 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 8 + 9 +\n",
      "                                              8 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 8 + 9 +\n",
      "      8 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 8 + 9 +\n",
      "  8 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [8] [0 <=] . infra first choice i 8 + 9 +\n",
      "                                                                               8 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 8] swaack first choice i 8 + 9 +\n",
      "                                                                             8 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 8] swaack first choice i 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 8] swaack first choice i 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 8] . swaack first choice i 8 + 9 +\n",
      "     8 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 8 + 9 +\n",
      "       8 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 8 + 9 +\n",
      "                     8 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 8 + 9 +\n",
      "                                                                               8 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 8 + 9 +\n",
      "                                                                             8 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 8 + 9 +\n",
      "                                                                               7 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 8 + 9 +\n",
      "                                                                             7 7 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 8 + 9 +\n",
      "                                   7 7 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 8 + 9 +\n",
      "                                                                               7 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 7 + 8 + 9 +\n",
      "                                                                        7 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 7 + 8 + 9 +\n",
      "                                                                7 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 7 + 8 + 9 +\n",
      "                                                      7 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 7 + 8 + 9 +\n",
      "                                              7 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 7 + 8 + 9 +\n",
      "      7 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 7 + 8 + 9 +\n",
      "  7 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [7] [0 <=] . infra first choice i 7 + 8 + 9 +\n",
      "                                                                               7 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 7] swaack first choice i 7 + 8 + 9 +\n",
      "                                                                             7 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 7] swaack first choice i 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 7] swaack first choice i 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 7] . swaack first choice i 7 + 8 + 9 +\n",
      "     7 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 7 + 8 + 9 +\n",
      "       7 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 7 + 8 + 9 +\n",
      "                     7 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 7 + 8 + 9 +\n",
      "                                                                               7 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                                                             7 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                                                               6 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                                                             6 6 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 7 + 8 + 9 +\n",
      "                                   6 6 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 7 + 8 + 9 +\n",
      "                                                                               6 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                                        6 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                                6 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                                      6 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 6 + 7 + 8 + 9 +\n",
      "                                              6 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 6 + 7 + 8 + 9 +\n",
      "      6 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 6 + 7 + 8 + 9 +\n",
      "  6 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [6] [0 <=] . infra first choice i 6 + 7 + 8 + 9 +\n",
      "                                                                               6 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 6] swaack first choice i 6 + 7 + 8 + 9 +\n",
      "                                                                             6 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 6] swaack first choice i 6 + 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 6] swaack first choice i 6 + 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 6] . swaack first choice i 6 + 7 + 8 + 9 +\n",
      "     6 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 6 + 7 + 8 + 9 +\n",
      "       6 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 6 + 7 + 8 + 9 +\n",
      "                     6 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 6 + 7 + 8 + 9 +\n",
      "                                                                               6 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                                                             6 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                                                               5 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                                                             5 5 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 6 + 7 + 8 + 9 +\n",
      "                                   5 5 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 6 + 7 + 8 + 9 +\n",
      "                                                                               5 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                        5 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                5 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                                      5 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 5 + 6 + 7 + 8 + 9 +\n",
      "                                              5 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 5 + 6 + 7 + 8 + 9 +\n",
      "      5 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 5 + 6 + 7 + 8 + 9 +\n",
      "  5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [5] [0 <=] . infra first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               5 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             5 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 5] . swaack first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "     5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 5 + 6 + 7 + 8 + 9 +\n",
      "       5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 5 + 6 + 7 + 8 + 9 +\n",
      "                     5 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               5 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             5 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               4 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             4 4 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   4 4 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               4 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                        4 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                4 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                      4 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                              4 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      4 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "  4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [4] [0 <=] . infra first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               4 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             4 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 4] . swaack first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "       4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                     4 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               4 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             4 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               3 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             3 3 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   3 3 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               3 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                        3 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                3 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                      3 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                              3 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      3 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "  3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [3] [0 <=] . infra first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               3 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             3 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 3] . swaack first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "       3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                     3 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               3 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             3 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               2 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             2 2 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   2 2 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               2 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                        2 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                2 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                      2 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                              2 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      2 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "  2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [2] [0 <=] . infra first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               2 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             2 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 2] . swaack first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "       2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                     2 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               2 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             2 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               1 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             1 1 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   1 1 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               1 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                        1 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                1 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                      1 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                              1 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      1 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "  1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [1] [0 <=] . infra first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               1 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             1 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                           False . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     False [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 1] . swaack first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "     1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [False] . first choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "       1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] False . choice i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                     1 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . i 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               1 . 1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             1 1 . - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               0 . dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             0 0 . [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                   0 0 [[0 <=] [pop 0] [1 - dup] [dip +] genrec] . dip + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               0 . [0 <=] [pop 0] [1 - dup] [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                        0 [0 <=] . [pop 0] [1 - dup] [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                0 [0 <=] [pop 0] . [1 - dup] [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                      0 [0 <=] [pop 0] [1 - dup] . [dip +] genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                              0 [0 <=] [pop 0] [1 - dup] [dip +] . genrec 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      0 [0 <=] [pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] . ifte 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "  0 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [0] [0 <=] . infra first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               0 . 0 <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             0 0 . <= [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                            True . [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      True [[pop 0] [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] 0] . swaack first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "      0 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] [True] . first choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "        0 [1 - dup [[0 <=] [pop 0] [1 - dup] [dip +] genrec] dip +] [pop 0] True . choice i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                       0 [pop 0] . i 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               0 . pop 0 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                                 . 0 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               0 . 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             0 0 . + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               0 . 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             0 1 . + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               1 . 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             1 2 . + 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               3 . 3 + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             3 3 . + 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                               6 . 4 + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                             6 4 . + 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                              10 . 5 + 6 + 7 + 8 + 9 +\n",
      "                                                                            10 5 . + 6 + 7 + 8 + 9 +\n",
      "                                                                              15 . 6 + 7 + 8 + 9 +\n",
      "                                                                            15 6 . + 7 + 8 + 9 +\n",
      "                                                                              21 . 7 + 8 + 9 +\n",
      "                                                                            21 7 . + 8 + 9 +\n",
      "                                                                              28 . 8 + 9 +\n",
      "                                                                            28 8 . + 9 +\n",
      "                                                                              36 . 9 +\n",
      "                                                                            36 9 . +\n",
      "                                                                              45 . \n"
     ]
    }
   ],
   "source": [
    "V('10 range_sum')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Factorial Function and Paramorphisms\n",
    "A paramorphism `P :: B -> A` is a recursion combinator that uses `dup` on intermediate values.\n",
    "\n",
    "    n swap [P] [pop] [[F] dupdip G] primrec\n",
    "\n",
    "With\n",
    "- `n :: A` is the \"identity\" for `F` (like 1 for multiplication, 0 for addition)\n",
    "- `F :: (A, B) -> A`\n",
    "- `G :: B -> B` generates the next `B` value.\n",
    "- and lastly `P :: B -> Bool` detects the end of the series."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For Factorial function (types `A` and `B` are both integer):\n",
    "\n",
    "    n == 1\n",
    "    F == *\n",
    "    G == --\n",
    "    P == 1 <="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "define('factorial == 1 swap [1 <=] [pop] [[*] dupdip --] primrec')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Try it with input 3 (omitting evaluation of predicate):\n",
    "\n",
    "    3 1 swap [1 <=] [pop] [[*] dupdip --] primrec\n",
    "    1 3      [1 <=] [pop] [[*] dupdip --] primrec\n",
    "\n",
    "    1 3 [*] dupdip --\n",
    "    1 3  * 3      --\n",
    "    3      3      --\n",
    "    3      2\n",
    "\n",
    "    3 2 [*] dupdip --\n",
    "    3 2  *  2      --\n",
    "    6       2      --\n",
    "    6       1\n",
    "\n",
    "    6 1 [1 <=] [pop] [[*] dupdip --] primrec\n",
    "\n",
    "    6 1 pop\n",
    "    6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "J('3 factorial')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Derive `paramorphism` from the form above.\n",
    "\n",
    "    n swap [P] [pop] [[F] dupdip G] primrec\n",
    "\n",
    "    n swap [P]       [pop]     [[F] dupdip G]                  primrec\n",
    "    n [P] [swap] dip [pop]     [[F] dupdip G]                  primrec\n",
    "    n [P] [[F] dupdip G]                [[swap] dip [pop]] dip primrec\n",
    "    n [P] [F] [dupdip G]           cons [[swap] dip [pop]] dip primrec\n",
    "    n [P] [F] [G] [dupdip] swoncat cons [[swap] dip [pop]] dip primrec\n",
    "\n",
    "    paramorphism == [dupdip] swoncat cons [[swap] dip [pop]] dip primrec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "define('paramorphism == [dupdip] swoncat cons [[swap] dip [pop]] dip primrec')\n",
    "define('factorial == 1 [1 <=] [*] [--] paramorphism')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "J('3 factorial')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# `tails`\n",
    "An example of a paramorphism for lists given in the [\"Bananas...\" paper](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.41.125) is `tails` which returns the list of \"tails\" of a list.\n",
    "\n",
    "    [1 2 3] tails == [[] [3] [2 3]]\n",
    "    \n",
    "Using `paramorphism` we would write:\n",
    "\n",
    "    n == []\n",
    "    F == rest swons\n",
    "    G == rest\n",
    "    P == not\n",
    "\n",
    "    tails == [] [not] [rest swons] [rest] paramorphism"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "define('tails == [] [not] [rest swons] [rest] paramorphism')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[] [3] [2 3]]\n"
     ]
    }
   ],
   "source": [
    "J('[1 2 3] tails')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276]\n"
     ]
    }
   ],
   "source": [
    "J('25 range tails [popop] infra [sum] map')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[276 253 231 210 190 171 153 136 120 105 91 78 66 55 45 36 28 21 15 10 6 3 1 0 0]\n"
     ]
    }
   ],
   "source": [
    "J('25 range [range_sum] map')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Factoring `rest`\n",
    "Right before the recursion begins we have:\n",
    "    \n",
    "    [] [1 2 3] [not] [pop] [[rest swons] dupdip rest] primrec\n",
    "    \n",
    "But we might prefer to factor `rest` in the quote:\n",
    "\n",
    "    [] [1 2 3] [not] [pop] [rest [swons] dupdip] primrec\n",
    "\n",
    "There's no way to do that with the `paramorphism` combinator as defined.  We would have to write and use a slightly different recursion combinator that accepted an additional \"preprocessor\" function `[H]` and built:\n",
    "\n",
    "    n swap [P] [pop] [H [F] dupdip G] primrec\n",
    "\n",
    "Or just write it out manually.  This is yet another place where the *sufficiently smart compiler* will one day automatically refactor the code.  We could write a `paramorphism` combinator that checked `[F]` and `[G]` for common prefix and extracted it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Patterns of Recursion\n",
    "Our story so far...\n",
    "\n",
    "- A combiner `F :: (B, B) -> B`\n",
    "- A predicate `P :: A -> Bool` to detect the base case\n",
    "- A base case value `c :: B`\n",
    "\n",
    "\n",
    "### Hylo-, Ana-, Cata-\n",
    "\n",
    "    w/ G :: A -> (A, B)\n",
    "\n",
    "    H == [P   ] [pop c ] [G          ] [dip F    ] genrec\n",
    "    A == [P   ] [pop []] [G          ] [dip swons] genrec\n",
    "    C == [[] =] [pop c ] [uncons swap] [dip F    ] genrec\n",
    "\n",
    "### Para-, ?-, ?-\n",
    "\n",
    "    w/ G :: B -> B\n",
    "\n",
    "    P == c  swap [P   ] [pop] [[F    ] dupdip G          ] primrec\n",
    "    ? == [] swap [P   ] [pop] [[swons] dupdip G          ] primrec\n",
    "    ? == c  swap [[] =] [pop] [[F    ] dupdip uncons swap] primrec\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Four Generalizations\n",
    "There are at least four kinds of recursive combinator, depending on two choices.  The first choice is whether the combiner function should be evaluated during the recursion or pushed into the pending expression to be \"collapsed\" at the end.  The second choice is whether the combiner needs to operate on the current value of the datastructure or the generator's output.\n",
    "\n",
    "    H ==        [P] [pop c] [G             ] [dip F] genrec\n",
    "    H == c swap [P] [pop]   [G [F]    dip  ] [i]     genrec\n",
    "    H ==        [P] [pop c] [  [G] dupdip  ] [dip F] genrec\n",
    "    H == c swap [P] [pop]   [  [F] dupdip G] [i]     genrec\n",
    "\n",
    "Consider:\n",
    "\n",
    "    ... a G [H] dip F                w/ a G == a' b\n",
    "    ... c a G [F] dip H                 a G == b  a'\n",
    "    ... a [G] dupdip [H] dip F          a G == a'\n",
    "    ... c a [F] dupdip G H              a G == a'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1\n",
    "\n",
    "    H == [P] [pop c] [G] [dip F] genrec\n",
    "\n",
    "Iterate n times.\n",
    "\n",
    "    ... a [P] [pop c] [G] [dip F] genrec\n",
    "    ... a  G [H] dip F\n",
    "    ... a' b [H] dip F\n",
    "    ... a' H b F\n",
    "    ... a'  G [H] dip F b F\n",
    "    ... a'' b [H] dip F b F\n",
    "    ... a'' H b F b F\n",
    "    ... a''  G [H] dip F b F b F\n",
    "    ... a''' b [H] dip F b F b F\n",
    "    ... a''' H b F b F b F\n",
    "    ... a''' pop c b F b F b F\n",
    "    ... c b F b F b F\n",
    "\n",
    "This form builds up a continuation that contains the intermediate results along with the pending combiner functions.  When the base case is reached the last term is replaced by the identity value c and the continuation \"collapses\" into the final result."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2\n",
    "When you can start with the identity value c on the stack and the combiner can operate as you go, using the intermediate results immediately rather than queuing them up, use this form.  An important difference is that the generator function must return its results in the reverse order.\n",
    "\n",
    "    H == c swap [P] [pop] [G [F] dip] primrec\n",
    "\n",
    "    ... c a G [F] dip H\n",
    "    ... c b a' [F] dip H\n",
    "    ... c b F a' H\n",
    "    ... c b F a' G [F] dip H\n",
    "    ... c b F b a'' [F] dip H\n",
    "    ... c b F b F a'' H\n",
    "    ... c b F b F a'' G [F] dip H\n",
    "    ... c b F b F b a''' [F] dip H\n",
    "    ... c b F b F b F a''' H\n",
    "    ... c b F b F b F a''' pop\n",
    "    ... c b F b F b F\n",
    "\n",
    "The end line here is the same as for above, but only because we didn't evaluate `F` when it normally would have been."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3\n",
    "If the combiner and the generator both need to work on the current value then `dup` must be used at some point, and the generator must produce one item instead of two (the b is instead the duplicate of a.)\n",
    "\n",
    "\n",
    "    H == [P] [pop c] [[G] dupdip] [dip F] genrec\n",
    "\n",
    "    ... a [G] dupdip [H] dip F\n",
    "    ... a  G a       [H] dip F\n",
    "    ... a'   a       [H] dip F\n",
    "    ... a' H a F\n",
    "    ... a' [G] dupdip [H] dip F a F\n",
    "    ... a'  G  a'     [H] dip F a F\n",
    "    ... a''    a'     [H] dip F a F\n",
    "    ... a'' H  a' F a F\n",
    "    ... a'' [G] dupdip [H] dip F a' F a F\n",
    "    ... a''  G  a''    [H] dip F a' F a F\n",
    "    ... a'''    a''    [H] dip F a' F a F\n",
    "    ... a''' H  a'' F a' F a F\n",
    "    ... a''' pop c  a'' F a' F a F\n",
    "    ...          c  a'' F a' F a F"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4\n",
    "And, last but not least, if you can combine as you go, starting with c, and the combiner needs to work on the current item, this is the form:\n",
    "\n",
    "    W == c swap [P] [pop] [[F] dupdip G] primrec\n",
    "\n",
    "    ... a c swap [P] [pop] [[F] dupdip G] primrec\n",
    "    ... c a [P] [pop] [[F] dupdip G] primrec\n",
    "    ... c a [F] dupdip G W\n",
    "    ... c a  F a G W\n",
    "    ... c a  F a'  W\n",
    "    ... c a  F a'  [F] dupdip G W\n",
    "    ... c a  F a'   F  a'     G W\n",
    "    ... c a  F a'   F  a''      W\n",
    "    ... c a  F a'   F  a''      [F] dupdip G W\n",
    "    ... c a  F a'   F  a''       F  a''    G W\n",
    "    ... c a  F a'   F  a''       F  a'''     W\n",
    "    ... c a  F a'   F  a''       F  a'''     pop\n",
    "    ... c a  F a'   F  a''       F"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Each of the four variations above can be specialized to ana- and catamorphic forms."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "def WTFmorphism(c, F, P, G):\n",
    "    '''Return a hylomorphism function H.'''\n",
    "\n",
    "    def H(a, d=c):\n",
    "        if P(a):\n",
    "            result = d\n",
    "        else:\n",
    "            a, b = G(a)\n",
    "            result = H(a, F(d, b))\n",
    "        return result\n",
    "\n",
    "    return H"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "F = lambda a, b: a + b\n",
    "P = lambda n: n <= 1\n",
    "G = lambda n: (n - 1, n - 1)\n",
    "\n",
    "wtf = WTFmorphism(0, F, P, G)\n",
    "\n",
    "print wtf(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    H == [P   ] [pop c ] [G          ] [dip F    ] genrec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "DefinitionWrapper.add_definitions('''\n",
    "P == 1 <=\n",
    "Ga == -- dup\n",
    "Gb == --\n",
    "c == 0\n",
    "F == +\n",
    "''', D)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                                                                             . [1 2 3] [[] =] [pop []] [uncons swap] [dip swons] genrec\n",
      "                                                                                                     [1 2 3] . [[] =] [pop []] [uncons swap] [dip swons] genrec\n",
      "                                                                                              [1 2 3] [[] =] . [pop []] [uncons swap] [dip swons] genrec\n",
      "                                                                                     [1 2 3] [[] =] [pop []] . [uncons swap] [dip swons] genrec\n",
      "                                                                       [1 2 3] [[] =] [pop []] [uncons swap] . [dip swons] genrec\n",
      "                                                           [1 2 3] [[] =] [pop []] [uncons swap] [dip swons] . genrec\n",
      "          [1 2 3] [[] =] [pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . ifte\n",
      "[1 2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [[1 2 3]] [[] =] . infra first choice i\n",
      "                                                                                                     [1 2 3] . [] = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [1 2 3]] swaack first choice i\n",
      "                                                                                                  [1 2 3] [] . = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [1 2 3]] swaack first choice i\n",
      "                                                                                                       False . [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [1 2 3]] swaack first choice i\n",
      "         False [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [1 2 3]] . swaack first choice i\n",
      "         [1 2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [False] . first choice i\n",
      "           [1 2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] False . choice i\n",
      "                          [1 2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . i\n",
      "                                                                                                     [1 2 3] . uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons\n",
      "                                                                                                     1 [2 3] . swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons\n",
      "                                                                                                     [2 3] 1 . [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons\n",
      "                                                  [2 3] 1 [[[] =] [pop []] [uncons swap] [dip swons] genrec] . dip swons\n",
      "                                                                                                       [2 3] . [[] =] [pop []] [uncons swap] [dip swons] genrec 1 swons\n",
      "                                                                                                [2 3] [[] =] . [pop []] [uncons swap] [dip swons] genrec 1 swons\n",
      "                                                                                       [2 3] [[] =] [pop []] . [uncons swap] [dip swons] genrec 1 swons\n",
      "                                                                         [2 3] [[] =] [pop []] [uncons swap] . [dip swons] genrec 1 swons\n",
      "                                                             [2 3] [[] =] [pop []] [uncons swap] [dip swons] . genrec 1 swons\n",
      "            [2 3] [[] =] [pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . ifte 1 swons\n",
      "    [2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [[2 3]] [[] =] . infra first choice i 1 swons\n",
      "                                                                                                       [2 3] . [] = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [2 3]] swaack first choice i 1 swons\n",
      "                                                                                                    [2 3] [] . = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [2 3]] swaack first choice i 1 swons\n",
      "                                                                                                       False . [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [2 3]] swaack first choice i 1 swons\n",
      "           False [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [2 3]] . swaack first choice i 1 swons\n",
      "           [2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 1 swons\n",
      "             [2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] False . choice i 1 swons\n",
      "                            [2 3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . i 1 swons\n",
      "                                                                                                       [2 3] . uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons 1 swons\n",
      "                                                                                                       2 [3] . swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons 1 swons\n",
      "                                                                                                       [3] 2 . [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons 1 swons\n",
      "                                                    [3] 2 [[[] =] [pop []] [uncons swap] [dip swons] genrec] . dip swons 1 swons\n",
      "                                                                                                         [3] . [[] =] [pop []] [uncons swap] [dip swons] genrec 2 swons 1 swons\n",
      "                                                                                                  [3] [[] =] . [pop []] [uncons swap] [dip swons] genrec 2 swons 1 swons\n",
      "                                                                                         [3] [[] =] [pop []] . [uncons swap] [dip swons] genrec 2 swons 1 swons\n",
      "                                                                           [3] [[] =] [pop []] [uncons swap] . [dip swons] genrec 2 swons 1 swons\n",
      "                                                               [3] [[] =] [pop []] [uncons swap] [dip swons] . genrec 2 swons 1 swons\n",
      "              [3] [[] =] [pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . ifte 2 swons 1 swons\n",
      "        [3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [[3]] [[] =] . infra first choice i 2 swons 1 swons\n",
      "                                                                                                         [3] . [] = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [3]] swaack first choice i 2 swons 1 swons\n",
      "                                                                                                      [3] [] . = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [3]] swaack first choice i 2 swons 1 swons\n",
      "                                                                                                       False . [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [3]] swaack first choice i 2 swons 1 swons\n",
      "             False [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [3]] . swaack first choice i 2 swons 1 swons\n",
      "             [3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 2 swons 1 swons\n",
      "               [3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] False . choice i 2 swons 1 swons\n",
      "                              [3] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . i 2 swons 1 swons\n",
      "                                                                                                         [3] . uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons 2 swons 1 swons\n",
      "                                                                                                        3 [] . swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons 2 swons 1 swons\n",
      "                                                                                                        [] 3 . [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons 2 swons 1 swons\n",
      "                                                     [] 3 [[[] =] [pop []] [uncons swap] [dip swons] genrec] . dip swons 2 swons 1 swons\n",
      "                                                                                                          [] . [[] =] [pop []] [uncons swap] [dip swons] genrec 3 swons 2 swons 1 swons\n",
      "                                                                                                   [] [[] =] . [pop []] [uncons swap] [dip swons] genrec 3 swons 2 swons 1 swons\n",
      "                                                                                          [] [[] =] [pop []] . [uncons swap] [dip swons] genrec 3 swons 2 swons 1 swons\n",
      "                                                                            [] [[] =] [pop []] [uncons swap] . [dip swons] genrec 3 swons 2 swons 1 swons\n",
      "                                                                [] [[] =] [pop []] [uncons swap] [dip swons] . genrec 3 swons 2 swons 1 swons\n",
      "               [] [[] =] [pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] . ifte 3 swons 2 swons 1 swons\n",
      "          [] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [[]] [[] =] . infra first choice i 3 swons 2 swons 1 swons\n",
      "                                                                                                          [] . [] = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] []] swaack first choice i 3 swons 2 swons 1 swons\n",
      "                                                                                                       [] [] . = [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] []] swaack first choice i 3 swons 2 swons 1 swons\n",
      "                                                                                                        True . [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] []] swaack first choice i 3 swons 2 swons 1 swons\n",
      "               True [[pop []] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] []] . swaack first choice i 3 swons 2 swons 1 swons\n",
      "               [] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] [True] . first choice i 3 swons 2 swons 1 swons\n",
      "                 [] [uncons swap [[[] =] [pop []] [uncons swap] [dip swons] genrec] dip swons] [pop []] True . choice i 3 swons 2 swons 1 swons\n",
      "                                                                                                 [] [pop []] . i 3 swons 2 swons 1 swons\n",
      "                                                                                                          [] . pop [] 3 swons 2 swons 1 swons\n",
      "                                                                                                             . [] 3 swons 2 swons 1 swons\n",
      "                                                                                                          [] . 3 swons 2 swons 1 swons\n",
      "                                                                                                        [] 3 . swons 2 swons 1 swons\n",
      "                                                                                                        [] 3 . swap cons 2 swons 1 swons\n",
      "                                                                                                        3 [] . cons 2 swons 1 swons\n",
      "                                                                                                         [3] . 2 swons 1 swons\n",
      "                                                                                                       [3] 2 . swons 1 swons\n",
      "                                                                                                       [3] 2 . swap cons 1 swons\n",
      "                                                                                                       2 [3] . cons 1 swons\n",
      "                                                                                                       [2 3] . 1 swons\n",
      "                                                                                                     [2 3] 1 . swons\n",
      "                                                                                                     [2 3] 1 . swap cons\n",
      "                                                                                                     1 [2 3] . cons\n",
      "                                                                                                     [1 2 3] . \n"
     ]
    }
   ],
   "source": [
    "V('[1 2 3] [[] =] [pop []] [uncons swap] [dip swons] genrec')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                               . 3 [P] [pop c] [Ga] [dip F] genrec\n",
      "                                                             3 . [P] [pop c] [Ga] [dip F] genrec\n",
      "                                                         3 [P] . [pop c] [Ga] [dip F] genrec\n",
      "                                                 3 [P] [pop c] . [Ga] [dip F] genrec\n",
      "                                            3 [P] [pop c] [Ga] . [dip F] genrec\n",
      "                                    3 [P] [pop c] [Ga] [dip F] . genrec\n",
      "    3 [P] [pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] . ifte\n",
      "3 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] [3] [P] . infra first choice i\n",
      "                                                             3 . P [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 3] swaack first choice i\n",
      "                                                             3 . 1 <= [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 3] swaack first choice i\n",
      "                                                           3 1 . <= [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 3] swaack first choice i\n",
      "                                                         False . [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 3] swaack first choice i\n",
      "False [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 3] . swaack first choice i\n",
      "3 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] [False] . first choice i\n",
      "  3 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] False . choice i\n",
      "                3 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] . i\n",
      "                                                             3 . Ga [[P] [pop c] [Ga] [dip F] genrec] dip F\n",
      "                                                             3 . -- dup [[P] [pop c] [Ga] [dip F] genrec] dip F\n",
      "                                                             2 . dup [[P] [pop c] [Ga] [dip F] genrec] dip F\n",
      "                                                           2 2 . [[P] [pop c] [Ga] [dip F] genrec] dip F\n",
      "                         2 2 [[P] [pop c] [Ga] [dip F] genrec] . dip F\n",
      "                                                             2 . [P] [pop c] [Ga] [dip F] genrec 2 F\n",
      "                                                         2 [P] . [pop c] [Ga] [dip F] genrec 2 F\n",
      "                                                 2 [P] [pop c] . [Ga] [dip F] genrec 2 F\n",
      "                                            2 [P] [pop c] [Ga] . [dip F] genrec 2 F\n",
      "                                    2 [P] [pop c] [Ga] [dip F] . genrec 2 F\n",
      "    2 [P] [pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] . ifte 2 F\n",
      "2 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] [2] [P] . infra first choice i 2 F\n",
      "                                                             2 . P [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 2] swaack first choice i 2 F\n",
      "                                                             2 . 1 <= [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 2] swaack first choice i 2 F\n",
      "                                                           2 1 . <= [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 2] swaack first choice i 2 F\n",
      "                                                         False . [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 2] swaack first choice i 2 F\n",
      "False [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 2] . swaack first choice i 2 F\n",
      "2 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] [False] . first choice i 2 F\n",
      "  2 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] False . choice i 2 F\n",
      "                2 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] . i 2 F\n",
      "                                                             2 . Ga [[P] [pop c] [Ga] [dip F] genrec] dip F 2 F\n",
      "                                                             2 . -- dup [[P] [pop c] [Ga] [dip F] genrec] dip F 2 F\n",
      "                                                             1 . dup [[P] [pop c] [Ga] [dip F] genrec] dip F 2 F\n",
      "                                                           1 1 . [[P] [pop c] [Ga] [dip F] genrec] dip F 2 F\n",
      "                         1 1 [[P] [pop c] [Ga] [dip F] genrec] . dip F 2 F\n",
      "                                                             1 . [P] [pop c] [Ga] [dip F] genrec 1 F 2 F\n",
      "                                                         1 [P] . [pop c] [Ga] [dip F] genrec 1 F 2 F\n",
      "                                                 1 [P] [pop c] . [Ga] [dip F] genrec 1 F 2 F\n",
      "                                            1 [P] [pop c] [Ga] . [dip F] genrec 1 F 2 F\n",
      "                                    1 [P] [pop c] [Ga] [dip F] . genrec 1 F 2 F\n",
      "    1 [P] [pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] . ifte 1 F 2 F\n",
      "1 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] [1] [P] . infra first choice i 1 F 2 F\n",
      "                                                             1 . P [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 1] swaack first choice i 1 F 2 F\n",
      "                                                             1 . 1 <= [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 1] swaack first choice i 1 F 2 F\n",
      "                                                           1 1 . <= [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 1] swaack first choice i 1 F 2 F\n",
      "                                                          True . [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 1] swaack first choice i 1 F 2 F\n",
      " True [[pop c] [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] 1] . swaack first choice i 1 F 2 F\n",
      " 1 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] [True] . first choice i 1 F 2 F\n",
      "   1 [Ga [[P] [pop c] [Ga] [dip F] genrec] dip F] [pop c] True . choice i 1 F 2 F\n",
      "                                                     1 [pop c] . i 1 F 2 F\n",
      "                                                             1 . pop c 1 F 2 F\n",
      "                                                               . c 1 F 2 F\n",
      "                                                               . 0 1 F 2 F\n",
      "                                                             0 . 1 F 2 F\n",
      "                                                           0 1 . F 2 F\n",
      "                                                           0 1 . + 2 F\n",
      "                                                             1 . 2 F\n",
      "                                                           1 2 . F\n",
      "                                                           1 2 . +\n",
      "                                                             3 . \n"
     ]
    }
   ],
   "source": [
    "V('3 [P] [pop c] [Ga] [dip F] genrec')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                                         . 3 [P] [pop []] [Ga] [dip swons] genrec\n",
      "                                                                       3 . [P] [pop []] [Ga] [dip swons] genrec\n",
      "                                                                   3 [P] . [pop []] [Ga] [dip swons] genrec\n",
      "                                                          3 [P] [pop []] . [Ga] [dip swons] genrec\n",
      "                                                     3 [P] [pop []] [Ga] . [dip swons] genrec\n",
      "                                         3 [P] [pop []] [Ga] [dip swons] . genrec\n",
      "    3 [P] [pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] . ifte\n",
      "3 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] [3] [P] . infra first choice i\n",
      "                                                                       3 . P [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 3] swaack first choice i\n",
      "                                                                       3 . 1 <= [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 3] swaack first choice i\n",
      "                                                                     3 1 . <= [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 3] swaack first choice i\n",
      "                                                                   False . [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 3] swaack first choice i\n",
      "False [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 3] . swaack first choice i\n",
      "3 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] [False] . first choice i\n",
      "  3 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] False . choice i\n",
      "                 3 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] . i\n",
      "                                                                       3 . Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons\n",
      "                                                                       3 . -- dup [[P] [pop []] [Ga] [dip swons] genrec] dip swons\n",
      "                                                                       2 . dup [[P] [pop []] [Ga] [dip swons] genrec] dip swons\n",
      "                                                                     2 2 . [[P] [pop []] [Ga] [dip swons] genrec] dip swons\n",
      "                              2 2 [[P] [pop []] [Ga] [dip swons] genrec] . dip swons\n",
      "                                                                       2 . [P] [pop []] [Ga] [dip swons] genrec 2 swons\n",
      "                                                                   2 [P] . [pop []] [Ga] [dip swons] genrec 2 swons\n",
      "                                                          2 [P] [pop []] . [Ga] [dip swons] genrec 2 swons\n",
      "                                                     2 [P] [pop []] [Ga] . [dip swons] genrec 2 swons\n",
      "                                         2 [P] [pop []] [Ga] [dip swons] . genrec 2 swons\n",
      "    2 [P] [pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] . ifte 2 swons\n",
      "2 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] [2] [P] . infra first choice i 2 swons\n",
      "                                                                       2 . P [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons\n",
      "                                                                       2 . 1 <= [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons\n",
      "                                                                     2 1 . <= [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons\n",
      "                                                                   False . [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons\n",
      "False [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 2] . swaack first choice i 2 swons\n",
      "2 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] [False] . first choice i 2 swons\n",
      "  2 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] False . choice i 2 swons\n",
      "                 2 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] . i 2 swons\n",
      "                                                                       2 . Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons 2 swons\n",
      "                                                                       2 . -- dup [[P] [pop []] [Ga] [dip swons] genrec] dip swons 2 swons\n",
      "                                                                       1 . dup [[P] [pop []] [Ga] [dip swons] genrec] dip swons 2 swons\n",
      "                                                                     1 1 . [[P] [pop []] [Ga] [dip swons] genrec] dip swons 2 swons\n",
      "                              1 1 [[P] [pop []] [Ga] [dip swons] genrec] . dip swons 2 swons\n",
      "                                                                       1 . [P] [pop []] [Ga] [dip swons] genrec 1 swons 2 swons\n",
      "                                                                   1 [P] . [pop []] [Ga] [dip swons] genrec 1 swons 2 swons\n",
      "                                                          1 [P] [pop []] . [Ga] [dip swons] genrec 1 swons 2 swons\n",
      "                                                     1 [P] [pop []] [Ga] . [dip swons] genrec 1 swons 2 swons\n",
      "                                         1 [P] [pop []] [Ga] [dip swons] . genrec 1 swons 2 swons\n",
      "    1 [P] [pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] . ifte 1 swons 2 swons\n",
      "1 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] [1] [P] . infra first choice i 1 swons 2 swons\n",
      "                                                                       1 . P [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons\n",
      "                                                                       1 . 1 <= [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons\n",
      "                                                                     1 1 . <= [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons\n",
      "                                                                    True . [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons\n",
      " True [[pop []] [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] 1] . swaack first choice i 1 swons 2 swons\n",
      " 1 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] [True] . first choice i 1 swons 2 swons\n",
      "   1 [Ga [[P] [pop []] [Ga] [dip swons] genrec] dip swons] [pop []] True . choice i 1 swons 2 swons\n",
      "                                                              1 [pop []] . i 1 swons 2 swons\n",
      "                                                                       1 . pop [] 1 swons 2 swons\n",
      "                                                                         . [] 1 swons 2 swons\n",
      "                                                                      [] . 1 swons 2 swons\n",
      "                                                                    [] 1 . swons 2 swons\n",
      "                                                                    [] 1 . swap cons 2 swons\n",
      "                                                                    1 [] . cons 2 swons\n",
      "                                                                     [1] . 2 swons\n",
      "                                                                   [1] 2 . swons\n",
      "                                                                   [1] 2 . swap cons\n",
      "                                                                   2 [1] . cons\n",
      "                                                                   [2 1] . \n"
     ]
    }
   ],
   "source": [
    "V('3 [P] [pop []] [Ga] [dip swons] genrec')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                                                               . [2 1] [[] =] [pop c] [uncons swap] [dip F] genrec\n",
      "                                                                                         [2 1] . [[] =] [pop c] [uncons swap] [dip F] genrec\n",
      "                                                                                  [2 1] [[] =] . [pop c] [uncons swap] [dip F] genrec\n",
      "                                                                          [2 1] [[] =] [pop c] . [uncons swap] [dip F] genrec\n",
      "                                                            [2 1] [[] =] [pop c] [uncons swap] . [dip F] genrec\n",
      "                                                    [2 1] [[] =] [pop c] [uncons swap] [dip F] . genrec\n",
      "        [2 1] [[] =] [pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] . ifte\n",
      "[2 1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] [[2 1]] [[] =] . infra first choice i\n",
      "                                                                                         [2 1] . [] = [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [2 1]] swaack first choice i\n",
      "                                                                                      [2 1] [] . = [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [2 1]] swaack first choice i\n",
      "                                                                                         False . [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [2 1]] swaack first choice i\n",
      "       False [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [2 1]] . swaack first choice i\n",
      "       [2 1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] [False] . first choice i\n",
      "         [2 1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] False . choice i\n",
      "                       [2 1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] . i\n",
      "                                                                                         [2 1] . uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F\n",
      "                                                                                         2 [1] . swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F\n",
      "                                                                                         [1] 2 . [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F\n",
      "                                           [1] 2 [[[] =] [pop c] [uncons swap] [dip F] genrec] . dip F\n",
      "                                                                                           [1] . [[] =] [pop c] [uncons swap] [dip F] genrec 2 F\n",
      "                                                                                    [1] [[] =] . [pop c] [uncons swap] [dip F] genrec 2 F\n",
      "                                                                            [1] [[] =] [pop c] . [uncons swap] [dip F] genrec 2 F\n",
      "                                                              [1] [[] =] [pop c] [uncons swap] . [dip F] genrec 2 F\n",
      "                                                      [1] [[] =] [pop c] [uncons swap] [dip F] . genrec 2 F\n",
      "          [1] [[] =] [pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] . ifte 2 F\n",
      "    [1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] [[1]] [[] =] . infra first choice i 2 F\n",
      "                                                                                           [1] . [] = [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [1]] swaack first choice i 2 F\n",
      "                                                                                        [1] [] . = [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [1]] swaack first choice i 2 F\n",
      "                                                                                         False . [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [1]] swaack first choice i 2 F\n",
      "         False [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [1]] . swaack first choice i 2 F\n",
      "         [1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] [False] . first choice i 2 F\n",
      "           [1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] False . choice i 2 F\n",
      "                         [1] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] . i 2 F\n",
      "                                                                                           [1] . uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F 2 F\n",
      "                                                                                          1 [] . swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F 2 F\n",
      "                                                                                          [] 1 . [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F 2 F\n",
      "                                            [] 1 [[[] =] [pop c] [uncons swap] [dip F] genrec] . dip F 2 F\n",
      "                                                                                            [] . [[] =] [pop c] [uncons swap] [dip F] genrec 1 F 2 F\n",
      "                                                                                     [] [[] =] . [pop c] [uncons swap] [dip F] genrec 1 F 2 F\n",
      "                                                                             [] [[] =] [pop c] . [uncons swap] [dip F] genrec 1 F 2 F\n",
      "                                                               [] [[] =] [pop c] [uncons swap] . [dip F] genrec 1 F 2 F\n",
      "                                                       [] [[] =] [pop c] [uncons swap] [dip F] . genrec 1 F 2 F\n",
      "           [] [[] =] [pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] . ifte 1 F 2 F\n",
      "      [] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] [[]] [[] =] . infra first choice i 1 F 2 F\n",
      "                                                                                            [] . [] = [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] []] swaack first choice i 1 F 2 F\n",
      "                                                                                         [] [] . = [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] []] swaack first choice i 1 F 2 F\n",
      "                                                                                          True . [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] []] swaack first choice i 1 F 2 F\n",
      "           True [[pop c] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] []] . swaack first choice i 1 F 2 F\n",
      "           [] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] [True] . first choice i 1 F 2 F\n",
      "             [] [uncons swap [[[] =] [pop c] [uncons swap] [dip F] genrec] dip F] [pop c] True . choice i 1 F 2 F\n",
      "                                                                                    [] [pop c] . i 1 F 2 F\n",
      "                                                                                            [] . pop c 1 F 2 F\n",
      "                                                                                               . c 1 F 2 F\n",
      "                                                                                               . 0 1 F 2 F\n",
      "                                                                                             0 . 1 F 2 F\n",
      "                                                                                           0 1 . F 2 F\n",
      "                                                                                           0 1 . + 2 F\n",
      "                                                                                             1 . 2 F\n",
      "                                                                                           1 2 . F\n",
      "                                                                                           1 2 . +\n",
      "                                                                                             3 . \n"
     ]
    }
   ],
   "source": [
    "V('[2 1] [[] =] [pop c ] [uncons swap] [dip F] genrec')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Appendix - Fun with Symbols\n",
    "\n",
    "    |[ (c, F), (G, P) ]| == (|c, F|) • [(G, P)]\n",
    "\n",
    "[\"Bananas, Lenses, & Barbed Wire\"](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.41.125)\n",
    "\n",
    "    (|...|)  [(...)]  [<...>]\n",
    "\n",
    "I think they are having slightly too much fun with the symbols.\n",
    "\n",
    "\"Too much is always better than not enough.\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
