Guest User

Untitled

a guest
Dec 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.19 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "Populating the interactive namespace from numpy and matplotlib\n",
  13. "Author : S Monroe\n",
  14. "Version : 3.6.3 | packaged by conda-forge | (default, Dec 9 2017, 16:22:46)\n",
  15. "Symbolic lib : 1.1.1\n",
  16. "Encoding : utf-8\n",
  17. "Timestamp : 1513369062.828918\n"
  18. ]
  19. }
  20. ],
  21. "source": [
  22. "%pylab inline\n",
  23. "from sympy import *\n",
  24. "from sympy.logic.boolalg import truth_table\n",
  25. "import sympy as sp\n",
  26. "import time\n",
  27. "\n",
  28. "#hextime=float.hex(time.time())\n",
  29. "\n",
  30. "a, b, x, y, z, t = symbols('a b x y z t')\n",
  31. "k, m, n = symbols('k m n', integer=True)\n",
  32. "f, g, h = symbols('f g h', cls=Function)\n",
  33. "\n",
  34. "\n",
  35. "init_printing()\n",
  36. "\n",
  37. "print(\"Author : S Monroe\")\n",
  38. "print(\"Version :\",sys.version[0:66])\n",
  39. "print(\"Symbolic lib :\",sp.__version__)\n",
  40. "print(\"Encoding :\",sys.getdefaultencoding())\n",
  41. "print(\"Timestamp :\",time.time())"
  42. ]
  43. },
  44. {
  45. "cell_type": "markdown",
  46. "metadata": {},
  47. "source": [
  48. "Usually, logic is divided into two states, \"TRUE\" and \"FALSE\" ... These two logic states are also known as \"1\" and \"0\" or \"HIGH\" and \"LOW\" respectively. Systems that use these two states are said to be \"Boolean\" or \"Binary\""
  49. ]
  50. },
  51. {
  52. "cell_type": "markdown",
  53. "metadata": {},
  54. "source": [
  55. "<code>IEEE-1164, used for VHDL (VHSIC Hardware Description Language) has 9 distinct logic levels:</code>\n",
  56. "\n",
  57. "<code>'U' uninitialized</code>\n",
  58. "\n",
  59. "<code>'X' strong drive, unknown logic value</code>\n",
  60. "\n",
  61. "<code>'0' strong drive, logic zero</code>\n",
  62. "\n",
  63. "<code>'1' strong drive, logic one</code>\n",
  64. "\n",
  65. "<code>'Z' high impedance</code>\n",
  66. "\n",
  67. "<code>'W' weak drive, unknown logic value</code>\n",
  68. "\n",
  69. "<code>'L' weak drive, logic zero</code>\n",
  70. "\n",
  71. "<code>'H' weak drive, logic one</code>\n",
  72. "\n",
  73. "<code>'-' don't care</code>"
  74. ]
  75. },
  76. {
  77. "cell_type": "markdown",
  78. "metadata": {},
  79. "source": [
  80. "For our purposes in this class, we will only concern ourselves with \"<code>1</code>\" and \"<code>0</code>\""
  81. ]
  82. },
  83. {
  84. "cell_type": "markdown",
  85. "metadata": {},
  86. "source": [
  87. "Obviously, if these values of \"<code>1</code>\" and \"<code>0</code>\" are to be implemented in hardware, they need to be assigned some physical value like voltage and/or current"
  88. ]
  89. },
  90. {
  91. "cell_type": "markdown",
  92. "metadata": {},
  93. "source": [
  94. "All of the logic we use in this class will use will be \"TTL\" (_\"Transistor-Transistor-Logic\"_)"
  95. ]
  96. },
  97. {
  98. "cell_type": "markdown",
  99. "metadata": {},
  100. "source": [
  101. "For historical reasons, TTL logic is given a grade number: \"74\" for so-called \"industrial grade\", and \"54\" for \"military grade\""
  102. ]
  103. },
  104. {
  105. "cell_type": "markdown",
  106. "metadata": {},
  107. "source": [
  108. "For this class, all the logic we use will be \"industrial grade\""
  109. ]
  110. },
  111. {
  112. "cell_type": "markdown",
  113. "metadata": {},
  114. "source": [
  115. "After the grade number is the _logic family_ designator. <b>For the purposes of this class</b> this will be \"Standard TTL\", \"Schottky TTL\" or \"Low-Power Schottky TTL\""
  116. ]
  117. },
  118. {
  119. "cell_type": "markdown",
  120. "metadata": {},
  121. "source": [
  122. "Finally, the part number has a sequence number indicating its function. <b>For example</b>, an integrated circuit package that is an industrial grade, two input <code>AND</code> gate containing four independent gates in standard TTL logic is a <code>7408</code>. The Schottky version is <code>74S08</code>, and the Low-Power Schottky is <code>74LS08</code>"
  123. ]
  124. },
  125. {
  126. "cell_type": "markdown",
  127. "metadata": {},
  128. "source": [
  129. "Contained below is a table indicating logic part numbers and logic function for the functions we will be using in this class<br><br>\n",
  130. "<style type=\"text/css\">\n",
  131. ".tg {border-collapse:collapse;border-spacing:0;}\n",
  132. ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  133. ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  134. ".tg .tg-rkwu{font-family:\"Courier New\", Courier, monospace !important;;vertical-align:top}\n",
  135. ".tg .tg-vyw9{font-family:\"Courier New\", Courier, monospace !important;}\n",
  136. ".tg .tg-yw4l{vertical-align:top}\n",
  137. "</style>\n",
  138. "<table class=\"tg\">\n",
  139. " <tr>\n",
  140. " <th class=\"tg-vyw9\">Part</th>\n",
  141. " <th class=\"tg-rkwu\">Function</th>\n",
  142. " <th class=\"tg-rkwu\">Device Count<br></th>\n",
  143. " <th class=\"tg-rkwu\">Input Count<br></th>\n",
  144. " </tr>\n",
  145. " <tr>\n",
  146. " <td class=\"tg-yw4l\">7400</td>\n",
  147. " <td class=\"tg-yw4l\">NAND<br></td>\n",
  148. " <td class=\"tg-yw4l\">4<br></td>\n",
  149. " <td class=\"tg-yw4l\">2/ea<br></td>\n",
  150. " </tr>\n",
  151. " <tr>\n",
  152. " <td class=\"tg-yw4l\">7402<br></td>\n",
  153. " <td class=\"tg-yw4l\">NOR<br></td>\n",
  154. " <td class=\"tg-yw4l\">4</td>\n",
  155. " <td class=\"tg-yw4l\">2/ea</td>\n",
  156. " </tr>\n",
  157. " <tr>\n",
  158. " <td class=\"tg-yw4l\">7404</td>\n",
  159. " <td class=\"tg-yw4l\">NOT</td>\n",
  160. " <td class=\"tg-yw4l\">6</td>\n",
  161. " <td class=\"tg-yw4l\">1/ea</td>\n",
  162. " </tr>\n",
  163. " <tr>\n",
  164. " <td class=\"tg-yw4l\">7408</td>\n",
  165. " <td class=\"tg-yw4l\">AND</td>\n",
  166. " <td class=\"tg-yw4l\">4</td>\n",
  167. " <td class=\"tg-yw4l\">2/ea</td>\n",
  168. " </tr>\n",
  169. " <tr>\n",
  170. " <td class=\"tg-yw4l\">7432</td>\n",
  171. " <td class=\"tg-yw4l\">OR</td>\n",
  172. " <td class=\"tg-yw4l\">4</td>\n",
  173. " <td class=\"tg-yw4l\">2/ea</td>\n",
  174. " </tr>\n",
  175. " <tr>\n",
  176. " <td class=\"tg-yw4l\">7486<br></td>\n",
  177. " <td class=\"tg-yw4l\">XOR</td>\n",
  178. " <td class=\"tg-yw4l\">4</td>\n",
  179. " <td class=\"tg-yw4l\">2/ea</td>\n",
  180. " </tr>\n",
  181. "</table>\n",
  182. "<br>\n",
  183. "<style type=\"text/css\">\n",
  184. ".tg {border-collapse:collapse;border-spacing:0;}\n",
  185. ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  186. ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  187. ".tg .tg-rkwu{font-family:\"Courier New\", Courier, monospace !important;;vertical-align:top}\n",
  188. ".tg .tg-vyw9{font-family:\"Courier New\", Courier, monospace !important;}\n",
  189. ".tg .tg-yw4l{vertical-align:top}\n",
  190. "</style>\n",
  191. "<table class=\"tg\">\n",
  192. " <tr>\n",
  193. " <th class=\"tg-vyw9\">Part</th>\n",
  194. " <th class=\"tg-rkwu\">Function</th>\n",
  195. " <th class=\"tg-rkwu\">Device Count<br></th>\n",
  196. " <th class=\"tg-rkwu\">Input Count<br></th>\n",
  197. " </tr>\n",
  198. " <tr>\n",
  199. " <td class=\"tg-yw4l\">74S00</td>\n",
  200. " <td class=\"tg-yw4l\">NAND<br></td>\n",
  201. " <td class=\"tg-yw4l\">4<br></td>\n",
  202. " <td class=\"tg-yw4l\">2/ea<br></td>\n",
  203. " </tr>\n",
  204. " <tr>\n",
  205. " <td class=\"tg-yw4l\">74S02<br></td>\n",
  206. " <td class=\"tg-yw4l\">NOR<br></td>\n",
  207. " <td class=\"tg-yw4l\">4</td>\n",
  208. " <td class=\"tg-yw4l\">2/ea</td>\n",
  209. " </tr>\n",
  210. " <tr>\n",
  211. " <td class=\"tg-yw4l\">74S04</td>\n",
  212. " <td class=\"tg-yw4l\">NOT</td>\n",
  213. " <td class=\"tg-yw4l\">6</td>\n",
  214. " <td class=\"tg-yw4l\">1/ea</td>\n",
  215. " </tr>\n",
  216. " <tr>\n",
  217. " <td class=\"tg-yw4l\">74S08</td>\n",
  218. " <td class=\"tg-yw4l\">AND</td>\n",
  219. " <td class=\"tg-yw4l\">4</td>\n",
  220. " <td class=\"tg-yw4l\">2/ea</td>\n",
  221. " </tr>\n",
  222. " <tr>\n",
  223. " <td class=\"tg-yw4l\">74S32</td>\n",
  224. " <td class=\"tg-yw4l\">OR</td>\n",
  225. " <td class=\"tg-yw4l\">4</td>\n",
  226. " <td class=\"tg-yw4l\">2/ea</td>\n",
  227. " </tr>\n",
  228. " <tr>\n",
  229. " <td class=\"tg-yw4l\">74S86<br></td>\n",
  230. " <td class=\"tg-yw4l\">XOR</td>\n",
  231. " <td class=\"tg-yw4l\">4</td>\n",
  232. " <td class=\"tg-yw4l\">2/ea</td>\n",
  233. " </tr>\n",
  234. "</table>\n",
  235. "<br>\n",
  236. "<style type=\"text/css\">\n",
  237. ".tg {border-collapse:collapse;border-spacing:0;}\n",
  238. ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  239. ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  240. ".tg .tg-rkwu{font-family:\"Courier New\", Courier, monospace !important;;vertical-align:top}\n",
  241. ".tg .tg-vyw9{font-family:\"Courier New\", Courier, monospace !important;}\n",
  242. ".tg .tg-yw4l{vertical-align:top}\n",
  243. "</style>\n",
  244. "<table class=\"tg\">\n",
  245. " <tr>\n",
  246. " <th class=\"tg-vyw9\">Part</th>\n",
  247. " <th class=\"tg-rkwu\">Function</th>\n",
  248. " <th class=\"tg-rkwu\">Device Count<br></th>\n",
  249. " <th class=\"tg-rkwu\">Input Count<br></th>\n",
  250. " </tr>\n",
  251. " <tr>\n",
  252. " <td class=\"tg-yw4l\">74LS00</td>\n",
  253. " <td class=\"tg-yw4l\">NAND<br></td>\n",
  254. " <td class=\"tg-yw4l\">4<br></td>\n",
  255. " <td class=\"tg-yw4l\">2/ea<br></td>\n",
  256. " </tr>\n",
  257. " <tr>\n",
  258. " <td class=\"tg-yw4l\">74LS02<br></td>\n",
  259. " <td class=\"tg-yw4l\">NOR<br></td>\n",
  260. " <td class=\"tg-yw4l\">4</td>\n",
  261. " <td class=\"tg-yw4l\">2/ea</td>\n",
  262. " </tr>\n",
  263. " <tr>\n",
  264. " <td class=\"tg-yw4l\">74LS04</td>\n",
  265. " <td class=\"tg-yw4l\">NOT</td>\n",
  266. " <td class=\"tg-yw4l\">6</td>\n",
  267. " <td class=\"tg-yw4l\">1/ea</td>\n",
  268. " </tr>\n",
  269. " <tr>\n",
  270. " <td class=\"tg-yw4l\">74LS08</td>\n",
  271. " <td class=\"tg-yw4l\">AND</td>\n",
  272. " <td class=\"tg-yw4l\">4</td>\n",
  273. " <td class=\"tg-yw4l\">2/ea</td>\n",
  274. " </tr>\n",
  275. " <tr>\n",
  276. " <td class=\"tg-yw4l\">74LS32</td>\n",
  277. " <td class=\"tg-yw4l\">OR</td>\n",
  278. " <td class=\"tg-yw4l\">4</td>\n",
  279. " <td class=\"tg-yw4l\">2/ea</td>\n",
  280. " </tr>\n",
  281. " <tr>\n",
  282. " <td class=\"tg-yw4l\">74LS86<br></td>\n",
  283. " <td class=\"tg-yw4l\">XOR</td>\n",
  284. " <td class=\"tg-yw4l\">4</td>\n",
  285. " <td class=\"tg-yw4l\">2/ea</td>\n",
  286. " </tr>\n",
  287. "</table>"
  288. ]
  289. },
  290. {
  291. "cell_type": "markdown",
  292. "metadata": {},
  293. "source": [
  294. "For each of the above logic families (i.e., \"Standard\", \"Schottky\", or \"Low-Power Schottky\") input voltage, output voltage, input current, output current, as well as propagation times will vary. A table below shows these in summary:\n",
  295. "<style type=\"text/css\">\n",
  296. ".tg {border-collapse:collapse;border-spacing:0;}\n",
  297. ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  298. ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}\n",
  299. ".tg .tg-vyw9{font-family:\"Courier New\", Courier, monospace !important;}\n",
  300. ".tg .tg-yw4l{vertical-align:top}\n",
  301. "</style>\n",
  302. "<table class=\"tg\">\n",
  303. " <tr>\n",
  304. " <th class=\"tg-vyw9\">Family<br></th>\n",
  305. " <th class=\"tg-yw4l\">$V_{IH}$</th>\n",
  306. " <th class=\"tg-yw4l\">$V_{IL}$</th>\n",
  307. " <th class=\"tg-yw4l\">$V_{OH}$</th>\n",
  308. " <th class=\"tg-yw4l\">$V_{OL}$<br></th>\n",
  309. " <th class=\"tg-yw4l\">$t_{plh}$<br></th>\n",
  310. " <th class=\"tg-yw4l\">$t_{phl}$</th>\n",
  311. " </tr>\n",
  312. " <tr>\n",
  313. " <td class=\"tg-yw4l\">STD</td>\n",
  314. " <td class=\"tg-yw4l\">2V</td>\n",
  315. " <td class=\"tg-yw4l\">0.8V</td>\n",
  316. " <td class=\"tg-yw4l\">2.4V</td>\n",
  317. " <td class=\"tg-yw4l\">0.4V</td>\n",
  318. " <td class=\"tg-yw4l\">11ns</td>\n",
  319. " <td class=\"tg-yw4l\">7ns</td>\n",
  320. " </tr>\n",
  321. " <tr>\n",
  322. " <td class=\"tg-yw4l\">S</td>\n",
  323. " <td class=\"tg-yw4l\">2V</td>\n",
  324. " <td class=\"tg-yw4l\">0.8V</td>\n",
  325. " <td class=\"tg-yw4l\">2.4V</td>\n",
  326. " <td class=\"tg-yw4l\">0.4V</td>\n",
  327. " <td class=\"tg-yw4l\">3ns</td>\n",
  328. " <td class=\"tg-yw4l\">3ns</td>\n",
  329. " </tr>\n",
  330. " <tr>\n",
  331. " <td class=\"tg-yw4l\">LS</td>\n",
  332. " <td class=\"tg-yw4l\">2V</td>\n",
  333. " <td class=\"tg-yw4l\">0.8V</td>\n",
  334. " <td class=\"tg-yw4l\">2.4V</td>\n",
  335. " <td class=\"tg-yw4l\">0.4V</td>\n",
  336. " <td class=\"tg-yw4l\">3ns</td>\n",
  337. " <td class=\"tg-yw4l\">3ns</td>\n",
  338. " </tr>\n",
  339. "</table>"
  340. ]
  341. },
  342. {
  343. "cell_type": "markdown",
  344. "metadata": {},
  345. "source": [
  346. "Let's look at a simple <code>NOT</code> function. For these examples, \"0\" or \"low\" is the same as \"false\", and \"1\" or \"high\" is the same as \"true\"<br>"
  347. ]
  348. },
  349. {
  350. "cell_type": "code",
  351. "execution_count": 2,
  352. "metadata": {},
  353. "outputs": [
  354. {
  355. "name": "stdout",
  356. "output_type": "stream",
  357. "text": [
  358. "True\n"
  359. ]
  360. }
  361. ],
  362. "source": [
  363. "Y1=~false\n",
  364. "print(Y1)"
  365. ]
  366. },
  367. {
  368. "cell_type": "code",
  369. "execution_count": 3,
  370. "metadata": {},
  371. "outputs": [
  372. {
  373. "name": "stdout",
  374. "output_type": "stream",
  375. "text": [
  376. "False\n"
  377. ]
  378. }
  379. ],
  380. "source": [
  381. "Y2=~true\n",
  382. "print(Y2)"
  383. ]
  384. },
  385. {
  386. "cell_type": "markdown",
  387. "metadata": {},
  388. "source": [
  389. "So, with a <code>NOT</code> function, we can see that whatever the input state is, the <code>NOT</code> function negates that input to produce the other state."
  390. ]
  391. },
  392. {
  393. "cell_type": "markdown",
  394. "metadata": {},
  395. "source": [
  396. "Let's look at a simple <code>AND</code> function. For these examples, \"0\" or \"low\" is the same as \"false\", and \"1\" or \"high\" is the same as \"true\""
  397. ]
  398. },
  399. {
  400. "cell_type": "code",
  401. "execution_count": 4,
  402. "metadata": {},
  403. "outputs": [
  404. {
  405. "name": "stdout",
  406. "output_type": "stream",
  407. "text": [
  408. "False\n"
  409. ]
  410. }
  411. ],
  412. "source": [
  413. "Y3=And(false, false)\n",
  414. "print(Y3)"
  415. ]
  416. },
  417. {
  418. "cell_type": "code",
  419. "execution_count": 5,
  420. "metadata": {},
  421. "outputs": [
  422. {
  423. "name": "stdout",
  424. "output_type": "stream",
  425. "text": [
  426. "False\n"
  427. ]
  428. }
  429. ],
  430. "source": [
  431. "Y4=And(false, true)\n",
  432. "print(Y4)"
  433. ]
  434. },
  435. {
  436. "cell_type": "code",
  437. "execution_count": 6,
  438. "metadata": {},
  439. "outputs": [
  440. {
  441. "name": "stdout",
  442. "output_type": "stream",
  443. "text": [
  444. "False\n"
  445. ]
  446. }
  447. ],
  448. "source": [
  449. "Y5=And(true, false)\n",
  450. "print(Y5)"
  451. ]
  452. },
  453. {
  454. "cell_type": "code",
  455. "execution_count": 7,
  456. "metadata": {},
  457. "outputs": [
  458. {
  459. "name": "stdout",
  460. "output_type": "stream",
  461. "text": [
  462. "True\n"
  463. ]
  464. }
  465. ],
  466. "source": [
  467. "Y6=And(true, true)\n",
  468. "print(Y6)"
  469. ]
  470. },
  471. {
  472. "cell_type": "markdown",
  473. "metadata": {},
  474. "source": [
  475. "Notice that the output is always <code>False</code> unless <code>input_1 <b>AND</b> input_2</code> are both <code>True</code>"
  476. ]
  477. },
  478. {
  479. "cell_type": "markdown",
  480. "metadata": {},
  481. "source": [
  482. "Let's look at a simple <code>OR</code> function. For these examples, \"0\" or \"low\" is the same as \"false\", and \"1\" or \"high\" is the same as \"true\""
  483. ]
  484. },
  485. {
  486. "cell_type": "code",
  487. "execution_count": 8,
  488. "metadata": {},
  489. "outputs": [
  490. {
  491. "name": "stdout",
  492. "output_type": "stream",
  493. "text": [
  494. "False\n"
  495. ]
  496. }
  497. ],
  498. "source": [
  499. "Y7=Or(false, false)\n",
  500. "print(Y7)"
  501. ]
  502. },
  503. {
  504. "cell_type": "code",
  505. "execution_count": 9,
  506. "metadata": {},
  507. "outputs": [
  508. {
  509. "name": "stdout",
  510. "output_type": "stream",
  511. "text": [
  512. "True\n"
  513. ]
  514. }
  515. ],
  516. "source": [
  517. "Y8=Or(false, true)\n",
  518. "print(Y8)"
  519. ]
  520. },
  521. {
  522. "cell_type": "code",
  523. "execution_count": 10,
  524. "metadata": {},
  525. "outputs": [
  526. {
  527. "name": "stdout",
  528. "output_type": "stream",
  529. "text": [
  530. "True\n"
  531. ]
  532. }
  533. ],
  534. "source": [
  535. "Y9=Or(true, false)\n",
  536. "print(Y9)"
  537. ]
  538. },
  539. {
  540. "cell_type": "code",
  541. "execution_count": 11,
  542. "metadata": {},
  543. "outputs": [
  544. {
  545. "name": "stdout",
  546. "output_type": "stream",
  547. "text": [
  548. "True\n"
  549. ]
  550. }
  551. ],
  552. "source": [
  553. "Y10=Or(true, true)\n",
  554. "print(Y10)"
  555. ]
  556. },
  557. {
  558. "cell_type": "markdown",
  559. "metadata": {},
  560. "source": [
  561. "Notice that the output is <code>True</code> when <code>input_1 <b>OR</b> input_2</code> are <code>True</code>"
  562. ]
  563. },
  564. {
  565. "cell_type": "markdown",
  566. "metadata": {},
  567. "source": [
  568. "We can create a <code>NAND</code> function, by simply combining the <code>NOT</code> and the <code>AND</code> ..."
  569. ]
  570. },
  571. {
  572. "cell_type": "code",
  573. "execution_count": 12,
  574. "metadata": {},
  575. "outputs": [
  576. {
  577. "name": "stdout",
  578. "output_type": "stream",
  579. "text": [
  580. "True\n"
  581. ]
  582. }
  583. ],
  584. "source": [
  585. "Y11=~(And(false,false))\n",
  586. "print(Y11)"
  587. ]
  588. },
  589. {
  590. "cell_type": "code",
  591. "execution_count": 13,
  592. "metadata": {},
  593. "outputs": [
  594. {
  595. "name": "stdout",
  596. "output_type": "stream",
  597. "text": [
  598. "True\n"
  599. ]
  600. }
  601. ],
  602. "source": [
  603. "Y12=~(And(false,true))\n",
  604. "print(Y12)"
  605. ]
  606. },
  607. {
  608. "cell_type": "code",
  609. "execution_count": 14,
  610. "metadata": {},
  611. "outputs": [
  612. {
  613. "name": "stdout",
  614. "output_type": "stream",
  615. "text": [
  616. "True\n"
  617. ]
  618. }
  619. ],
  620. "source": [
  621. "Y13=~(And(true,false))\n",
  622. "print(Y13)"
  623. ]
  624. },
  625. {
  626. "cell_type": "code",
  627. "execution_count": 15,
  628. "metadata": {},
  629. "outputs": [
  630. {
  631. "name": "stdout",
  632. "output_type": "stream",
  633. "text": [
  634. "False\n"
  635. ]
  636. }
  637. ],
  638. "source": [
  639. "Y14=~(And(true,true))\n",
  640. "print(Y14)"
  641. ]
  642. },
  643. {
  644. "cell_type": "markdown",
  645. "metadata": {},
  646. "source": [
  647. "We can create a <code>NOR</code> function, by simply combining the <code>NOT</code> and the <code>OR</code> ..."
  648. ]
  649. },
  650. {
  651. "cell_type": "code",
  652. "execution_count": 16,
  653. "metadata": {},
  654. "outputs": [
  655. {
  656. "name": "stdout",
  657. "output_type": "stream",
  658. "text": [
  659. "True\n"
  660. ]
  661. }
  662. ],
  663. "source": [
  664. "Y15=~(Or(false,false))\n",
  665. "print(Y15)"
  666. ]
  667. },
  668. {
  669. "cell_type": "code",
  670. "execution_count": 17,
  671. "metadata": {},
  672. "outputs": [
  673. {
  674. "name": "stdout",
  675. "output_type": "stream",
  676. "text": [
  677. "False\n"
  678. ]
  679. }
  680. ],
  681. "source": [
  682. "Y16=~(Or(false,true))\n",
  683. "print(Y16)"
  684. ]
  685. },
  686. {
  687. "cell_type": "code",
  688. "execution_count": 18,
  689. "metadata": {},
  690. "outputs": [
  691. {
  692. "name": "stdout",
  693. "output_type": "stream",
  694. "text": [
  695. "False\n"
  696. ]
  697. }
  698. ],
  699. "source": [
  700. "Y17=~(Or(true,false))\n",
  701. "print(Y17)"
  702. ]
  703. },
  704. {
  705. "cell_type": "code",
  706. "execution_count": 19,
  707. "metadata": {},
  708. "outputs": [
  709. {
  710. "name": "stdout",
  711. "output_type": "stream",
  712. "text": [
  713. "False\n"
  714. ]
  715. }
  716. ],
  717. "source": [
  718. "Y18=~(Or(true,true))\n",
  719. "print(Y18)"
  720. ]
  721. },
  722. {
  723. "cell_type": "markdown",
  724. "metadata": {},
  725. "source": [
  726. "Finally, let's create an <code>XOR</code> function ..."
  727. ]
  728. },
  729. {
  730. "cell_type": "code",
  731. "execution_count": 20,
  732. "metadata": {},
  733. "outputs": [
  734. {
  735. "name": "stdout",
  736. "output_type": "stream",
  737. "text": [
  738. "False\n"
  739. ]
  740. }
  741. ],
  742. "source": [
  743. "Y19=Xor(false,false)\n",
  744. "print(Y19)"
  745. ]
  746. },
  747. {
  748. "cell_type": "code",
  749. "execution_count": 21,
  750. "metadata": {},
  751. "outputs": [
  752. {
  753. "name": "stdout",
  754. "output_type": "stream",
  755. "text": [
  756. "True\n"
  757. ]
  758. }
  759. ],
  760. "source": [
  761. "Y20=Xor(false,true)\n",
  762. "print(Y20)"
  763. ]
  764. },
  765. {
  766. "cell_type": "code",
  767. "execution_count": 22,
  768. "metadata": {},
  769. "outputs": [
  770. {
  771. "name": "stdout",
  772. "output_type": "stream",
  773. "text": [
  774. "True\n"
  775. ]
  776. }
  777. ],
  778. "source": [
  779. "Y20=Xor(true,false)\n",
  780. "print(Y20)"
  781. ]
  782. },
  783. {
  784. "cell_type": "code",
  785. "execution_count": 23,
  786. "metadata": {},
  787. "outputs": [
  788. {
  789. "name": "stdout",
  790. "output_type": "stream",
  791. "text": [
  792. "False\n"
  793. ]
  794. }
  795. ],
  796. "source": [
  797. "Y21=Xor(true,true)\n",
  798. "print(Y21)"
  799. ]
  800. },
  801. {
  802. "cell_type": "markdown",
  803. "metadata": {},
  804. "source": [
  805. "Notice that the output is <code>True</code> when either <code>input_1 <b>OR</b> input_2</code> are <code>True</code>, but <b>not when both</b> are <code>TRUE</code>"
  806. ]
  807. },
  808. {
  809. "cell_type": "markdown",
  810. "metadata": {},
  811. "source": [
  812. "Now that we have seen all the logic functions in action, lets create a series of tables ... in each case the table will provide all possible input states and all possible output states:"
  813. ]
  814. },
  815. {
  816. "cell_type": "code",
  817. "execution_count": 24,
  818. "metadata": {},
  819. "outputs": [
  820. {
  821. "name": "stdout",
  822. "output_type": "stream",
  823. "text": [
  824. "NOT function:\n",
  825. "a y\n",
  826. "-----\n",
  827. "0 1\n",
  828. "1 0\n"
  829. ]
  830. }
  831. ],
  832. "source": [
  833. "a1=(0)\n",
  834. "a2=(1)\n",
  835. "print(\"NOT function:\")\n",
  836. "print(\"a y\")\n",
  837. "print(\"-----\")\n",
  838. "print(a1,int(not(a1)))\n",
  839. "print(a2,int(not(a2)))"
  840. ]
  841. },
  842. {
  843. "cell_type": "code",
  844. "execution_count": 25,
  845. "metadata": {},
  846. "outputs": [
  847. {
  848. "name": "stdout",
  849. "output_type": "stream",
  850. "text": [
  851. "AND function:\n",
  852. "a b y\n",
  853. "-----\n",
  854. "0 0 0\n",
  855. "0 1 0\n",
  856. "1 0 0\n",
  857. "1 1 1\n"
  858. ]
  859. }
  860. ],
  861. "source": [
  862. "a1=(0)\n",
  863. "b1=(0)\n",
  864. "a2=(0)\n",
  865. "b2=(1)\n",
  866. "a3=(1)\n",
  867. "b3=(0)\n",
  868. "a4=(1)\n",
  869. "b4=(1)\n",
  870. "print(\"AND function:\")\n",
  871. "print(\"a b y\")\n",
  872. "print(\"-----\")\n",
  873. "print(a1,b1,(a1&b1))\n",
  874. "print(a2,b2,(a2&b2))\n",
  875. "print(a3,b3,(a3&b3))\n",
  876. "print(a4,b4,(a4&b4))"
  877. ]
  878. },
  879. {
  880. "cell_type": "code",
  881. "execution_count": 26,
  882. "metadata": {},
  883. "outputs": [
  884. {
  885. "name": "stdout",
  886. "output_type": "stream",
  887. "text": [
  888. "NAND function:\n",
  889. "a b y\n",
  890. "-----\n",
  891. "0 0 1\n",
  892. "0 1 1\n",
  893. "1 0 1\n",
  894. "1 1 0\n"
  895. ]
  896. }
  897. ],
  898. "source": [
  899. "a1=(0)\n",
  900. "b1=(0)\n",
  901. "a2=(0)\n",
  902. "b2=(1)\n",
  903. "a3=(1)\n",
  904. "b3=(0)\n",
  905. "a4=(1)\n",
  906. "b4=(1)\n",
  907. "print(\"NAND function:\")\n",
  908. "print(\"a b y\")\n",
  909. "print(\"-----\")\n",
  910. "print(a1,b1,int(not(a1&b1)))\n",
  911. "print(a2,b2,int(not(a2&b2)))\n",
  912. "print(a3,b3,int(not(a3&b3)))\n",
  913. "print(a4,b4,int(not(a4&b4)))"
  914. ]
  915. },
  916. {
  917. "cell_type": "code",
  918. "execution_count": 27,
  919. "metadata": {},
  920. "outputs": [
  921. {
  922. "name": "stdout",
  923. "output_type": "stream",
  924. "text": [
  925. "OR function:\n",
  926. "a b y\n",
  927. "-----\n",
  928. "0 0 0\n",
  929. "0 1 1\n",
  930. "1 0 1\n",
  931. "1 1 1\n"
  932. ]
  933. }
  934. ],
  935. "source": [
  936. "a1=(0)\n",
  937. "b1=(0)\n",
  938. "a2=(0)\n",
  939. "b2=(1)\n",
  940. "a3=(1)\n",
  941. "b3=(0)\n",
  942. "a4=(1)\n",
  943. "b4=(1)\n",
  944. "print(\"OR function:\")\n",
  945. "print(\"a b y\")\n",
  946. "print(\"-----\")\n",
  947. "print(a1,b1,(a1|b1))\n",
  948. "print(a2,b2,(a2|b2))\n",
  949. "print(a3,b3,(a3|b3))\n",
  950. "print(a4,b4,(a4|b4))"
  951. ]
  952. },
  953. {
  954. "cell_type": "code",
  955. "execution_count": 28,
  956. "metadata": {},
  957. "outputs": [
  958. {
  959. "name": "stdout",
  960. "output_type": "stream",
  961. "text": [
  962. "NOR function:\n",
  963. "a b y\n",
  964. "-----\n",
  965. "0 0 1\n",
  966. "0 1 0\n",
  967. "1 0 0\n",
  968. "1 1 0\n"
  969. ]
  970. }
  971. ],
  972. "source": [
  973. "a1=(0)\n",
  974. "b1=(0)\n",
  975. "a2=(0)\n",
  976. "b2=(1)\n",
  977. "a3=(1)\n",
  978. "b3=(0)\n",
  979. "a4=(1)\n",
  980. "b4=(1)\n",
  981. "print(\"NOR function:\")\n",
  982. "print(\"a b y\")\n",
  983. "print(\"-----\")\n",
  984. "print(a1,b1,int(not(a1|b1)))\n",
  985. "print(a2,b2,int(not(a2|b2)))\n",
  986. "print(a3,b3,int(not(a3|b3)))\n",
  987. "print(a4,b4,int(not(a4|b4)))"
  988. ]
  989. },
  990. {
  991. "cell_type": "code",
  992. "execution_count": 29,
  993. "metadata": {},
  994. "outputs": [
  995. {
  996. "name": "stdout",
  997. "output_type": "stream",
  998. "text": [
  999. "XOR function:\n",
  1000. "a b y\n",
  1001. "-----\n",
  1002. "0 0 0\n",
  1003. "0 1 1\n",
  1004. "1 0 1\n",
  1005. "1 1 0\n"
  1006. ]
  1007. }
  1008. ],
  1009. "source": [
  1010. "a1=(0)\n",
  1011. "b1=(0)\n",
  1012. "a2=(0)\n",
  1013. "b2=(1)\n",
  1014. "a3=(1)\n",
  1015. "b3=(0)\n",
  1016. "a4=(1)\n",
  1017. "b4=(1)\n",
  1018. "print(\"XOR function:\")\n",
  1019. "print(\"a b y\")\n",
  1020. "print(\"-----\")\n",
  1021. "print(a1,b1,(a1^b1))\n",
  1022. "print(a2,b2,(a2^b2))\n",
  1023. "print(a3,b3,(a3^b3))\n",
  1024. "print(a4,b4,(a4^b4))"
  1025. ]
  1026. }
  1027. ],
  1028. "metadata": {
  1029. "kernelspec": {
  1030. "display_name": "Python 3",
  1031. "language": "python",
  1032. "name": "python3"
  1033. },
  1034. "language_info": {
  1035. "codemirror_mode": {
  1036. "name": "ipython",
  1037. "version": 3
  1038. },
  1039. "file_extension": ".py",
  1040. "mimetype": "text/x-python",
  1041. "name": "python",
  1042. "nbconvert_exporter": "python",
  1043. "pygments_lexer": "ipython3",
  1044. "version": "3.6.3"
  1045. }
  1046. },
  1047. "nbformat": 4,
  1048. "nbformat_minor": 2
  1049. }
Add Comment
Please, Sign In to add comment