Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calroc/7076411 to your computer and use it in GitHub Desktop.
Save calroc/7076411 to your computer and use it in GitHub Desktop.
Solving Logic Puzzles with the Laws of Form Notation
{
"metadata": {
"name": "Solving Logic Puzzles with the Laws of Form Notation"
},
"name": "Solving Logic Puzzles with the Laws of Form Notation",
"nbformat": 2,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"source": "# Solving Logic Puzzles with the Laws of Form Notation"
},
{
"cell_type": "markdown",
"source": "We can use the following functions to build up forms that represent\nelectronic circuits and logical statements:"
},
{
"cell_type": "code",
"collapsed": true,
"input": "nor = lambda *bits: bits\nor_ = lambda *bits: nor(bits)\nand_ = lambda *bits: tuple(nor(bit) for bit in bits)\nnand = lambda *bits: nor(and_(*bits))\neqiv = lambda *bits: (bits, and_(*bits))\nxor = lambda *bits: nor(eqiv(*bits))",
"language": "python",
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"source": "An expression composed of tuples and strings, which serve as logical symbols or variables, can be transformed into a standard form."
},
{
"cell_type": "code",
"collapsed": true,
"input": "def reify(meaning, form):\n if isinstance(form, basestring):\n return meaning.get(form, form)\n return tuple(reify(meaning, inner) for inner in form)",
"language": "python",
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": true,
"input": "def standard_form(x, form):\n Ex = reify({x: ((),)}, form)\n E_x_ = reify({x: ()}, form)\n return (x, Ex), ((x,), E_x_)",
"language": "python",
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"source": "It is also helpful to be able to simply forms. We can use functions like these to reduce forms according to the Bricken basis."
},
{
"cell_type": "code",
"collapsed": true,
"input": "def unwrap(form):\n '''\n Remove all (()) and let ((*)) -> * in a form. Generator.\n '''\n for term in form:\n if term == ((),):\n continue\n if isinstance(term, tuple) and len(term) == 1 and isinstance(term[0], tuple):\n # Flatten out one \"layer\" of \"wrapping\".\n for item in term[0]:\n yield item\n continue\n yield term",
"language": "python",
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": true,
"input": "_A = lambda form: form if isinstance(form, basestring) else tuple(unwrap(form))\n_B = lambda form: form if isinstance(form, basestring) else ((),) if () in form else form",
"language": "python",
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": true,
"input": "def Reduce(form):\n if isinstance(form, basestring):\n return form\n if len(form) == 1 and isinstance(form[0], tuple) and len(form[0]) == 1:\n return Reduce(form[0][0])\n return tuple(_A(_B(tuple(map(Reduce, form)))))",
"language": "python",
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"source": "This is a helper function to find all the symbols in a form."
},
{
"cell_type": "code",
"collapsed": true,
"input": "def collect_names(form, names=None):\n if names is None:\n names = set()\n if isinstance(form, basestring):\n names.add(form)\n else:\n for inner in form:\n collect_names(inner, names)\n return names",
"language": "python",
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "markdown",
"source": "This is a helper function to generate a nice string representation of a form."
},
{
"cell_type": "code",
"collapsed": true,
"input": "to_string = lambda term: (str(term)\n .replace(' ', '')\n .replace(\"','\", ' ')\n .replace(\"'\", '')\n .replace(',', '')\n .replace('(())', '\u25ce')\n .replace('()', '\u25cb')\n )",
"language": "python",
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "markdown",
"source": "This function applies the standard_form() function to a form for each of the names in the form. It also prints out the result at each stage for our edification."
},
{
"cell_type": "code",
"collapsed": true,
"input": "def fstan(form):\n for name in sorted(collect_names(form)):\n form = Reduce(standard_form(name, form))\n print name, to_string(form) ; print\n return form",
"language": "python",
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "markdown",
"source": "Now we can solve a logic puzzle. The following is based on George Burnett-Stuart's [Exposition on Lewis Carroll's Five Liar Problem](http://markability.net/five_liars.htm), which in turn\nis based on [William Bricken's article](http://iconicmath.com/mypdfs/bl-fiveliars.090625.pdf). In this case the process of mechanically computing the full standard form of the puzzle\nis sufficient to discover the two solutions of the puzzle. I do not know under what circumstances this will always be true."
},
{
"cell_type": "code",
"collapsed": true,
"input": "a, b, c, d, e, f, g, h, i, j = 'abcdefghij'",
"language": "python",
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": true,
"input": "tale = {\n a: eqiv(xor(b, g), eqiv(d, i)), # same as xor(xor(b, g), xor(d, i)) etc...\n f: xor(nand(c, h), nand(e, j)),\n\n b: eqiv(xor(a, f), eqiv(c, h)),\n g: xor(nand(d, i), or_(e, j)),\n\n c: xor(or_(a, f), or_(d, i)),\n h: xor(xor(b, g), nand(e, j)),\n\n d: xor(nand(a, f), nand(e, j)),\n i: xor(nand(b, g), or_(c, h)),\n\n e: xor(or_(a, f), or_(b, g)),\n j: eqiv(xor(c, h), eqiv(d, i)),\n }",
"language": "python",
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": "E = or_(*(eqiv(name, expr) for name, expr in tale.iteritems()))\nprint to_string(E)",
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "((((a(((((b g)((b)(g))))((d i)((d)(i))))(((((b g)((b)(g)))))(((d i)((d)(i)))))))((a)((((((b g)((b)(g))))((d i)((d)(i))))(((((b g)((b)(g)))))(((d i)((d)(i)))))))))((c(((((a f))((d i)))((((a f)))(((d i)))))))((c)((((((a f))((d i)))((((a f)))(((d i)))))))))((b(((((a f)((a)(f))))((c h)((c)(h))))(((((a f)((a)(f)))))(((c h)((c)(h)))))))((b)((((((a f)((a)(f))))((c h)((c)(h))))(((((a f)((a)(f)))))(((c h)((c)(h)))))))))((e(((((a f))((b g)))((((a f)))(((b g)))))))((e)((((((a f))((b g)))((((a f)))(((b g)))))))))((d((((((a)(f)))(((e)(j))))(((((a)(f))))((((e)(j))))))))((d)(((((((a)(f)))(((e)(j))))(((((a)(f))))((((e)(j))))))))))((g((((((d)(i)))((e j)))(((((d)(i))))(((e j)))))))((g)(((((((d)(i)))((e j)))(((((d)(i))))(((e j)))))))))((f((((((c)(h)))(((e)(j))))(((((c)(h))))((((e)(j))))))))((f)(((((((c)(h)))(((e)(j))))(((((c)(h))))((((e)(j))))))))))((i((((((b)(g)))((c h)))(((((b)(g))))(((c h)))))))((i)(((((((b)(g)))((c h)))(((((b)(g))))(((c h)))))))))((h((((((b g)((b)(g))))(((e)(j))))(((((b g)((b)(g)))))((((e)(j))))))))((h)(((((((b g)((b)(g))))(((e)(j))))(((((b g)((b)(g)))))((((e)(j))))))))))((j(((((c h)((c)(h))))((d i)((d)(i))))(((((c h)((c)(h)))))(((d i)((d)(i)))))))((j)((((((c h)((c)(h))))((d i)((d)(i))))(((((c h)((c)(h)))))(((d i)((d)(i)))))))))))"
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": "print to_string(Reduce(E))",
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "((((a(((b g)((b)(g))((d i)((d)(i))))(((b g)((b)(g)))(d i)((d)(i)))))((a)((b g)((b)(g))((d i)((d)(i))))(((b g)((b)(g)))(d i)((d)(i)))))((c(a f d i)((a f)(d i)))((c)((a f d i)((a f)(d i)))))((b(((a f)((a)(f))((c h)((c)(h))))(((a f)((a)(f)))(c h)((c)(h)))))((b)((a f)((a)(f))((c h)((c)(h))))(((a f)((a)(f)))(c h)((c)(h)))))((e(a f b g)((a f)(b g)))((e)((a f b g)((a f)(b g)))))((d((a)(f)(e)(j))(((a)(f))((e)(j))))((d)(((a)(f)(e)(j))(((a)(f))((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i((b)(g)c h)(((b)(g))(c h)))((i)(((b)(g)c h)(((b)(g))(c h)))))((h((b g)((b)(g))(e)(j))(((b g)((b)(g)))((e)(j))))((h)(((b g)((b)(g))(e)(j))(((b g)((b)(g)))((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))))"
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": "Z = fstan(E)",
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "a ((a(((b g)((b)(g))((d i)((d)(i))))(((b g)((b)(g)))(d i)((d)(i))))((c(f d i)((f)(d i)))((c)((f d i)((f)(d i)))))((b(((f)((c h)((c)(h))))(f(c h)((c)(h)))))((b)((f)((c h)((c)(h))))(f(c h)((c)(h)))))((e(f b g)((f)(b g)))((e)((f b g)((f)(b g)))))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i((b)(g)c h)(((b)(g))(c h)))((i)(((b)(g)c h)(((b)(g))(c h)))))((h((b g)((b)(g))(e)(j))(((b g)((b)(g)))((e)(j))))((h)(((b g)((b)(g))(e)(j))(((b g)((b)(g)))((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i))))))((a)((b g)((b)(g))((d i)((d)(i))))(((b g)((b)(g)))(d i)((d)(i)))((c d i)((c)(d i)))((b((f((c h)((c)(h))))((f)(c h)((c)(h)))))((b)(f((c h)((c)(h))))((f)(c h)((c)(h)))))((e b g)((e)(b g)))((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i((b)(g)c h)(((b)(g))(c h)))((i)(((b)(g)c h)(((b)(g))(c h)))))((h((b g)((b)(g))(e)(j))(((b g)((b)(g)))((e)(j))))((h)(((b g)((b)(g))(e)(j))(((b g)((b)(g)))((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))))\n\nb ((b((a(((g)((d i)((d)(i))))(g(d i)((d)(i))))((c(f d i)((f)(d i)))((c)((f d i)((f)(d i)))))(((f)((c h)((c)(h))))(f(c h)((c)(h))))((e(f g)((f)(g)))((e)((f g)((f)(g)))))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i c h)((i)(c h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i))))))((a)((g)((d i)((d)(i))))(g(d i)((d)(i)))((c d i)((c)(d i)))((f((c h)((c)(h))))((f)(c h)((c)(h))))((e g)((e)(g)))((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i c h)((i)(c h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i))))))))((b)((a((g((d i)((d)(i))))((g)(d i)((d)(i))))((c(f d i)((f)(d i)))((c)((f d i)((f)(d i)))))((f)((c h)((c)(h))))(f(c h)((c)(h)))((e f)((e)(f)))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i((g)c h)(g(c h)))((i)(((g)c h)(g(c h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i))))))((a)(g((d i)((d)(i))))((g)(d i)((d)(i)))((c d i)((c)(d i)))(f((c h)((c)(h))))((f)(c h)((c)(h)))(e)((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((c)(h)(e)(j))(((c)(h))((e)(j))))((f)(((c)(h)(e)(j))(((c)(h))((e)(j))))))((i((g)c h)(g(c h)))((i)(((g)c h)(g(c h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))((j)((c h)((c)(h))((d i)((d)(i))))(((c h)((c)(h)))(d i)((d)(i)))))))))\n\nc ((c((b((a(((g)((d i)((d)(i))))(g(d i)((d)(i))))(f d i)((f)(d i))(((f)h)(f(h)))((e(f g)((f)(g)))((e)((f g)((f)(g)))))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f(e)(j))((f)((e)(j))))((i h)((i)(h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((h)((d i)((d)(i))))(h(d i)((d)(i)))))((j)((h)((d i)((d)(i))))(h(d i)((d)(i))))))((a)((g)((d i)((d)(i))))(g(d i)((d)(i)))d i((f h)((f)(h)))((e g)((e)(g)))((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f(e)(j))((f)((e)(j))))((i h)((i)(h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((h)((d i)((d)(i))))(h(d i)((d)(i)))))((j)((h)((d i)((d)(i))))(h(d i)((d)(i))))))))((b)((a((g((d i)((d)(i))))((g)(d i)((d)(i))))(f d i)((f)(d i))((f)h)(f(h))((e f)((e)(f)))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f(e)(j))((f)((e)(j))))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((h)((d i)((d)(i))))(h(d i)((d)(i)))))((j)((h)((d i)((d)(i))))(h(d i)((d)(i))))))((a)(g((d i)((d)(i))))((g)(d i)((d)(i)))d i(f h)((f)(h))(e)((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f(e)(j))((f)((e)(j))))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((h)((d i)((d)(i))))(h(d i)((d)(i)))))((j)((h)((d i)((d)(i))))(h(d i)((d)(i))))))))))((c)((b((a(((g)((d i)((d)(i))))(g(d i)((d)(i))))((f d i)((f)(d i)))(((f)(h))(f h))((e(f g)((f)(g)))((e)((f g)((f)(g)))))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))(i)((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j((h((d i)((d)(i))))((h)(d i)((d)(i)))))((j)(h((d i)((d)(i))))((h)(d i)((d)(i))))))((a)((g)((d i)((d)(i))))(g(d i)((d)(i)))(d i)((f(h))((f)h))((e g)((e)(g)))((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))(i)((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j((h((d i)((d)(i))))((h)(d i)((d)(i)))))((j)(h((d i)((d)(i))))((h)(d i)((d)(i))))))))((b)((a((g((d i)((d)(i))))((g)(d i)((d)(i))))((f d i)((f)(d i)))((f)(h))(f h)((e f)((e)(f)))((d(e)(j))((d)((e)(j))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))((i(g))((i)g))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j((h((d i)((d)(i))))((h)(d i)((d)(i)))))((j)(h((d i)((d)(i))))((h)(d i)((d)(i))))))((a)(g((d i)((d)(i))))((g)(d i)((d)(i)))(d i)(f(h))((f)h)(e)((d((f)(e)(j))(f((e)(j))))((d)(((f)(e)(j))(f((e)(j))))))((g((d)(i)e j)(((d)(i))(e j)))((g)(((d)(i)e j)(((d)(i))(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))((i(g))((i)g))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j((h((d i)((d)(i))))((h)(d i)((d)(i)))))((j)(h((d i)((d)(i))))((h)(d i)((d)(i)))))))))))\n\nd"
},
{
"output_type": "stream",
"stream": "stdout",
"text": " ((d((c((b((a(((g)i)(g(i)))(f i)((f)(i))(((f)h)(f(h)))((e(f g)((f)(g)))((e)((f g)((f)(g)))))(e)(j)((g e j)((g)(e j)))((f(e)(j))((f)((e)(j))))((i h)((i)(h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)((g)i)(g(i))i((f h)((f)(h)))((e g)((e)(g)))((f)(e)(j))(f((e)(j)))((g e j)((g)(e j)))((f(e)(j))((f)((e)(j))))((i h)((i)(h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((b)((a((g i)((g)(i)))(f i)((f)(i))((f)h)(f(h))((e f)((e)(f)))(e)(j)((g e j)((g)(e j)))((f(e)(j))((f)((e)(j))))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)(g i)((g)(i))i(f h)((f)(h))(e)((f)(e)(j))(f((e)(j)))((g e j)((g)(e j)))((f(e)(j))((f)((e)(j))))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))))((c)((b((a(((g)i)(g(i)))((f i)((f)(i)))(((f)(h))(f h))((e(f g)((f)(g)))((e)((f g)((f)(g)))))(e)(j)((g e j)((g)(e j)))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))(i)((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)((g)i)(g(i))(i)((f(h))((f)h))((e g)((e)(g)))((f)(e)(j))(f((e)(j)))((g e j)((g)(e j)))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))(i)((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((b)((a((g i)((g)(i)))((f i)((f)(i)))((f)(h))(f h)((e f)((e)(f)))(e)(j)((g e j)((g)(e j)))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))((i(g))((i)g))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)(g i)((g)(i))(i)(f(h))((f)h)(e)((f)(e)(j))(f((e)(j)))((g e j)((g)(e j)))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))((i(g))((i)g))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))))))((d)((c((b a(((g)(i))(g i))f(((f)h)(f(h)))((e(f g)((f)(g)))((e)((f g)((f)(g)))))((e)(j))((g((i)e j)(i(e j)))((g)(((i)e j)(i(e j)))))((f(e)(j))((f)((e)(j))))((i h)((i)(h)))((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j(((h)(i))(h i)))((j)((h)(i))(h i))))((b)a((g(i))((g)i))f((f)h)(f(h))((e f)((e)(f)))((e)(j))((g((i)e j)(i(e j)))((g)(((i)e j)(i(e j)))))((f(e)(j))((f)((e)(j))))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j(((h)(i))(h i)))((j)((h)(i))(h i))))))((c)((b((a(((g)(i))(g i))(f)(((f)(h))(f h))((e(f g)((f)(g)))((e)((f g)((f)(g)))))((e)(j))((g((i)e j)(i(e j)))((g)(((i)e j)(i(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))(i)((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)((g)(i))(g i)((f(h))((f)h))((e g)((e)(g)))(((f)(e)(j))(f((e)(j))))((g((i)e j)(i(e j)))((g)(((i)e j)(i(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))(i)((h((g)(e)(j))(g((e)(j))))((h)(((g)(e)(j))(g((e)(j))))))((j((h(i))((h)i)))((j)(h(i))((h)i))))))((b)((a((g(i))((g)i))(f)((f)(h))(f h)((e f)((e)(f)))((e)(j))((g((i)e j)(i(e j)))((g)(((i)e j)(i(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))((i(g))((i)g))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)(g(i))((g)i)(f(h))((f)h)(e)(((f)(e)(j))(f((e)(j))))((g((i)e j)(i(e j)))((g)(((i)e j)(i(e j)))))((f((h)(e)(j))(h((e)(j))))((f)(((h)(e)(j))(h((e)(j))))))((i(g))((i)g))((h(g(e)(j))((g)((e)(j))))((h)((g(e)(j))((g)((e)(j))))))((j((h(i))((h)i)))((j)(h(i))((h)i)))))))))))\n\ne ((e((d((c b(a)((g)i)(g(i))i((f h)((f)(h)))g(f)((g j)((g)(j)))(f)((i h)((i)(h)))((h(g))((h)g))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((c)b(a)((g)i)(g(i))(i)((f(h))((f)h))g(f)((g j)((g)(j)))((f(h))((f)h))(i)((h(g))((h)g))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((d)((c((b a(((g)(i))(g i))f(((f)h)(f(h)))(f g)((f)(g))((g((i)j)(i(j)))((g)(((i)j)(i(j)))))(f)((i h)((i)(h)))((h(g))((h)g))((j(((h)(i))(h i)))((j)((h)(i))(h i))))((b)a((g(i))((g)i))f((f)h)(f(h))f((g((i)j)(i(j)))((g)(((i)j)(i(j)))))(f)((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h g)((h)(g)))((j(((h)(i))(h i)))((j)((h)(i))(h i))))))((c)((b((a(((g)(i))(g i))(f)(((f)(h))(f h))(f g)((f)(g))((g((i)j)(i(j)))((g)(((i)j)(i(j)))))((f(h))((f)h))(i)((h(g))((h)g))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)((g)(i))(g i)((f(h))((f)h))g f((g((i)j)(i(j)))((g)(((i)j)(i(j)))))((f(h))((f)h))(i)((h(g))((h)g))((j((h(i))((h)i)))((j)(h(i))((h)i))))))((b)a((g(i))((g)i))(f)((f)(h))(f h)f((g((i)j)(i(j)))((g)(((i)j)(i(j)))))((f(h))((f)h))((i(g))((i)g))((h g)((h)(g)))((j((h(i))((h)i)))((j)(h(i))((h)i))))))))))((e)((d((c((b((a(((g)i)(g(i)))(f i)((f)(i))(((f)h)(f(h)))((f g)((f)(g)))(j)(g)((f(j))((f)j))((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)((g)i)(g(i))i((f h)((f)(h)))(g)((f)(j))(f j)(g)((f(j))((f)j))((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((b)((a((g i)((g)(i)))(f i)((f)(i))((f)h)(f(h))(f)(j)(g)((f(j))((f)j))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(j))((g)j))((h)((g(j))((g)j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)(g i)((g)(i))i(f h)((f)(h))((f)(j))(f j)(g)((f(j))((f)j))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(j))((g)j))((h)((g(j))((g)j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))))((c)((b((a(((g)i)(g(i)))((f i)((f)(i)))(((f)(h))(f h))((f g)((f)(g)))(j)(g)((f((h)(j))(h j))((f)(((h)(j))(h j))))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)((g)i)(g(i))(i)((f(h))((f)h))(g)((f)(j))(f j)(g)((f((h)(j))(h j))((f)(((h)(j))(h j))))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((b)((a((g i)((g)(i)))((f i)((f)(i)))((f)(h))(f h)(f)(j)(g)((f((h)(j))(h j))((f)(((h)(j))(h j))))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)(g i)((g)(i))(i)(f(h))((f)h)((f)(j))(f j)(g)((f((h)(j))(h j))((f)(((h)(j))(h j))))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))))))((d)((c((b a(((g)(i))(g i))f(((f)h)(f(h)))((f g)((f)(g)))j((g(i))((g)i))((f(j))((f)j))((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)(i))(h i)))((j)((h)(i))(h i))))((b)a((g(i))((g)i))f((f)h)(f(h))(f)j((g(i))((g)i))((f(j))((f)j))((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(j))((g)j))((h)((g(j))((g)j))))((j(((h)(i))(h i)))((j)((h)(i))(h i))))))((c)((b((a(((g)(i))(g i))(f)(((f)(h))(f h))((f g)((f)(g)))j((g(i))((g)i))((f((h)(j))(h j))((f)(((h)(j))(h j))))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)((g)(i))(g i)((f(h))((f)h))(g)(((f)(j))(f j))((g(i))((g)i))((f((h)(j))(h j))((f)(((h)(j))(h j))))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))))((b)((a((g(i))((g)i))(f)((f)(h))(f h)(f)j((g(i))((g)i))((f((h)(j))(h j))((f)(((h)(j))(h j))))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)(g(i))((g)i)(f(h))((f)h)(((f)(j))(f j))((g(i))((g)i))((f((h)(j))(h j))((f)(((h)(j))(h j))))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h(i))((h)i)))((j)(h(i))((h)i)))))))))))))\n\nf"
},
{
"output_type": "stream",
"stream": "stdout",
"text": " ((f((e(d)(c)b(a)((g)(i))(g i)(h)g((g((i)j)(i(j)))((g)(((i)j)(i(j)))))(h)(i)((h(g))((h)g))((j((h(i))((h)i)))((j)(h(i))((h)i))))((e)((d((c((b((a(((g)i)(g(i)))(i)(h)g(j)(g)(j)((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)((g)i)(g(i))i h(g)(j)(g)(j)((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((b)(a)(g i)((g)(i))i(h)(j)(g)(j)((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(j))((g)j))((h)((g(j))((g)j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((c)((b((a(((g)i)(g(i)))i h g(j)(g)((h)(j))(h j)(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)((g)i)(g(i))(i)(h)(g)(j)(g)((h)(j))(h j)(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((b)(a)(g i)((g)(i))(i)h(j)(g)((h)(j))(h j)((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))))((d)((c b a(((g)(i))(g i))(h)g j((g(i))((g)i))(j)((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)(i))(h i)))((j)((h)(i))(h i))))((c)((b(a)((g)(i))(g i)(h)(g)j((g(i))((g)i))((h)(j))(h j)(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((b)(a)(g(i))((g)i)h j((g(i))((g)i))((h)(j))(h j)((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))))))))))((f)((e((d((c b(a)((g)i)(g(i))i(h)g((g j)((g)(j)))((i h)((i)(h)))((h(g))((h)g))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((c)b(a)((g)i)(g(i))(i)h g((g j)((g)(j)))h(i)((h(g))((h)g))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((d)(c)b a(((g)(i))(g i))(h)g((g((i)j)(i(j)))((g)(((i)j)(i(j)))))h(i)((h(g))((h)g))((j((h(i))((h)i)))((j)(h(i))((h)i))))))((e)((d((c((b((a(((g)i)(g(i)))i h(g)(j)(g)j((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)((g)i)(g(i))i(h)(g)j(g)j((i h)((i)(h)))((h((g)(j))(g j))((h)(((g)(j))(g j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((b)((a((g i)((g)(i)))i(h)(j)(g)j((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(j))((g)j))((h)((g(j))((g)j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)(g i)((g)(i))i h j(g)j((i((g)h)(g(h)))((i)(((g)h)(g(h)))))((h(g(j))((g)j))((h)((g(j))((g)j))))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))))((c)((b((a(((g)i)(g(i)))(i)(h)(g)(j)(g)(((h)(j))(h j))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)((g)i)(g(i))(i)h(g)j(g)(((h)(j))(h j))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((b)((a((g i)((g)(i)))(i)h(j)(g)(((h)(j))(h j))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)(g i)((g)(i))(i)(h)j(g)(((h)(j))(h j))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))))))((d)(c)((b((a(((g)(i))(g i))(h)(g)j((g(i))((g)i))(((h)(j))(h j))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)((g)(i))(g i)h(g)(j)((g(i))((g)i))(((h)(j))(h j))(i)((h((g)(j))(g j))((h)(((g)(j))(g j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))))((b)((a((g(i))((g)i))h j((g(i))((g)i))(((h)(j))(h j))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)(g(i))((g)i)(h)(j)((g(i))((g)i))(((h)(j))(h j))((i(g))((i)g))((h(g(j))((g)j))((h)((g(j))((g)j))))((j((h(i))((h)i)))((j)(h(i))((h)i)))))))))))))\n\ng ((g((f((e(d)(c)b(a)(i)(h)((i)j)(i(j))(h)(i)(h)((j((h(i))((h)i)))((j)(h(i))((h)i))))((e)(d)((c b a i(h)j(i)(j)((i h)((i)(h)))((h(j))((h)j))((j(((h)(i))(h i)))((j)((h)(i))(h i))))((c)(b)(a)i h j(i)((h)(j))(h j)(i)((h j)((h)(j)))((j((h(i))((h)i)))((j)(h(i))((h)i))))))))((f)((e((d((c b(a)i i(h)j((i h)((i)(h)))(h)((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((c)b(a)i(i)h j h(i)(h)((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((d)(c)b a i(h)((i)j)(i(j))h(i)(h)((j((h(i))((h)i)))((j)(h(i))((h)i))))))((e)(d)(c)(b)((a(i)h j(i)(((h)(j))(h j))(i)((h j)((h)(j)))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)i(h)(j)(i)(((h)(j))(h j))(i)((h j)((h)(j)))((j((h(i))((h)i)))((j)(h(i))((h)i))))))))))((g)((f(e)((d((c((b(a)(i)i h(j)(j)((i h)((i)(h)))((h j)((h)(j)))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((b)(a)i i(h)(j)(j)((i(h))((i)h))((h(j))((h)j))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((c)((b(a)(i)(i)(h)(j)((h)(j))(h j)(i)((h j)((h)(j)))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((b)(a)i(i)h(j)((h)(j))(h j)i((h(j))((h)j))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))))((d)(c)((b(a)i(h)j i((h)(j))(h j)(i)((h j)((h)(j)))((j((h(i))((h)i)))((j)(h(i))((h)i))))((b)(a)(i)h j i((h)(j))(h j)i((h(j))((h)j))((j((h(i))((h)i)))((j)(h(i))((h)i))))))))((f)(e)((d((c((b((a i i h(j)j((i h)((i)(h)))((h j)((h)(j)))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)(i)i(h)j j((i h)((i)(h)))((h j)((h)(j)))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))((b)((a(i)i(h)(j)j((i(h))((i)h))((h(j))((h)j))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))((a)i i h j j((i(h))((i)h))((h(j))((h)j))((j(((h)i)(h(i))))((j)((h)i)(h(i)))))))))((c)((b((a i(i)(h)(j)(((h)(j))(h j))(i)((h j)((h)(j)))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)(i)(i)h j(((h)(j))(h j))(i)((h j)((h)(j)))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))((b)((a(i)(i)h(j)(((h)(j))(h j))i((h(j))((h)j))((j((h i)((h)(i))))((j)(h i)((h)(i)))))((a)i(i)(h)j(((h)(j))(h j))i((h(j))((h)j))((j((h i)((h)(i))))((j)(h i)((h)(i)))))))))))((d)(c)((b((a(i)(h)j i(((h)(j))(h j))(i)((h j)((h)(j)))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)i h(j)i(((h)(j))(h j))(i)((h j)((h)(j)))((j((h(i))((h)i)))((j)(h(i))((h)i))))))((b)((a i h j i(((h)(j))(h j))i((h(j))((h)j))((j((h(i))((h)i)))((j)(h(i))((h)i))))((a)(i)(h)(j)i(((h)(j))(h j))i((h(j))((h)j))((j((h(i))((h)i)))((j)(h(i))((h)i)))))))))))))\n\nh ((h((g((f(e)(d)(c)(b)(a)i j(i)(j)(i)j((j(i))((j)i)))((f)(e)(d)(c)(b)a(i)j(i)j(i)j((j(i))((j)i)))))((g)((f(e)((d((c b(a)(i)i(j)(j)i j((j(i))((j)i)))((c)(b)(a)i(i)(j)(j)i(j)((j i)((j)(i))))))((d)(c)(b)(a)(i)j i(j)i(j)((j(i))((j)i)))))((f)(e)((d((c((b a i i(j)j i j((j(i))((j)i)))((b)(a)i i j j(i)(j)((j(i))((j)i)))))((c)((b(a)(i)(i)j j(i)j((j i)((j)(i))))((b)a(i)(i)(j)j i(j)((j i)((j)(i))))))))((d)(c)((b(a)i(j)i j(i)j((j(i))((j)i)))((b)a i j i j i(j)((j(i))((j)i)))))))))))((h)((g((f((e(d)(c)b(a)(i)((i)j)(i(j))(i)((j i)((j)(i))))((e)(d)c b a i j(i)(j)(i)j((j(i))((j)i)))))((f)((e d c b(a)i i j(i)((j i)((j)(i))))((e)(d)(c)(b)(a)i(j)(i)(j)(i)(j)((j i)((j)(i))))))))((g)((f(e)((d((c(b)(a)i i(j)(j)i j((j i)((j)(i))))((c)b(a)(i)(i)(j)j(i)(j)((j(i))((j)i)))))((d)(c)b(a)i j i j(i)(j)((j i)((j)(i))))))((f)(e)((d((c((b(a)(i)i j j(i)(j)((j i)((j)(i))))((b)a(i)i(j)j i j((j i)((j)(i))))))((c)((b a i(i)(j)(j)(i)(j)((j(i))((j)i)))((b)(a)i(i)j(j)i j((j(i))((j)i)))))))((d)(c)((b a(i)j i(j)(i)(j)((j i)((j)(i))))((b)(a)(i)(j)i(j)i j((j i)((j)(i)))))))))))))\n\ni"
},
{
"output_type": "stream",
"stream": "stdout",
"text": " ((i((h(g)(f)(e)((d c b a(j)j j(j))((d)(c)(b)a j j(j)(j))))((h)(g)f(e)d c(b)(a)(j)(j)j j)))((i)((h((g(f)(e)(d)(c)(b)a j j j j)((g)(f)(e)d(c)b(a)j j j(j))))((h)((g f e(d)(c)b(a)(j)(j))((g)f(e)d(c)b(a)(j)j(j)j))))))\n\nj ((j(i)h g(f)(e)(d)(c)(b)a)((j)(i)(h)g f e(d)(c)b(a)))\n"
}
],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": "print to_string(Z)",
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "((j(i)h g(f)(e)(d)(c)(b)a)((j)(i)(h)g f e(d)(c)b(a)))"
}
],
"prompt_number": 15
},
{
"cell_type": "markdown",
"source": "See http://markability.net/five_liars.htm et. al."
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment