{
"cells": [
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# CS 121 Lecture 5 : Syntactic sugar and computing every function"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"# utility code \n",
"%run \"Utilities.ipynb\"\n",
"from IPython.display import clear_output\n",
"clear_output()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"def AND(a,b): return a*b\n",
"\n",
"def OR(a,b): return 1 if a+b else 0\n",
"\n",
"def NOT(a): return 1-a"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"def IF(cond,a,b):\n",
" notcond = NAND(cond,cond)\n",
" temp = NAND(b,notcond)\n",
" temp1 = NAND(a,cond)\n",
" return NAND(temp,temp1)\n",
"mystery = circuit2prog(circuit(IF))"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"scrolled": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gate_0 = NAND(X[0],X[0])\n",
"gate_1 = NAND(X[2],gate_0)\n",
"gate_2 = NAND(X[1],X[0])\n",
"Y[0] = NAND(gate_1,gate_2)\n",
"\n"
]
},
{
"data": {
"text/plain": []
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/svg+xml": [
"\r\n",
"\r\n",
"\r\n",
"\r\n"
],
"text/plain": [
"