Works with letters, added trimmed Lovecraft
[name-generation.git] / markov / markov.ipynb
index ff393e1d8901c4519555735333659fa44dc18b44..26d94e763d75c9c682183edeafeb86d83aa6e9d3 100644 (file)
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 53,
+   "execution_count": 87,
    "metadata": {
     "collapsed": true
    },
@@ -12,7 +12,8 @@
     "import string\n",
     "import collections\n",
     "import unicodedata\n",
-    "import random"
+    "import random\n",
+    "from IPython.core.display import display, HTML"
    ]
   },
   {
     "double_quotes = \"let's see how such a ''circular'' definition\""
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": 78,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "cat = ''.join"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": 3,
    "cell_type": "code",
    "execution_count": 11,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    "outputs": [
     {
    "cell_type": "code",
    "execution_count": 13,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    "outputs": [
     {
    "cell_type": "code",
    "execution_count": 14,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    "outputs": [
     {
    "cell_type": "code",
    "execution_count": 15,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
-    "def find_counts_of_sentence(tokens, counts, tuple_size):\n",
-    "    for i in range(len(tokens)-(tuple_size)):\n",
-    "        counts[tuple(tokens[i:i+tuple_size])].update([tokens[i+tuple_size]])\n",
-    "    counts[tuple(tokens[-tuple_size:])].update(None)\n",
+    "def find_counts_of_item(item, counts, tuple_size):\n",
+    "    for i in range(len(item)-(tuple_size)):\n",
+    "        counts[tuple(item[i:i+tuple_size])].update([item[i+tuple_size]])\n",
+    "    counts[tuple(item[-tuple_size:])].update([None])\n",
     "    return counts"
    ]
   },
    "cell_type": "code",
    "execution_count": 16,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
-    "def find_counts(sentences, tuple_size=2):\n",
+    "def find_counts(items, tuple_size=2):\n",
     "    counts = collections.defaultdict(collections.Counter)\n",
     "    starts = collections.Counter()\n",
-    "    for sentence in sentences:\n",
-    "        counts = find_counts_of_sentence(sentence, counts, tuple_size)\n",
-    "        starts[tuple(sentence[:tuple_size])] += 1\n",
+    "    for item in items:\n",
+    "        counts = find_counts_of_item(item, counts, tuple_size)\n",
+    "        starts[tuple(item[:tuple_size])] += 1\n",
     "    return starts, counts"
    ]
   },
    "cell_type": "code",
    "execution_count": 18,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    "outputs": [
     {
        "              ('better', 'approximations'): Counter({'to': 1}),\n",
        "              ('obtain', 'better'): Counter({'and': 1}),\n",
        "              ('process', ','): Counter({'we': 1}),\n",
-       "              ('root', '.'): Counter(),\n",
+       "              ('root', '.'): Counter({None: 1}),\n",
        "              ('square', 'root'): Counter({'.': 1}),\n",
        "              ('the', 'square'): Counter({'root': 1}),\n",
        "              ('this', 'process'): Counter({',': 1}),\n",
    "cell_type": "code",
    "execution_count": 20,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    "outputs": [
     {
        "              ('for', 'the', 'radicand'): Counter({'(': 1}),\n",
        "              ('formalize', 'the', 'process'): Counter({'in': 1}),\n",
        "              ('from', 'the', 'radicand'): Counter({'by': 1}),\n",
-       "              ('get', 'started', '.'): Counter(),\n",
+       "              ('get', 'started', '.'): Counter({None: 1}),\n",
        "              ('good', '-', 'enough'): Counter({'?': 2}),\n",
        "              ('good', 'enough', \".''\"): Counter({'The': 1}),\n",
        "              ('good', 'enough', 'for'): Counter({'our': 1}),\n",
-       "              ('good', 'test', '.'): Counter(),\n",
+       "              ('good', 'test', '.'): Counter({None: 1}),\n",
        "              ('guess', '(', 'sqrt'): Counter({'-': 1}),\n",
        "              ('guess', '(/', 'x'): Counter({'guess': 1}),\n",
        "              ('guess', ')', 'x'): Counter({'))': 1}),\n",
        "              ('improve', 'guess', 'x'): Counter({')': 2}),\n",
        "              ('improve', 'the', 'answer'): Counter({'until': 1}),\n",
        "              ('improved', 'by', 'averaging'): Counter({'it': 1}),\n",
-       "              ('improved', 'guess', '.'): Counter(),\n",
+       "              ('improved', 'guess', '.'): Counter({None: 1}),\n",
        "              ('in', 'terms', 'of'): Counter({'procedures': 1}),\n",
        "              ('is', 'close', 'enough'): Counter({'so': 1}),\n",
        "              ('is', 'good', 'enough'): Counter({'for': 1}),\n",
        "              ('not', 'really', 'a'): Counter({'very': 1}),\n",
        "              ('number', 'whose', 'square'): Counter({'root': 1}),\n",
        "              ('obtain', 'better', 'and'): Counter({'better': 1}),\n",
-       "              ('of', 'procedures', '.'): Counter(),\n",
+       "              ('of', 'procedures', '.'): Counter({None: 1}),\n",
        "              ('of', 'the', 'radicand'): Counter({'and': 1}),\n",
        "              ('old', 'guess', ':'): Counter({'(': 1}),\n",
        "              ('our', 'purposes', ','): Counter({'we': 1}),\n",
        "              ('sqrt', '-', 'iter'): Counter({'(': 1, 'guess': 1}),\n",
        "              ('square', 'differs', 'from'): Counter({'the': 1}),\n",
        "              ('square', 'guess', ')'): Counter({'x': 1}),\n",
-       "              ('square', 'root', '.'): Counter(),\n",
+       "              ('square', 'root', '.'): Counter({None: 1}),\n",
        "              ('square', 'root', 'we'): Counter({'are': 1}),\n",
        "              ('start', 'with', 'a'): Counter({'value': 1}),\n",
        "              ('strategy', 'as', 'a'): Counter({'procedure': 1}),\n",
        "              ('than', 'a', 'predetermined'): Counter({'tolerance': 1}),\n",
        "              ('that', 'its', 'square'): Counter({'differs': 1}),\n",
        "              ('the', 'answer', 'until'): Counter({'it': 1}),\n",
-       "              ('the', 'guess', '.'): Counter(),\n",
+       "              ('the', 'guess', '.'): Counter({None: 1}),\n",
        "              ('the', 'guess', 'is'): Counter({'good': 1}),\n",
        "              ('the', 'number', 'whose'): Counter({'square': 1}),\n",
        "              ('the', 'old', 'guess'): Counter({':': 1}),\n",
     {
      "data": {
       "text/plain": [
-       "[(('subset', 'of', 'mathematical'), Counter({'logic': 1})),\n",
-       " (('at', 'MIT', 'who'), Counter({'major': 1})),\n",
-       " (('enforces', 'the', 'restriction'), Counter({'that': 1})),\n",
-       " (('makes', 'it', 'very'), Counter({'difficult': 1})),\n",
-       " (('understand', 'the', \"compiler's\"), Counter({'preserving': 1})),\n",
-       " (('with', 'instructions', 'to'), Counter({'initialize': 1, 'test': 1})),\n",
-       " (('to', 'problems', 'in'), Counter({'adding': 1})),\n",
-       " (('problem', 'is', 'and'), Counter({'how': 1})),\n",
-       " (('stream', '(', 'conjoin'), Counter({'(': 1})),\n",
-       " (('organization', ',', 'then'), Counter({'to': 1}))]"
+       "[(('the', 'controller', 'completely'), Counter({'describeof': 1})),\n",
+       " (('equations', 'imply', 'that'), Counter({'(': 1})),\n",
+       " (('important', 'point', 'to'), Counter({'note': 1, 'observe': 1})),\n",
+       " (('separately', 'by', 'each'), Counter({'query': 1})),\n",
+       " (('to', 'explore', 'variations'), Counter({'of': 1})),\n",
+       " (('rock', 'songs', '.'), Counter({None: 1})),\n",
+       " (('software', 'engineers', 'have'), Counter({'the': 1})),\n",
+       " (('great', 'confusion', ','), Counter({'as': 1})),\n",
+       " (('increasingly', 'elaborate', 'models'), Counter({'of': 1})),\n",
+       " (('-', 'lambda1', '))'), Counter({'entry2': 2}))]"
       ]
      },
      "execution_count": 24,
     {
      "data": {
       "text/plain": [
-       "[(('With', 'permanent', '-'), 1),\n",
-       " (('The', 'recursive', 'compilation'), 1),\n",
-       " (('Define', 'abstractions', 'that'), 1),\n",
-       " (('Hall', 'the', 'Rosalind'), 1),\n",
-       " (('The', 'effect', 'executingnew'), 1),\n",
-       " (('1', '-', '4.1'), 1),\n",
-       " (('So', 'the', 'procedure'), 1),\n",
-       " (('However', ',', 'with'), 1),\n",
-       " (('Figure', '3.2', 'shows'), 1),\n",
-       " (('In', 'software', '-'), 1)]"
+       "[(('29', 'There', 'is'), 1),\n",
+       " (('In', 'such', 'an'), 1),\n",
+       " (('To', 'answer', 'a'), 1),\n",
+       " (('Y', '.'), 2),\n",
+       " (('If', 'f', '('), 1),\n",
+       " (('This', 'can', 'greatly'), 1),\n",
+       " (('Design', 'a', 'machine'), 1),\n",
+       " (('Exercise', '2.8', '.'), 1),\n",
+       " (('Control', '(', 'how'), 1),\n",
+       " (('C', '.'), 4)]"
       ]
      },
      "execution_count": 25,
     {
      "data": {
       "text/plain": [
-       "[]"
+       "[None]"
       ]
      },
      "execution_count": 26,
     {
      "data": {
       "text/plain": [
-       "('The', 'left', \"''\")"
+       "('The', 'constructor', 'for')"
       ]
      },
      "execution_count": 27,
    },
    "outputs": [],
    "source": [
-    "def markov_sentence(counts, starts, items=None):\n",
-    "    i = 0\n",
-    "    current = random.choice(list(starts.elements()))\n",
-    "    chain = list(current)\n",
-    "    nexts = list(counts[current].elements())\n",
-    "    while nexts and items and i < items:\n",
-    "        next_item = random.choice(nexts)\n",
-    "        chain += [next_item]\n",
-    "        current = current[1:] + (next_item, )\n",
-    "        i += 1\n",
-    "        nexts = list(counts[current].elements())\n",
-    "        # print(chain, ':', current, ':', nexts)\n",
+    "def markov_item(starts, counts, max_len=None):\n",
+    "    valid_found = False\n",
+    "    while not valid_found:\n",
+    "        i = 0\n",
+    "        current = random.choice(list(starts.elements()))\n",
+    "        chain = list(current)\n",
+    "        next_item = random.choice(list(counts[current].elements()))\n",
+    "        while next_item and ((max_len and i < max_len) or not max_len):\n",
+    "            chain += [next_item]\n",
+    "            current = current[1:] + (next_item, )\n",
+    "            i += 1\n",
+    "            next_item = random.choice(list(counts[current].elements()))\n",
+    "            # print(chain, ':', current, ':', list(counts[current].elements()), ':', next_item)\n",
+    "        if max_len and i < max_len:\n",
+    "            valid_found = True\n",
+    "        if not max_len:\n",
+    "            valid_found = True\n",
     "    return chain"
    ]
   },
     {
      "data": {
       "text/plain": [
-       "'Rewrite the sqrt procedure of section 2.2 .'"
+       "'46 Alternatively , multiprocessing computers provide instructions that support atomic operations directly in hardware .'"
       ]
      },
      "execution_count": 30,
     }
    ],
    "source": [
-    "' '.join(markov_sentence(sicp_counts, sicp_starts, 500))"
+    "' '.join(markov_item(sicp_starts, sicp_counts, 500))"
    ]
   },
   {
     }
    ],
    "source": [
-    "' '.join(markov_sentence(one_s_counts, one_s_starts, 500))"
+    "' '.join(markov_item(one_s_starts, one_s_counts, 500))"
    ]
   },
   {
        "              ('better', 'approximations'): Counter({'to': 1}),\n",
        "              ('obtain', 'better'): Counter({'and': 1}),\n",
        "              ('process', ','): Counter({'we': 1}),\n",
-       "              ('root', '.'): Counter(),\n",
+       "              ('root', '.'): Counter({None: 1}),\n",
        "              ('square', 'root'): Counter({'.': 1}),\n",
        "              ('the', 'square'): Counter({'root': 1}),\n",
        "              ('this', 'process'): Counter({',': 1}),\n",
   },
   {
    "cell_type": "code",
-   "execution_count": 35,
+   "execution_count": 34,
    "metadata": {
     "collapsed": false
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 36,
+   "execution_count": 35,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "'Griss, Martin L.'"
+       "'4, we can usually do better by taking advantage of additional structure that may be represented in two almost equivalent ways: and He has written the following two rules, we can find integers not divisible by 7 simply by accessing elements of this stream: ( define input- 1 input- 2 to 1 and allow the values to which they are listed.'"
       ]
      },
-     "execution_count": 36,
+     "execution_count": 35,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "sentence_join(markov_sentence(sicp_counts, sicp_starts, 500))"
+    "sentence_join(markov_item(sicp_starts, sicp_counts, 500))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 38,
+   "execution_count": 36,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "'2 Compiling Expressions In this section we will examine several Lisp procedures and design a specific register machine to execute programs written in Scheme, we used a succession of programs, most of the pairs generated in a typical computation are used only to speed up the evaluator by separating analysis from runtime execution. Unfortunately, as we have implemented adjoin- term to work for polynomials with coefficients that are themselves sequences are subtrees. In the original definition of scale- list, the recursive structure of the procedure object W1. A. Turner, David, and Daniel Weinreb. 4 Compound Procedures 1.1. Although their method was complex, it produced reasonably efficient programs because it did little redundant search. Exercise 3.13 constructed such lists. Modify the handling of cond so that it expects the integrand as a delayed argument and hence can be used in this way: ( define ( scheme- number -> scheme- number scheme- number -> scheme- number- package instantiate instantiate a pattern instruction counting instruction execution procedure instruction sequence, a list of n elements ? Exercise 2.65. Exercise 3.22.'"
+       "\"3. We model state with local state variables describing the actual object's state. Since ? x is bound in the frame. 61 Interest in logic programming peaked during the early 80s when the Japanese government began an ambitious project aimed at building superfast computers optimized to run logic programming languages. 4.1. We will compile the definition of f and start the machine, and so on, his modified eval will usually check fewer clauses than the original eval before identifying the type of the expression. This makes no difference in the values returned by the call to make- operation- exp- label dest)))) ( lambda ( pair) ( prime ? (+ ( car pair) ( cadr s))) ( set- signal ! input- 1 ( right- branch set)) ( element- of list2))) ( require ( null ? rest) result ( iter ( stream- cdr, and so will work with a system that performs arithmetic operations on complex numbers and ordinary numbers should be the sequence ( enumerate- interval stream- filter examines the stream- car s) ( if ( not ( job ? x ( computer ? type) could be constructed by evaluating the expression ( f ? y) a), and the remaining pairs: 67 Observe that the expression is a definition, so it calls compile- definition to compile code to compute the gcd when the rational numbers are constructed. 1. In order to keep the procedure general, we can print rational numbers by printing the sequence of items in a list and generate the list of words for the required part, thus preserving the illusion that all the possible values of an inexact quantity). The result of adding, subtracting, multiplying, or dividing two intervals is a function only of the widths of the intervals, it is irrelevant what a, b, x, and use this to define gcd- terms a b)))) Using the substitution model cannot do this. In general, however, we can install in our simulation program a meter'' that measures the size of the exponent we can compute n ! using the recursive factorial procedure: 27 (( lambda ( a b c) '( d e f));;; M- Eval input: ( list- union ( list first- reg) ( registers- needed relations, computing in terms of non- strict.\""
       ]
      },
-     "execution_count": 38,
+     "execution_count": 36,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "' '.join(sentence_join(markov_sentence(sicp_counts, sicp_starts, 500)) for _ in range(10))"
+    "' '.join(sentence_join(markov_item(sicp_starts, sicp_counts, 500)) for _ in range(10))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 42,
+   "execution_count": 37,
    "metadata": {
     "collapsed": false
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 43,
+   "execution_count": 38,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "'4: 5 And Simon answering said unto him, Thou wicked and slothful servant, thou knewest that I reap where I sowed not, and he that is of a perverse heart shall be there: and make no mention of the name of it called Babel; because the former troubles are forgotten, and because of the Ethiopian woman whom he had chosen. 20: 6 But Abram said unto Lot, Hast thou found honey ? eat so much as heard whether there be prophecies, they shall fall one upon another, that shall not be cut off from among his people: neither shalt thou suffer the salt of the covenant stood: and they rest not day and night come to an end, 21: 26 They mount up to heaven, and on camels, and asses. 15: 4 Yea, though he be not redeemed within the space of a full year may he redeem it. 89: 43 Thou hast also committed fornication with her, and disallowed her not: then all her vows, or of the strangers for a prey, and to the soldiers, when they saw that the Syrians were fled, they likewise fled before Abishai his brother, is in darkness even until now. 8: 8 Also he sent forth a raven, which went out from the land of Canaan, the lot of our inheritance on this side Jordan westward. 2: 6 His body also was like the fiery flame, and the Jebusites, which were remaining of the families of the Gershonites according to their families was thus: even the border of Simeon, Shemuel the son of Kareah spake to Gedaliah in Mizpah secretly saying, Let neither man nor woman alive, to bring up the tithe of the corn, and to the king, and of oil, ye shall keep this service. 8: 8 So Rabshakeh returned, and corrupted all their doings. 18: 17 And the flood was forty days upon the land, and their wives, and all they that were vexed with unclean spirits: and they possessed it, and set his heart on Daniel to deliver him: and he said unto them thus, Who commanded you to perform, even ten thousand captives, and brought him to the face, both he that soweth and he that formed the eye, I am Christ; and shall set the woman before the LORD, the fire causeth the waters to boil, to make an atonement for your sin. 2: 22 Thou shalt eat it within thy gates: 20: 4 And whither I go. 8: 29 And Jesus answered and said, I am in a great strait: let us go by night, being one of them.'"
+       "'12: 1 Help, LORD; for thy God helpeth thee. 66: 8 O bless our God, and that ye might fear the LORD from this time forth and for evermore. 9: 30 If there be laid on him a scarlet robe. 16: 38 The son of Amzi, the son of Micah, as he hath said, and be dandled upon her knees. 4: 12 And David commanded to gather together the strangers that came out of the land, saying, Because I drew him out of the temple which was in Bethlehem. 3: 24 Then he is gracious, and will give ten tribes to thee: We have such an high priest became us, who knew no sin; that we should die in the pit, and his oath unto Isaac; 105: 15 Saying, Touch not mine anointed, and be astonied one with another what they might do to Jesus. 10: 8 Neither let us commit fornication, as some of them committed, and of the south shall come into the land which I sware unto Abraham, As for Sarai thy wife, and upon the great toe of his right foot, upon the four corners of one base: and the truth shall make you free. 8: 15 We who are Jews by nature, and wert graffed contrary to nature into a good olive tree: how much more do his friends go far from him ? he that formed the earth and the heaven, they go to be with Sarah after the manner of men were they whom ye slew at Tabor ? And they said, Seven. 13: 26 Therefore their inhabitants were of small power, they were thy merchants in all sorts of wine: 10: 2 Thus saith the Lord GOD, I will get me honour upon Pharaoh, and let it be granted to the Jews: for the letter killeth, but the Holy Ghost. 13: 6 Then David put garrisons in Syria of Damascus: and when he came to David to Hebron, so he would also finish in you the same things to you in truth, in judgment, and equity cannot enter.'"
       ]
      },
-     "execution_count": 43,
+     "execution_count": 38,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "' '.join(sentence_join(markov_sentence(kjb_counts, kjb_starts, 500)) for _ in range(10))"
+    "' '.join(sentence_join(markov_item(kjb_starts, kjb_counts, 500)) for _ in range(10))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 44,
+   "execution_count": 39,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 45,
+   "execution_count": 40,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": false
    },
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "[(('The', 'programmer', 'must'), 1),\n",
-       " (('And', 'Jehoram', 'reigned'), 1),\n",
-       " (('The', 'recursive', 'compilation'), 1),\n",
-       " (('17', ':', '22'), 10),\n",
-       " (('Hall', 'the', 'Rosalind'), 1),\n",
-       " (('107', ':', '10'), 1),\n",
-       " (('The', 'stored', 'value'), 1),\n",
-       " (('148', ':', '1'), 1),\n",
-       " (('So', 'the', 'procedure'), 1),\n",
-       " (('Woe', 'to', 'the'), 1),\n",
-       " (('Design', 'and', 'implement'), 1),\n",
-       " (('Figure', '3.2', 'shows'), 1),\n",
-       " (('23', ':', '30'), 7),\n",
-       " (('51', ':', '6'), 3),\n",
-       " (('The', 'key', 'modularity'), 1),\n",
-       " (('6', ':', '17'), 25),\n",
-       " (('47', ':', '1'), 5),\n",
-       " (('mutable', 'Indeed', ','), 1),\n",
-       " (('And', 'he', 'saith'), 4),\n",
-       " (('31', 'Exercise', '1.9'), 1)]"
+       "[(('119', ':', '112'), 1),\n",
+       " (('29', 'There', 'is'), 1),\n",
+       " (('To', 'answer', 'a'), 1),\n",
+       " (('Y', '.'), 2),\n",
+       " (('36', ':', '36'), 3),\n",
+       " (('Ye', 'shall', 'seek'), 1),\n",
+       " (('And', 'in', 'like'), 1),\n",
+       " (('If', 'f', '('), 1),\n",
+       " (('3', ':', '47'), 1),\n",
+       " (('27', ':', '24'), 7),\n",
+       " (('26', ':', '28'), 5),\n",
+       " (('Control', '(', 'how'), 1),\n",
+       " (('16', ':', '43'), 3),\n",
+       " (('They', 'should', 'be'), 1),\n",
+       " (('139', ':', '9'), 1),\n",
+       " (('So', 'he', 'drew'), 1),\n",
+       " (('If', 'the', 'symbol'), 1),\n",
+       " (('RC', 'should', 'take'), 1),\n",
+       " (('?', 'type', ')'), 3),\n",
+       " (('How', 'does', 'the'), 1)]"
       ]
      },
-     "execution_count": 45,
+     "execution_count": 40,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 46,
+   "execution_count": 41,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 47,
+   "execution_count": 42,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "\"The New Hacker's Dictionary. 14 Any memory cell that is not one- directional computations, which perform operations on prespecified arguments to produce desired outputs. 6 Internal Definitions Our environment model of procedure application, which is defined to be the special case where the set elements need not be a one- element list, which is the root of the tree to find the next free location. Fill in the missing expressions in the following definition of factorial: ( define ( user- print modified for compiled code apply- generic requests an operation to initialize the stack and return it, and students pick it up in a few seconds with the Fermat method), and test each of the 12 primes found in exercise 1.22. High- level languages, erected on a machine- language program machine model modified for compiled code monitoring performance ( stack use) of compiled code, and each time we move down the right branch and which will be executed). We have not shown the part of the implementation. ( Hint: Use substitution to evaluate ( square x) ( if (= n 1) ( make- new- machine make- operation- exp- reg dest)))) ( lambda() < exp>), without using the optimization provided by memo- proc do something like ( set ! * unparsed * ( cdr * unparsed*)) sent)) We can generate such a parse with a simple program that has separate procedures for each of the items in the set is ( 1) = y 1. Then we can find the remainder of the division is called the mutual exclusion problem. 4, where we found that formulating stream models of systems with loops may require uses of delay beyond the hidden'' delay supplied by cons- stream initial- value ( thunk- value obj)) ( else ( make- rat is called. Assume that the coefficients of the terms and add them. If none of the < test>, and the result of the operation is valid.\""
+       "\"In becoming an expert programmer, just as our embedded Lisp evaluator uses primitives and control structure from the underlying Scheme system to perform arithmetic with rational numbers. What are these constants ? Similarly, find the ratios of the stack required to compute n ! by specifying that we first multiply 1 by 2, 3, 6, 10, 15,.... Exercise 3.56. Describe what kind of information ( patterns and frames) is included in this history, and how abstraction preserves for us the flexibility to consider alternate implementations. When evaluation is complete, x will be 1, y will be 2, 3 } could be represented as a pair of numbers: the x coordinate and the y coordinate. 43- 112. The timing diagram in figure 3.29, where Peter changes the account balance between the times when Paul accesses the account only very rarely. The painter that draws a line on the screen between two specified points. ( save continue) ( save n); save factorial procedure Figure 5.17: Compilation of the definition of the primitive procedure objects, so long as apply can identify and apply them by using the order of events where balance starts at 100, Peter withdraws 10, Paul withdraws 25, and yet the final value of balance. The entries at ev- application or ev- begin ev- definition- 1)) after- gcd- 2 Figure 5.10: Assigning labels to the continue register, since each level'' of the polynomials can be integers, rational numbers, complex numbers are implemented in terms of n for the total number of leaves of a tree branch- dest breakpoint broken heart bug capturing a free variable car ( primitive procedure) apply- dispatch ( test ( op definition?) ( reg ( reg proc)) ( goto ( label read- eval- print- loop)) ( else ( actual- value rather than eval: ( define ( add- streams ( scale- list integrand dt) int))) The interpreter's ability to deal with both of these can be used as a preparation for work in artificial intelligence. When we consider processes that operate on this representation.\""
       ]
      },
-     "execution_count": 47,
+     "execution_count": 42,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "' '.join(sentence_join(markov_sentence(sicp_counts, sicp_starts, 500)) for _ in range(10))"
+    "' '.join(sentence_join(markov_item(sicp_starts, sicp_counts, 500)) for _ in range(10))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 48,
+   "execution_count": 43,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "\"19: 25 But thou, O God: for they commit lewdness. 16: 15 And forgetteth that the foot may crush them, or that is in thee by the walls and in the feast of unleavened bread, until the selfsame day. 28: 23 But I will take away out of all his troubles. 4: 5 And they shall answer and say unto him, Is not this the fast that I have been with you at all seasons: the hard causes they brought unto him all the elders of the land of Egypt saying, 12: 11 Now when Job's three friends heard of all that therein is, in my realm, which are come to the place which the man of God, the God of Israel, which they could not so much as to eat. 5: 28 The LORD shall preserve thy going out; and it was shut. 43: 4 And the king of the nations: for I will stretch out my hand, and be rejected of the elders: from whom also I speak freely: for I have loved strangers, and after his going forth is prepared as the morning, that they come up out of Egypt, even they also turned to be their governor in the land of thy acts and of thy wisdom was not told me: thy hair is as a troubled fountain, and she conceived, and bare Jacob the fifth son. 22: 38 And Elisha came again to him, and upon the great toe of their right feet: and Deborah went up with ten thousand men of Judah; We have a little sister, and her days shall not be forgiven. 13: 2 And it shall come to pass, when the people removed from their tents, and said unto him that is near of kin unto us, he would raise up Christ to sit on the throne; yea, they have trodden my portion under foot, whose land the rivers have spoiled, to the right hand of the king. 40: 34 Then said they unto him an accusation against him. 14: 1 The priests the Levites, unto Ezra the priest brought the law before the congregation for judgment, but there was no bread there but the shewbread, which was the son of Meshullam, the son of Hinnom, and burnt it with fire, and destroyed down to the pit.\""
+       "'8: 16 ( For six months did Joab remain there with all Israel, and he shall serve: I have not shewed them. 25: 34 But when the blade was sprung up, it withered away, because they were accursed: neither will I tempt the LORD. 16: 44 Behold, he breaketh down, and the land of thy kindred that is called a brother be a fornicator, or covetous, or an Hebrew woman, be sold unto your enemies for bondmen and bondwomen unto you: ye shall pass before your brethren the children of Israel took Amaziah king of Judah went up to eat and drink before him; and he gave him to wife Asenath the daughter of Saul, that Saul put the people in whose heart are the ways of my people: and he took her, and yet couldest not be satisfied; and thy raiment was of fine gold, amounting to six hundred talents. 32: 6 And Israel said unto him, I know thee by name, hath lifted up his eyes, and when he saw that, behold, I have put off my sackcloth, and girded himself. 28: 9 But the wise took oil in their vessels with their lamps, and took counsel how they might destroy him. And Tobiah sent letters to put me into the dust of your city, which were come again out of the camp, all Israel have transgressed thy law, nor hearkened unto me, even he lifted up his eyes, and look not back: bring my sons from far, their silver and their gold shall be able to redeem it, then it shall be given unto you. 37: 3 Trust in the LORD, that obeyeth the voice of singing men and singing women. 19: 10 Delight is not seemly for a fool: much less do lying lips a prince. 36: 18 Because of the multitude of thy strangers shall be like small dust, and made him look up: and it came to pass the selfsame day the hand of the LORD, that hate thee. 13: 58 And they called for Samson out of the midst of us, and shall rain it upon him while he is near: 55: 11 So that the face of his brother whom he slew at one time.'"
       ]
      },
-     "execution_count": 48,
+     "execution_count": 43,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "' '.join(sentence_join(markov_sentence(kjb_counts, kjb_starts, 500)) for _ in range(10))"
+    "' '.join(sentence_join(markov_item(kjb_starts, kjb_counts, 500)) for _ in range(10))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 50,
+   "execution_count": 44,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "'6: 30 And the children of Israel, and the garlick: 11: 11 And Balak said unto Balaam, Go with the men, whom I have not spoken of me the thing that I hate, saith the LORD. 14: 27 And Joshua made them that day, saith the LORD; If ye will not fall upon me yourselves. 7: 2 Thou hast given a banner to them that believe: 2: 37 And at the end of the mountain that lieth before the valley of vision, breaking down the walls of the houses withal: 29: 37 Their meat offering and their drink offerings, and offer an offering made by fire unto the LORD. Then the master of his mercy; 1: 36 And Bethnimrah, and Succoth, and encamped at Hazeroth. If the queue was initially empty, we set the front and rear pointers of the queue in the first month in the second chariot that he had built, 10: 32 Benjamin, Malluch, and Adaiah, 10: 6 In burnt offerings and sacrifices, and with him an hundred and thirty. An extreme case of inefficiency occurs when the system falls into infinite loops in making deductions. 18: 12 And when the days of Cainan were nine hundred sixty and two years, and begat Methuselah: 5: 11 And Manoah arose, and rebuked them, because of the words which the horn spake: I sought him, but feared the people, He is my shepherd, and the Levites shall keep the watch of the LORD, and we will give ourselves continually to prayer, a certain blind man sat by the way. 34: 20 In a moment, and be still. One thing that makes the query language provides means of combination is crucial to the ability to represent compound data. 4: 15 That which is far off shall die of the pestilence.'"
+       "\"7: 3 And when I rose in the morning as he returned into the host, and went forth before them all, saying, Behold, I have brought him forth abroad, and said, Thy servant Uriah the Hittite: thirty and seven thousand. 135: 8 Who also declared unto us your love in the truth; It is expedient for you, that ye should be guilty. 68: 10 Thy cheeks are comely with rows of jewels, thy neck with chains of gold. 2: 25 And he set up the horn. 19: 14 My kinsfolk have failed, and my people love to have it return 0. 5: 14 And when Eli heard the noise of the taking of Babylon the earth is earthly, and speaketh uprightly; he that toucheth the land, concerning the vessels that remain in this city, and had beaten the graven images into powder, and strawed it upon the altar: these are the kings of Israel ? 16: 10 And I took the little book. 17: 8 Upright men shall be made smooth; 3: 2 And the Lord make you to increase and abound in love one toward another; men with men working that which is sold shall remain in the day when I drink it new with you in weakness, and in all thy coast seven days; and also after that, when they spake unto them, Hearken unto the voice of mirth, and the seats of them that boil, where the body of Christ; that we may put them to shame that hated us. 2: 2 Then said the LORD, and of brass, and carried the people away into Babylon unto Christ are fourteen generations; and thou shalt live. 27: 13 Why dost thou strive against him ? or if thy transgressions be multiplied, and all the curses that are written in the king's dale: for he hath been worth a double hired servant to thee, and thy silver and thy gold is mine; and she shall turn to you again. 18: 43 And the LORD spake unto Moses, saying, Have thou nothing to do with thee, saith the Lord GOD.\""
       ]
      },
-     "execution_count": 50,
+     "execution_count": 44,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "' '.join(sentence_join(markov_sentence(all_counts, all_starts, 500)) for _ in range(10))"
+    "' '.join(sentence_join(markov_item(all_starts, all_counts, 500)) for _ in range(10))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 63,
+   "execution_count": 45,
    "metadata": {
     "collapsed": false
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 65,
+   "execution_count": 46,
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "['32 The stranger that is, that hath taken a new clause to the unit square ( imag- part, and our Saviour.',\n",
-       " '112: 2 And, behold, immediately he arose, and cast them to pass at that level, which loveth thee and thy word is gone a little sister, to bring them unto the sea, they reach even to him, with the whole land shall be the Son of man are before the LORD pondereth the hearts of the first and the latter days.',\n",
-       " '10: 38 Joel the chief man of God, as much as any of the wood offering, with his fathers: also they were ashamed: let not the light of the Greeks seek after my name, and said unto him that doeth righteousness at all redeem ought of the LORD appointed other seventy also, as at other times, and Mearah that is spent in our streets: and in Benjamin fenced cities, and to all that he will preserve him, and couple the curtains of goats that were numbered of them that sleep sleep in the house of Jeroboam the son of Mattaniah: for ye shall be shortened.',\n",
-       " '( This argument is the spirit of his nostrils, and turn again by the heel in the place where concurrency control, and he that reapeth may rejoice.',\n",
-       " '6: 7 That ye may be of the truth.',\n",
-       " '6: 10 And thou shalt see it.',\n",
-       " \"9: 25 And it shall come and sing praise to thee with ? x set) false))))) Without- interrupts disables time- shared operating systems, especially they who are ye in me is true,'' for example, if thou warn the righteous smite me; 26: 10 Declaring the end.\",\n",
-       " '7: 22 But he rebelled against thee, yet make thee to anger, and Jeremoth, and the men of Babylon.',\n",
-       " '( define ( cube x)))) ( parallel- execute is a great multitude from Galilee, into the ark of the dust of the desire of our attitudes about programming and, behold, they brought out the mote out of thy land shall fall therein: and the compiler.',\n",
-       " 'And Peter remembered the days when God overthrew Sodom and her towns and country round about upon the horns, and openeth their ears are open, and to the user, provide a rigorous mathematical definition of the boards of fir.',\n",
-       " '5.4.',\n",
-       " 'For example, we set the battle increased that trouble me ! for my comfort in these cases are recognized by the space is ( define ( append- instruction- sequence, we will use a distinct bignum data type enables the system should be bound in chains among all the days that have not walked in the faith, I will surely shew myself unto prayer.',\n",
-       " '1: 15 And thou shalt require of the testimony in Jacob his people made no lamentation.',\n",
-       " '12: 37 Then he questioned with him.',\n",
-       " 'The procedure that takes as input a pattern such as had not obtained that which is at hand, that David had a servant to wife.',\n",
-       " '2: 11 Now this I say unto thee; and they that were diseased.',\n",
-       " 'There are many ways in the matter, they withered away from him, sing praises unto God from the tower, and birds of the terms of more and more abundantly unto you, he hath given unto thee: and they shall offer the gift, with the beasts of the same car.',\n",
-       " 'You must implement the generic procedure so that they name, and go up, and take up his pillars.',\n",
-       " \"We will have to change ( or ( recursively) during analysis is a faithful man who was yet shut up him that shaketh it ? 30: 15 The way of the LORD's passover.\",\n",
-       " 'Amen, and combine the two horns were high; that thou hast heard, Satan: thou hast redeemed.',\n",
-       " \"The community's broader work goes beyond issues of objects that can skill to hew in the gate of Issachar according to all that they may shave their heads, neither have seen strange things to write coercion procedures that manipulate the shared account.\",\n",
-       " \"25: 1: 36 My desire is, and Lot his brother's name was Tamar: she is thy love to have done evil in his disease he sought how he loved the people and the Amalekites had carried it into the sea side: and they shall be as frontlets between thine eyes behold, the joy wherewith we joy for your goodness is as the shadow of death stain it; because he had said unto her mistress, and they of Tyre and Sidon, which uses the last; I will restore it to a given application problem; the family of the whole congregation of the armies of Israel, and shod them, having faithful children not accused of riot, speaking of the lad where he entereth in by the young men now arise, if we call make- new- machine procedure, we hurt them, and his dwelling place of rest, but shall surely pay ox for a fool: much more diligent, upon these tables the words which I also was accounted to him, and much people, and upon the persons were four leprous men at his birth.\",\n",
-       " '32: 3 She crieth in the gate from the power of the sea shall be unclean.',\n",
-       " '2: 13 To keep the commandments of the wicked he turneth upside down shall be set in my sanctuary ? but thou shalt make two rings in the wine, which is called the Italian band, when ye go to Dothan.',\n",
-       " '21: 8 Therefore thus saith the LORD our God in heaven.',\n",
-       " 'The empty set is being paid more than lovers of God; every one over against him.',\n",
-       " 'And the sons of Bilhah.',\n",
-       " '34: 22 Saying, Give us this great fire any more at all times: unless she had seen.',\n",
-       " '1: 7 Ain, Remmon, and Lot the son of Pashur, a flame: there shall be strong.',\n",
-       " '32: 10 Yea, all the leaves of a combination, and Meshullam.']"
+       "['Typical memory systems provide a driver loop.',\n",
+       " '2: 10 Which doeth great wonders, ye were sealed twelve thousand.',\n",
+       " \"59: 13 ( 3 4)) ( fib n) ( newline)) We must evaluate (* x y) (/ (+ x 4))) x) ( let (( avpt (/ (+ ( sum term a) ( registers- needed seq1)) ( branch ( label ev- sequence '( proc argl continue)); linkage code machine- model > < value>. Thus, she came trembling, he that ruled throughout the seven seals thereof: it shall be forty and five hundred and ten thousand in breadth.\",\n",
+       " '9: 22 And the chief captain that he shall do my prophets no harm: 35 And the firstborn, Jehush the second time the LORD: that I visit them, If thou cast down, even since the assembler to store the current value of the sword, and to which denominators.',\n",
+       " 'And he blessed Joseph, saying, They hated me, Son of man: preserve my life, or a product of the mountain which is escaped ? And the children of Israel went thither a whoring after their tongues, in the dispatch as in a 1954 paper that essentially founded the earth are burned without inhabitant, and it was not, to find the value of a combination operation cross- type information.',\n",
+       " '35: 14 And that first covenant had also seen the Father hath loved us, and mourn; 61: 8 But there is neither bond nor free: for that the brook Kidron.',\n",
+       " '22: 18 But he that confirmeth not all of them in the procedure object followed by code to check whether the car pointer of the winepress shall not do any thing as of the congregation of the king had heard that it is symmetrical-- variables are transformed in this case, we will shew who are under the shadow of thy body, yet shall know that the LORD.',\n",
+       " '1: 16 Wash you, an he lamb without blemish: 29 Then fled Moses at this: primitive expressions such as C.',\n",
+       " '22: 4: 6 Then shall he appear the sign of a man to his sons that shall vex thee, O Judah, in which my people, that Pharaoh should have sorrow from them that did cleave unto the LORD shall renew their strength, O Media; all that pertained to Saul ? choose you, having never learned ? 7: 1 And the remnant of the fire shall ever be removed, and exhort.',\n",
+       " '12: 42 For I was an angel come down from the lions ? The most common way to do unto the king said unto the king of Shimron, and slew them at all times, to identify all the army of the house, and cause the horn of oil, saith the LORD said unto him, Nay; but the LORD followed them.',\n",
+       " '6: 2 And he said unto them; and it was told is true, then that we have students use the second seal, I have decked my bed I sought him, Is Saul also went his way, and the transgression of an hundred talents of gold, and in the way he sees it.',\n",
+       " 'C.',\n",
+       " '11: 11 If ye have gathered the wind ceased: and David his father: and it was hid three months in Jerusalem.',\n",
+       " 'Next, the same with a great forsaking in the world with time.',\n",
+       " '13: 10 Yet was she slain.',\n",
+       " '18: 30 And Mephibosheth had a long blast with the trumpets, and cast them down into Egypt.',\n",
+       " 'Thus make- queue, a third type.',\n",
+       " '( Compare the two patterns (? x c ? x should be apparent that the primitive elements of its arguments, the selectors they call their lands; every one for his mouth, and the candlestick, and filled them with the voice of Israel, to him, and how he had delight in lies: they shall light the hidden wisdom, nor did him honour at his words: and the nail, and on the eighth day; and there be laid in the six hundred men; leave us not love in the face of the Lord, behold, men of Israel; and he shall eat the fruit of the fat of rams, of the air; the family of the prophets, that we have not profited them that they might not lift up thine eyes be open, and teachest him out of thy counsels of the blood upon him.',\n",
+       " '3: 33 They give drink to every good work.',\n",
+       " '14: 8 For he that is an everlasting covenant, whom God hath remembered her iniquities.',\n",
+       " '46: 2 When I brake the bands of their sacrifices, which brought thee out of the nations be blessed.',\n",
+       " '4: 10 Arise ye, when thou thyself art a God of Abraham, I was an hundred forty and five.',\n",
+       " '2: 17 And David said, How many hired servants of Saul the son of Israel eat not any that were virgins apparelled.',\n",
+       " '8: 15 Every raven after his servant with the edge of the altar round about Gibeah.',\n",
+       " '32: 31 Behold, thou hast made void the counsel of peace, without changing the thunk once the longsuffering of our God.',\n",
+       " '2: 21 Have pity upon the earth; and he had commanded him, saying, So is he which baptizeth with the notion of a variable, we will change make- instruction- sequences is thus the empty frame, [ 2 ] message- passing techniques developed in conjunction with higher- order evaluation applicative order as a branch, and begat sons and their inheritance be given to thy fathers hath given me knowledge of him.',\n",
+       " '8: 10 And Judah saw his sons.',\n",
+       " 'Proof of correctness of the priests praised the LORD.',\n",
+       " '71: 19 I know thy works.',\n",
+       " '12: 44 And Shema begat Raham, the son of Josedech, the dart, nor make any manner of sickness and all the people that they should believe on him, Let her alone: if so be that they were come from the face of the nations of the going up to the Huffman tree of figure 5.12 and examine the state of that value leads to the LORD for evermore, and in the midst of Israel numbered, and ointments, and twelve oxen, that they should be the Son, go forth as a tree non- strict nondeterminism, we can tell whether the bindings in the evaluator machine, and followed the LORD sent an angel standing in the house of feasting and joy; he hath taken increase: but I obtained mercy; that they without us: for thou art good in the midst of the expression ( and ( not (= ( remainder ( square x) Figure 3.12: Lists x: (( a b) ( first- class elements in language design who were fifty and six.']"
       ]
      },
-     "execution_count": 65,
+     "execution_count": 46,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "[sentence_join(markov_sentence(all2_counts, all2_starts, 500)) for _ in range(30)]"
+    "[sentence_join(markov_item(all2_starts, all2_counts, 500)) for _ in range(30)]"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 66,
+   "execution_count": 47,
    "metadata": {
     "collapsed": false
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 70,
+   "execution_count": 48,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/plain": [
-       "\"To make a new procedure object W1. Now, if you fail to imagine an alien evolution had led him. We also have to steer better with four interface procedures to enforce the condition is called forcing. In Proceedings of the window I did not, they wished; so that the great sweep, half- bent on its own opposite. There he worked like beavers over Lake's two best planes, fitting them again it was very blurred, and very handsome save for his family. By incorporating a limited number of arrests, the brightness and affability which promised respite from our emotions, and aerial, aeroplane parts, an' crinkly albino hair, pale blue eyes, impotently trying to tell is more ancient than the ordered union- set pairs))) Make- withdraw. Out of the same hallucination. I had wander'd in rapture beneath them; and there was only a lone coyote on the side turned away from both men sat still and attempt to divide both the Esquimaux wizards and the weirdness of the sort used in Mesopotamia, being wakeful, and could not sleep well that sucks your life and sensation- the hellish whine of the vault I kept deathly quiet, and when I told them the back of the Eighteenth Century, with full daemoniac fury upon the dark stairs. ( You should find that much of the same constraint that the whole way to the westward precipice beside him was a baronet before his arrival. 1 Representations for Complex Numbers We will augment the factorial machine shown in figure 5.14) of section 5.2 we use apply- dispatch, and seemed to notice this ripple until reminded by later events; but I can scarcely describe the strangeness was not sorry for him did not believe he was so rapidly overtaking it in an infinite continued fraction expansion for e x is unbound.\""
+       "'But on the moon shone down cold through the unseen tumbler meant a danger not to be increasing in vividness and darkened with dread of opening it or descend the wide appearance of this treatment of not and lisp- value rather than practical examples in this decrepit edifice. There were gods and the receiver, and shuddered. Bothersome forms, and the hellish image; but it is worth correcting. Three coffin- shaped man with Oriental eyes has said that Aspinwall had died of it. With the extra lens I could not have written the following procedures. The telepathic messages had not yet sufficiently trained to do with queer oils as Marceline had always done. The inlaid doors and the pc: ( define ( analyze- quoted exp) ( let (( x 3- 10 I have ever shared. Example: Arithmetic Operations The task seemed known to me in this farther void of fear and triumph seemed to evoke. Only after such a loathsome cost, and the awful concept of a branch instruction at the ends of the equator had been there and engulfed all the efforts of sturdy Colonial tenants and dewy rose- wreathed world of somnolent cerebration. Sir Wade would speak of our physical creation.'"
       ]
      },
-     "execution_count": 70,
+     "execution_count": 48,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "\" \".join(sentence_join(markov_sentence(sl2_counts, sl2_starts, 500)) for _ in range(10))"
+    "\" \".join(sentence_join(markov_item(sl2_starts, sl2_counts, 500)) for _ in range(10))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 75,
+   "execution_count": 49,
    "metadata": {
     "collapsed": false
    },
     {
      "data": {
       "text/html": [
-       "<p>Mrs. Now she heard voices in other universes and other myths, they raised and the senior Ward, however, were soon unbuttoning our heavy flying furs. 4 Exponentiation Consider the following August his labours. The face was a dream- world discovery in press. Each time we called a program for simulating diffusion ( say N / k calls to protected are done; though once in a begin.) The evaluator can check to see a pale lemon- yellow while his singular results. I had carried off. Reflecting upon these pictures can revive. There was a hideous uncertainty came over and over must you land amongst them with hot brooding gaze and evil. Dee was never regarded by the known habits of childish rebelliousness being exchanged for other needs of the steel- rimmed pince- nez and pointed stiffly to a cloud of probable East- Indian or Indochinese provenance, though I could tell; yet it is too tremendous for any to picture or encompass. Aroused at last to see the old Asian castles clinging to him on his study, a rational number can automatically be applied to frames in parallel and merging with the unbeautiful things of earth's convulsions, this is embedded.</h1>"
+       "<p>\" I buried myself in a fearful daze out into the grounds, and especially down cellar, and from what I went with them gold- green stone idol found. We had all been rather jovial, and a general alarm. We will also modify the environment as context for evaluation of the creatures to invade a lethal stupor which wards off madness by dulling the memory of those books wish a word or a 1) (* x (+ x 2))) produces the average citizen. The names of Akeley and play, and produces a painter; therefore, is called. There are, which one might spy through the remaining stretch of road, and as she had said in a scientific purpose, so that its cdr is the empty stream or a labyrinth of inexplicably fashioned metal under a certain transcribed witch- woman- her name in life imagined, the sleeping plain. To form even a sign of man's world and perhaps sinister history, philosophy, and was placed on exhibition early in the water change- detector sense- data and primitive mammals, and the like. His walks were late ( as that of the forbidden ? The rifling of Ezra Weeden, who had come to recognize the will and buried to the open sea some were incised and wholly at the hospital. Trying the match is basically the same way as for the tomb of man and his hints occasionally became concrete. Curwen's sailors would then pose as a free hand and radiating out in the neighbourhood noted. He had known Al always, were freely spoken of as two separate problems: what'' to a tremendous effect on me, and even the myriad towering stories had fallen through, revealing a wide range.</h1>"
       ],
       "text/plain": [
        "<IPython.core.display.HTML object>"
     }
    ],
    "source": [
-    "from IPython.core.display import display, HTML\n",
     "display(HTML('<p>' + \n",
-    "             \" \".join(sentence_join(markov_sentence(sl2_counts, sl2_starts, 500)) for _ in range(10)) + \n",
+    "             \" \".join(sentence_join(markov_item(sl2_starts, sl2_counts, 500)) for _ in range(10)) + \n",
     "             '</h1>'))"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": 57,
+   "metadata": {
+    "collapsed": false,
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(8177, 249224)"
+      ]
+     },
+     "execution_count": 57,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sum(sicp_starts.values()), sum(sum(c.values()) for c in sicp_counts.values())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 58,
+   "metadata": {
+    "collapsed": false,
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(26374, 958228)"
+      ]
+     },
+     "execution_count": 58,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sum(kjb_starts.values()), sum(sum(c.values()) for c in kjb_counts.values())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 91,
+   "metadata": {
+    "collapsed": false,
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(24560, 683961)"
+      ]
+     },
+     "execution_count": 91,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "lovecraft = unaccent(open('lovecraft-trimmed.txt').read())\n",
+    "lovecraft_starts, lovecraft_counts = find_counts(sentences(tokenise(lovecraft)), tuple_size=2)\n",
+    "sum(lovecraft_starts.values()), sum(sum(c.values()) for c in lovecraft_counts.values())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 92,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "3.225388284211814"
+      ]
+     },
+     "execution_count": 92,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sum(kjb_starts.values()) / sum(sicp_starts.values())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 93,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "3.8448464032356435"
+      ]
+     },
+     "execution_count": 93,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sum(sum(c.values()) for c in kjb_counts.values()) / sum(sum(c.values()) for c in sicp_counts.values())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 94,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(3.0035465329582975, 2.7443625012037365)"
+      ]
+     },
+     "execution_count": 94,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sum(lovecraft_starts.values()) / sum(sicp_starts.values()), \\\n",
+    "sum(sum(c.values()) for c in lovecraft_counts.values()) / sum(sum(c.values()) for c in sicp_counts.values())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 95,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def scale_merge(left_starts, left_start_scale, left_counts, left_count_scale, \n",
+    "                right_starts, right_start_scale, right_counts, right_count_scale):\n",
+    "    starts = collections.Counter()\n",
+    "    counts = collections.defaultdict(collections.Counter)\n",
+    "    \n",
+    "    for k, n in left_starts.items():\n",
+    "        starts[k] = n * left_start_scale\n",
+    "    for k, n in right_starts.items():\n",
+    "        starts[k] += n * right_start_scale\n",
+    "    \n",
+    "    for k in left_counts:\n",
+    "        for j in left_counts[k]:\n",
+    "            counts[k][j] = left_counts[k][j] * left_count_scale\n",
+    "            \n",
+    "    for k in right_counts:\n",
+    "        for j in right_counts[k]:\n",
+    "            counts[k][j] = right_counts[k][j] * right_count_scale\n",
+    "\n",
+    "    return starts, counts"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 96,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "sk_starts, sk_counts = scale_merge(sicp_starts, 3, sicp_counts, 4, kjb_starts, 1, kjb_counts, 1)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 97,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "<p>The voltage response v of the circuit ( summarized by v C, the Lisp evaluator would be to process the query ( and ( supervisor ? x ? middle- manager in the wheel rule of section 4.4.</p><p>3: 11 Therefore thy gates shall be burned therein.</p><p>36: 3 And say to the forest of the south shall be strong, and eat bread.</p><p>The servants said unto him, My LORD, if thou go with us; and he gave him, and saith unto them, ready to depart on the morrow, which was set over the affairs of this life, and out of the hand that wrote.</p><p>5: 6 And the sword shall abide on his cities, and with an extreme burning, and the vintage shall reach unto Azal: yea, though many false witnesses came, yet found they none.</p><p>He adds all the weekly meetings of the firm to the Microshaft data base by expressions of the query system repeatedly reads input expressions.</p><p>Specifically: The evaluator enables us to increase the modularity of our systems by encapsulating, or hiding,'' parts of the earth, that the LORD cast out before the LORD, as the LORD commanded to give unto her the cup of the Lord Jesus Christ, was in number three hundred thousand choice men, able to deliver you from his iniquities.</p><p>Cy agrees that Ben is right about the behavior of a quantity x as a function of n, to be applied in the same way as in the night visions, and your goodliest young men, and they slew all the males from a month old and upward, from the east side unto the west side, a portion for Asher.</p><p>13: 1 And the LORD said, Bring the portion which I gave thee, of the children of Israel before their idols, and all that is in use, existing programs that define procedures with these names bound as local variables.</p><p>For example, the complex number z = x + iy ( where i 2 =- 1) can be expressed as sequence operations.</p>"
+      ],
+      "text/plain": [
+       "<IPython.core.display.HTML object>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "display(HTML(cat('<p>' + sentence_join(markov_item(sk_starts, sk_counts, 500)) + '</p>' for _ in range(10))))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 98,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "sl_starts, sl_counts = scale_merge(sicp_starts, 3, sicp_counts, 2, lovecraft_starts, 1, lovecraft_counts, 1)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 99,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "<p>Akeley had been a nightmare of buzzing voices, and a partial relief from the second signal ordering a general plan was to see him.</p><p>From the handwriting ? Do you wonder how many farmhouses burnt to ashes.</p><p>1 that the interpreter runs, it follows a process that must be made to a system in which complex numbers are naturally represented as ordered pairs.</p><p>Then the GCD is the other argument for * ( assign proc ( op ( opcompiled- procedure- entry) ( let (( segments ( segments agenda) ( cdr z)) ( append (( save, first- reg) ( modifies- register ? modularity, [ 2 ] unify- match query- pattern frame) ( let (( t1 -> t2 ( apply- generic op ( t1 -> t2 ( get- register- contents < machine- model > < register- name > ( op vector- set!) ( reg new- cdrs) ( reg env));; begin actual procedure body ( save continue) ( goto ( reg val)) Now we can try our rational- number operations in terms of abstract selectors and constructors for this notation such that our derivative program still works ? 2.3.</p><p>And yet it was, or that those horrible cylinders and machines- and the desolate salt marshes, desolate and unpeopled, chaos was complete long before I die I should be as it shines on certain others- even a perfect solution, because of a long and familiar doom.</p><p>He defines the following two rules: For any list y, the empty list, then the smaller number in the sequence.</p><p>Of all its curious influence call up the sixty- three at the cryptic parchment; but upon examining the bank as if to accentuate by their fellow- men.</p><p>When he read this, but kept it in the hideous culmination of events that depopulated the whole scene of such data as my torch could not doubt the power of its unfamiliar temporary form, was of little quaint fishing towns that climbed from the Rowley road drew so close to the fourth floor, and likewise any metal case- resulted in a vast Italian quarter, and a feeling that some of our camel drivers older than Memphis and mankind.</p><p>\" Ye see all too close to the sight.</p><p>In the roseal dawn the burghers of Milwaukee rose to panic.</p>"
+      ],
+      "text/plain": [
+       "<IPython.core.display.HTML object>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "display(HTML(cat('<p>' + sentence_join(markov_item(sl_starts, sl_counts, 500)) + '</p>' for _ in range(10))))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 100,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "lk_starts, lk_counts = scale_merge(lovecraft_starts, 1, lovecraft_counts, 1, kjb_starts, 1, kjb_counts, 1)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 101,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "<p>I say harass, because they have when they tore open the massive pre- Revolutionary homes with their nails, so I think almost hope that no man has yet dared not seem to have the ether- resisting wings characteristic of him, and many things.</p><p>2: 31 And he said unto him, Caesar's.</p><p>33: 9 Nevertheless the priests of the high places of Baal, which are called might receive the fruits of your ground; neither shall thy tears run down like a river, and every tree therein: for then should ye go after vain things, which thou hast redeemed.</p><p>He could scarcely decipher what they portrayed, and almost ghastly results, since it could be done.</p><p>27: 12 These shall stand upon the mount of Olives, then sent Jesus two disciples, 21: 6 And Ezra blessed the LORD God, even the porch of the house of the LORD was with Jehoshaphat, because he had heard therefore that he was Rebekah's son: and I will remove far off from my presence: 23: 11 And they found written in the law.</p><p>Was he just come up.</p><p>Lanterns that shudder and death are penned.</p><p>But this was a cross of new developments in those fields where the west window, and with haste To get this impetus, though to my flagging quest; for thousands and tens of thousands of light which would warn the waiting horse gave a thrill that a small man probably having a kind of a chaotic pronunciation.</p><p>Beneath him dozens of queer things I had not traversed before; and though progress was very close indeed.</p><p>52: 23 And they were exceeding many: neither was the word of the LORD came again unto Jerusalem and Judah, Hanani, Eliathah, Giddalti, and Romamtiezer, Joshbekashah, Mallothi, Hothir, and Mahazioth: 25: 27 Over against the border were at the north bay of the salt sea: this shall not be ashamed of Chemosh, as the manner of all the tribes of the children of Ammon said to Hanun, Thinkest thou that David doth honour thy father, that he may die: because she hath not sinned.</p>"
+      ],
+      "text/plain": [
+       "<IPython.core.display.HTML object>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "display(HTML(cat('<p>' + sentence_join(markov_item(lk_starts, lk_counts, 500)) + '</p>' for _ in range(10))))"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,