{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"Dependencies for this notebook: `graphviz` executable installed on the system and on the path, [networkx](https://anaconda.org/anaconda/networkx) and [graphviz python](https://anaconda.org/conda-forge/python-graphviz) anaconda packages. (See [here](https://graphviz.readthedocs.io/en/stable/index.html) for the documentation of the latter package.)\n",
"\n",
"Please run the utility code at the bottom of this notebook first.\n",
"\n",
"You should be able to upload this notebook to the JupyterHub instance on canvas.\n",
"\n",
"__comment:__ In this notebook I use `x_17` and not `x17` for 3SAT and 3NAND formula to be more consistent with our notation for NAND. This is of course not very important."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"%run \"Utilities.ipynb\"\n",
"from IPython.display import clear_output\n",
"clear_output()"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
" _Useful unicode symbols:_ φ ∨ ∧ ¬ ≠ Ψ"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"def numvars(φ):\n",
" for n in range(len(φ)-1,0,-1):\n",
" if φ.find('x'+str(n))>= 0 or φ.find('z'+str(n))>= 0: return n+1\n",
" raise Exception\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"from collections import defaultdict"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import networkx as nx\n",
"\n",
"import pydotplus\n",
"\n",
"def nxgraph(G):\n",
" P = pydotplus.graph_from_dot_data(G.source)\n",
" return nx.drawing.nx_pydot.from_pydot(P)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## NANDSAT\n",
"\n",
"__Input:__ $Q \\in \\{0,1\\}^*$: NAND-CIRC program of $n$ inputs and $1$ output\n",
"\n",
"__Output:__ $1$ iff $\\exists y\\in \\{0,1\\}^n$ s.t. $Q(y)=1$."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"inputHidden": false,
"outputHidden": false,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"xor5 = r'''\n",
"u = NAND(X[0],X[1])\n",
"v = NAND( X[0] , u)\n",
"w = NAND( X[1] , u)\n",
"s = NAND( v , w)\n",
"u = NAND( s , X[2])\n",
"v = NAND( s , u)\n",
"w = NAND( X[2] , u)\n",
"s = NAND( v , w)\n",
"u = NAND( s , X[3])\n",
"v = NAND( s , u)\n",
"w = NAND( X[3] , u)\n",
"s = NAND( v , w)\n",
"u = NAND( s , X[4])\n",
"v = NAND( s , u)\n",
"w = NAND( X[4] , u)\n",
"Y[0] = NAND( v , w)\n",
"'''[1:]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": []
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/svg+xml": [
"\r\n",
"\r\n",
"\r\n",
"\r\n"
],
"text/plain": [
"