{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Truth Tables Tutorial Workbook\n", "\n", "**What is this workbook?**\n", "A workbook is a collection of problems, accompanied by solutions to them. \n", "The explanations focus on the logical steps required to solve a problem; they illustrate the concepts that need to be applied to come up with a solution to the problem, explaining the mathematical steps required. \n", "\n", "Note that a workbook should not be the primary source of knowledge on the subject matter; it assumes that you've already read a tutorial or a textbook and that you are now seeking to improve your problem-solving skills. You should attempt solving the tasks of the respective kata first, and turn to the workbook only if stuck. While a textbook emphasizes knowledge acquisition, a workbook emphasizes skill acquisition.\n", "\n", "This workbook describes the solutions to the problems offered in the [Truth Tables tutorial](./TruthTables.ipynb). \n", "Since the tasks are offered as programming problems, the explanations also cover some elements of Python that might be non-obvious for a first-time user.\n", "\n", "**What you should know for this workbook**\n", "\n", "1. Truth tables.\n", "2. Basic Python knowledge is helpful but not necessary." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Task 1. Projective functions (elementary variables)\n", "\n", "**Goal:** \n", "Describe the three projective functions $x_1$, $x_2$, $x_3$ represented by integers. Each of them is a 3-input function, i.e., $f(x) : \\{0,1\\}^{3} \\rightarrow \\{0,1\\}$\n", "\n", "We use the following convention:\n", "- $x_1$ is the least significant input.\n", "- $x_3$ is the most significant input.\n", "\n", "> The function $x_1$ (least significant input) is given as an example. \n", "The function is true for assignments $001$, $011$, $101$, and $111$, since for all these assignments their least significant bit $x_1 = 1$.\n", "\n", "If $x_1 = 0b10101010$, what are the values of $x_2$ and $x_3$?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Solution\n", "\n", "Let's take another look at the truth table for the functions $x_1$, $x_2$, and $x_3$ \n", "\n", "
| $x_3$ | \n", "$x_2$ | \n", "$x_1$ | \n", "Is $x_1 = 1?$ | \n", "Is $x_2 = 1?$ | \n", "Is $x_3 = 1?$ | \n", "Bit of the integer which represents the truth table | \n", "
|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "0 | \n", "\n", " | \n", " | \n", " | Least significant | \n", "
| 0 | \n", "0 | \n", "1 | \n", "Yes | \n", "\n", " | \n", " | \n", " |
| 0 | \n", "1 | \n", "0 | \n", "\n", " | Yes | \n", "\n", " | \n", " |
| 0 | \n", "1 | \n", "1 | \n", "Yes | \n", "Yes | \n", "\n", " | \n", " |
| 1 | \n", "0 | \n", "0 | \n", "\n", " | \n", " | Yes | \n", "\n", " |
| 1 | \n", "0 | \n", "1 | \n", "Yes | \n", "\n", " | Yes | \n", "\n", " |
| 1 | \n", "1 | \n", "0 | \n", "\n", " | Yes | \n", "Yes | \n", "\n", " |
| 1 | \n", "1 | \n", "1 | \n", "Yes | \n", "Yes | \n", "Yes | \n", "Most Significant | \n", "