Today we will try to explain how to create a truth table for a logical expression. Please note that Boolean algebra is found in at least three tasks of the unified state exam. If you read this article, you will surely get more points in the computer science exam.
Operations
Before compiling a truth table, we suggest getting acquainted with the operations of Boolean algebra.
We begin our acquaintance with the negation function. It is also called inversion. Here is an example: the expression "I go to the cinema today." We apply an inversion to it, as a result we have: "Today I DO NOT go to the cinema."
Now let's talk about the functions of multiplication and addition, in Boolean algebra they have names - conjunction and disjunction, respectively. Suppose we are told: "you will go to the cinema if you learn the lessons and take out the trash." In this proposal, the union βANDβ performs the function of conjunction, and βIFβ - the function of conjunction.
A logical consequence is another complex operation of logic that contains two expressions: a condition and a consequence. If interpreted into Russian, the sentence is structured approximately as follows: "if I have time to learn literature, I will go to the cinema." Part of the sentence before the decimal point is the condition, and after the decimal point is the consequence.
Now briefly about the equivalence or equivalence function. It is rather difficult to draw a parallel with the Russian language in this case. For equivalence, it is worth remembering that if two input expressions are either false or true, then the result is positive, that is, equal to one.
Algorithm
Now we will talk about how to compile a truth table on computer science, or rather, discuss the algorithm of our actions.
To create a table, first of all, you need to decide on the number of cells, columns and rows. We will do everything in stages.
- We determine the number of lines. To do this, it is necessary to calculate how many variables are included in the expression, and to raise a deuce to this number. For example, how to create a truth table, or rather find out the number of rows for an expression with three variables? We raise two to the third degree and get eight. Excluding the header, we need eight lines.
- In order to determine the number of columns, we need to count and number the operations in this expression. For example, in the expression nonA * C + B there are only three operations. The first is negation, the second is multiplication, the third is addition. So to fill in the values ββof operations, we need three columns. But, it is worth considering that our expression consists of three variables, and we need to fill out their possible combinations, we add three more columns. Total is 6.
- Next, we move on to listing possible combinations of variables and filling out the table. Be sure to consider the priority of operations.
First example (three variables)
We suggest you solve the following problem: calculate how many combinations satisfy the condition F = 1 of the expression: (not A + B) * not C + A. And now about how to create a truth table to solve the problem. We resort to the help of a compiled algorithm of actions.
- Number of rows = 9 (eight combinations of variables + one row - table heading).
- Priority of functions: 1 - inversion, 2 - addition in brackets, 3 - inversion C, 4 - multiplication, 5 - addition.
- The number of columns = 8.
- Table compilation and completion.
Expression A | Expression B | Expression C | Operation No. 1 | Operation No. 2 | Operation No. 3 | Operation No. 4 | Operation No. 5 |
- | - | - | + | + | + | + | AND |
- | - | + | + | + | - | - | L |
- | + | - | + | + | + | + | AND |
- | + | + | + | + | - | - | L |
+ | - | - | - | - | + | - | AND |
+ | - | + | - | - | - | - | AND |
+ | + | - | - | - | + | - | AND |
+ | + | + | - | - | - | - | AND |
- Finding the answer to the question.
- Record response. Answer: 6. Pay attention to the fact that the condition of the assignment asks how many combinations satisfy, but does not ask to list them.
Second example (4 variables)
We invite you to consider the question: how to compile a truth table for the formula: A * B * notC + D? How many combinations correspond to: F = 0.
We follow the same algorithm. The number of rows in our case increases to 17, and columns to 8. The priority of operations:
- A * B;
- ns;
- multiplication of the results of the first and second operations;
- addition is the result of the third operation and the value of variable D.
We suggest that you independently try to compile and fill out the table, and then check the results in this section of the article.
Variable A | Variable B | Variable C | Variable D | Multiplication (1) | Inversion (2) | Multiplication (3) | Addition (4) |
- | - | - | - | - | + | - | - |
- | - | - | + | - | + | - | + |
- | - | + | - | - | - | - | - |
- | - | + | + | - | - | - | + |
- | + | - | - | - | + | - | - |
- | + | - | + | - | + | - | + |
- | + | + | - | - | - | - | - |
- | + | + | + | - | - | - | + |
+ | - | - | - | - | + | - | - |
+ | - | - | + | - | + | - | + |
+ | - | + | - | - | - | - | - |
+ | - | + | + | - | - | - | + |
+ | + | - | - | + | + | + | + |
+ | + | - | + | + | + | + | + |
+ | + | + | - | + | - | - | - |
+ | + | + | + | + | - | - | + |
From the resulting table, we conclude: 7 different combinations of variables satisfy this condition.