Solving systems of logical equations graphically. Methods for solving systems of logical equations

This material contains a presentation that presents solution methods logical equations and systems of logical equations in task B15 (No. 23, 2015) of the Unified State Exam in computer science. It is known that this task is one of the most difficult among the Unified State Examination tasks. The presentation can be useful when teaching lessons on the topic “Logic” in specialized classes, as well as when preparing for the Unified State Exam.

Download:

Preview:

To use presentation previews, create an account for yourself ( account) Google and log in: https://accounts.google.com


Slide captions:

Solution of task B15 (systems of logical equations) Vishnevskaya M.P., MAOU “Gymnasium No. 3” November 18, 2013, Saratov

Task B15 is one of the most difficult in the Unified State Exam in computer science!!! The following skills are tested: convert expressions containing logical variables; describe in natural language the set of values ​​of logical variables for which a given set of logical variables is true; count the number of binary sets that satisfy given conditions. The most difficult thing is because... there are no formal rules on how to do this, it requires guesswork.

What you can't do without!

What you can't do without!

Symbols conjunction: A /\ B , A  B , AB , A &B, A and B disjunction: A \ / B , A + B , A | B , A or B negation:  A , A, not A equivalence: A  B, A  B, A  B exclusive “or”: A  B , A xor B

Variable replacement method How many different sets of values ​​of logical variables x1, x2, ..., x9, x10 exist that satisfy all the conditions listed below: ((x1 ≡ x2) \/ (x3 ≡ x4)) /\ ​​(¬(x1 ≡ x2) \/ ¬(x3 ≡ x4)) = 1 ((x3 ≡ x4) \/ (x5 ≡ x6)) /\ ​​(¬(x3 ≡ x4) \/ ¬(x5 ≡ x6)) = 1 ((x5 ≡ x6 ) \/ (x7 ≡ x8)) /\ ​​(¬(x5 ≡ x7) \/ ¬(x7 ≡ x8)) = 1 ((x7 ≡ x8) \/ (x9 ≡ x10)) /\ ​​(¬(x7 ≡ x8) \/ ¬(x9 ≡ x10)) = 1 The answer does not need to list all the different sets x1, x2, …, x9, x10 for which this system of equalities holds. As an answer, you must indicate the number of such sets (demo version 2012)

Solution Step 1. Simplify by changing variables t1 = x1  x2 t2 = x3  x4 t3 = x5  x6 t4 = x7  x8 t5 = x9  x10 After simplification: (t1 \/ t2) /\ (¬t1 \/ ¬ t2) =1 (t2 \/ t3) /\ (¬t2 \/ ¬ t3) =1 (t3 \/ t4) /\ (¬t3 \/ ¬ t4) =1 (t4 \/ t5) /\ ( ¬t4 \/ ¬ t5) =1 Consider one of the equations: (t1 \/ t2) /\ (¬t1 \/ ¬ t2) =1 Obviously, it =1 only if one of the variables is 0 and the other is 1. Let's use the formula to express the XOR operation through conjunction and disjunction: (t1 \/ t2) /\ (¬t1 \/ ¬ t2) = t1  t2 = ¬(t1 ≡ t2) =1 ¬(t1 ≡ t2) =1 ¬( t2 ≡ t3) =1 ¬(t3 ≡ t4) =1 ¬(t4 ≡ t5) =1

Step2. System analysis ¬(t1 ≡ t2) =1 ¬(t2 ≡ t3) =1 ¬(t3 ≡ t4) =1 ¬(t4 ≡ t5) =1 t1 t2 t3 t4 t5 0 1 0 1 0 1 0 1 0 1 Т .To. tk = x2k-1 ≡ x2k (t1 = x1  x2 ,….), then each value of tk corresponds to two pairs of values ​​x2k-1 and x2k, for example: tk =0 corresponds to two pairs - (0,1) and (1, 0) , and tk =1 – pairs (0,0) and (1,1).

Step3. Counting the number of solutions. Each t has 2 solutions, the number of ts is 5. Thus. for variables t there are 2 5 = 32 solutions. But for each t there corresponds a pair of solutions x, i.e. the original system has 2*32 = 64 solutions. Answer: 64

Method of eliminating part of the solutions How many different sets of values ​​of logical variables x1, x2, ..., x5, y1,y2,..., y5 exist that satisfy all the conditions listed below: (x1→ x2)∧(x2→ x3)∧(x3→ x4 )∧(x4→ x5) =1; (y1→ y2)∧(y2→ y3)∧(y3→ y4) ∧(y4→ y5) =1; y5→ x5 =1. The answer does not need to list all the different sets x1, x2, ..., x5, y 1 , y2, ... , y5 for which this system of equalities holds. The answer must indicate the number of such sets.

Solution. Step 1. Sequential solution of the equations x1 1 0 x2 1 0 1 x3 1 0 1 1 x4 1 0 1 1 1 x5 1 0 1 1 1 1 The first equation is the conjunction of several operations of implication, equal to 1, i.e. each of the implications is true. The implication is false only in one case, when 1  0, in all other cases (0  0, 0  1, 1  1) the operation returns 1. Let's write this in table form:

Step 1. Sequential solution of equations T.o. 6 sets of solutions were obtained for x1, x2, x3, x4, x5: (00000), (00001), (00011), (00111), (01111), (11111). Reasoning similarly, we come to the conclusion that for y1, y2, y3, y4, y5 there is the same set of solutions. Because these equations are independent, i.e. they do not have common variables, then the solution to this system of equations (without taking into account the third equation) will be 6 * 6 = 36 pairs of “X’s” and “Y’s”. Consider the third equation: y5→ x5 =1 The solution is the pairs: 0 0 0 1 1 1 The pair is not a solution: 1 0

Let's compare the solutions obtained. Where y5 =1, x5=0 is not suitable. there are 5 such pairs. Number of solutions to the system: 36-5= 31. Answer: 31 Combinatorics was needed!!!

Dynamic programming method How many various solutions has a logical equation x 1 → x 2 → x 3 → x 4 → x 5 → x 6 = 1, where x 1, x 2, …, x 6 are logical variables? The answer does not need to list all the different sets of variable values ​​for which this equality holds. As an answer, you need to indicate the quantities of such sets.

Solution Step1. Analysis of the condition On the left in the equation the operations of implication are written sequentially, the priority is the same. Let's rewrite: ((((X 1 → X 2) → X 3) → X 4) → X 5) → X 6 = 1 NB! Each subsequent variable depends not on the previous one, but on the result of the previous implication!

Step2. Revealing the pattern Let's consider the first implication, X 1 → X 2. Truth table: X 1 X 2 X 1 → X 2 0 0 1 0 1 1 1 0 0 1 1 1 From one 0 we got 2 units, and from 1 we got one 0 and one 1. There is only one 0 and three 1s, this is the result of the first operation.

Step2. Revealing a pattern By connecting x 3 to the result of the first operation, we get: F(x 1 ,x 2) x 3 F(x 1 ,x 2)  x 3 0 0 1 0 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 From two 0 – two 1, from each 1 (there are 3) one 0 and one 1 (3+3)

Step 3. Derivation of the formula T.o. you can create formulas for calculating the number of zeros N i and the number of ones E i for an equation with i variables: ,

Step 4. Filling out the table Let's fill out the table from left to right for i = 6, calculating the number of zeros and ones using the above formulas; the table shows how the next column is built from the previous one: number of variables 1 2 3 4 5 6 Number of zeros N i 1 1 3 5 11 21 Number of ones E i 1 2*1+1= 3 2*1+3= 5 11 21 43 Answer: 43

Method using simplifications of logical expressions How many different solutions does the equation have ((J → K) → (M  N  L))  ((M  N  L) → (¬ J  K))  (M → J) = 1 where J, K, L, M, N are logical variables? The answer does not need to list all the different sets of values ​​of J, K, L, M and N for which this equality holds. As an answer, you need to indicate the number of such sets.

Solution Note that J → K = ¬ J  K Let’s introduce a change of variables: J → K=A, M  N  L =B Let’s rewrite the equation taking into account the change: (A → B)  (B → A)  (M → J)=1 4. (A  B)  (M → J)= 1 5. Obviously, A  B for the same values ​​of A and B 6. Consider the last implication M → J =1 This is possible if: M= J=0 M=0, J=1 M=J=1

Solution Because A  B, then When M=J=0 we get 1 + K=0. No solutions. When M=0, J=1 we get 0 + K=0, K=0, and N and L are any, 4 solutions: ¬ J  K = M  N  L K N L 0 0 0 0 0 1 0 1 0 0 1 1

Solution 10. When M=J=1 we get 0+K=1 *N * L, or K=N*L, 4 solutions: 11. Total has 4+4=8 solutions Answer: 8 K N L 0 0 0 0 0 1 0 1 0 1 1 1

Sources of information: O.B. Bogomolova, D.Yu. Usenkov. B15: new tasks and new solutions // Informatics, No. 6, 2012, p. 35 – 39. K.Yu. Polyakov. Logical equations // Informatics, No. 14, 2011, p. 30-35. http://ege-go.ru/zadania/grb/b15/, [Electronic resource]. http://kpolyakov.narod.ru/school/ege.htm, [Electronic resource].


Let be a logical function of n variables. The logical equation looks like:

The constant C has the value 1 or 0.

A logical equation can have from 0 to different solutions. If C is equal to 1, then the solutions are all those sets of variables from the truth table for which the function F takes the value true (1). The remaining sets are solutions of the equation with C equal to zero. You can always consider only equations of the form:

Indeed, let the equation be given:

In this case, we can go to the equivalent equation:

Consider a system of k logical equations:

The solution to a system is a set of variables on which all equations of the system are satisfied. In terms of logical functions, to obtain a solution to a system of logical equations, one should find a set on which the logical function Ф is true, representing the conjunction of the original functions:

If the number of variables is small, for example, less than 5, then it is not difficult to construct a truth table for the function, which allows us to say how many solutions the system has and what are the sets that provide solutions.

In some USE problems on finding solutions to a system of logical equations, the number of variables reaches 10. Then constructing a truth table becomes an almost impossible task. Solving the problem requires a different approach. For an arbitrary system of equations there are no general method, different from brute force, which allows solving such problems.

In the problems proposed on the exam, the solution is usually based on taking into account the specifics of the system of equations. I repeat, apart from trying out all the options for a set of variables, there is no general way to solve the problem. The solution must be built based on the specifics of the system. It is often useful to carry out a preliminary simplification of a system of equations using known laws of logic. Another useful technique for solving this problem is as follows. We are not interested in all sets, but only those on which the function has the value 1. Instead of building a complete truth table, we will build its analogue - a binary decision tree. Each branch of this tree corresponds to one solution and specifies a set on which the function has the value 1. The number of branches in the decision tree coincides with the number of solutions to the system of equations.

I will explain what a binary decision tree is and how it is built using examples of several problems.

Problem 18

How many different sets of values ​​of the logical variables x1, x2, x3, x4, x5, y1, y2, y3, y4, y5 are there that satisfy the system of two equations?

Answer: The system has 36 different solutions.

Solution: The system of equations includes two equations. Let's find the number of solutions for the first equation, depending on 5 variables - . The first equation can in turn be considered as a system of 5 equations. As has been shown, the system of equations actually represents the conjunction of logical functions. The converse statement is also true - a conjunction of conditions can be considered as a system of equations.

Let's build a decision tree for implication () - the first term of the conjunction, which can be considered as the first equation. This is what it looks like graphic image this tree


The tree consists of two levels according to the number of variables in the equation. The first level describes the first variable. Two branches of this level reflect the possible values ​​of this variable - 1 and 0. At the second level, the branches of the tree reflect only those possible values ​​of the variable for which the equation evaluates to true. Since the equation specifies an implication, a branch on which has the value 1 requires that on this branch there be a value of 1. A branch on which has the value 0 generates two branches with values ​​equal to 0 and 1. The constructed tree specifies three solutions, on of which the implication takes the value 1. On each branch, a corresponding set of variable values ​​is written out, giving a solution to the equation.

These sets are: ((1, 1), (0, 1), (0, 0))

Let's continue building the decision tree by adding the following equation, the following implication. The specificity of our system of equations is that each new equation of the system uses one variable from the previous equation, adding one new variable. Since the variable already has values ​​in the tree, then on all branches where the variable has a value of 1, the variable will also have a value of 1. For such branches, the construction of the tree continues to the next level, but no new branches appear. A single branch where a variable has a value of 0 will branch into two branches where the variable will receive values ​​of 0 and 1. Thus, each addition of a new equation, given its specificity, adds one solution. Original first equation:

has 6 solutions. Here's what the complete decision tree for this equation looks like:


The second equation of our system is similar to the first:

The only difference is that the equation uses Y variables. This equation also has 6 solutions. Since every variable solution can be combined with every variable solution, then total number There are 36 solutions.

Please note that the constructed decision tree gives not only the number of solutions (according to the number of branches), but also the solutions themselves written on each branch of the tree.

Problem 19

How many different sets of values ​​of the logical variables x1, x2, x3, x4, x5, y1, y2, y3, y4, y5 are there that satisfy all the conditions listed below?

This task is a modification of the previous task. The difference is that another equation is added that relates the variables X and Y.

It follows from the equation that when has a value of 1 (one such solution exists), then it has a value of 1. Thus, there is one set on which and have values ​​of 1. When equal to 0, it can have any value, both 0 and and 1. Therefore, each set with , equal to 0, and there are 5 such sets, corresponds to all 6 sets with variables Y. Therefore, the total number of solutions is 31.

Problem 20

Solution: Remembering the basic equivalences, we write our equation as:

The cyclic chain of implications means that the variables are identical, so our equation is equivalent to the equation:

This equation has two solutions when all are either 1 or 0.

Problem 21

How many solutions does the equation have:

Solution: Just as in problem 20, we move from cyclic implications to identities, rewriting the equation in the form:

Let's build a decision tree for this equation:


Problem 22

How many solutions does the following system of equations have?

How to solve some problems in sections A and B of the computer science exam

Lesson #3. Logics. Logic functions. Solving equations

A large number of Unified State Exam problems are devoted to propositional logic. To solve most of them, it is enough to know the basic laws of propositional logic, knowledge of the truth tables of logical functions of one and two variables. I will give the basic laws of propositional logic.

  1. Commutativity of disjunction and conjunction:
    a ˅ b ≡ b ˅ a
    a^b ≡ b^a
  2. Distributive law regarding disjunction and conjunction:
    a ˅ (b^с) ≡ (a ˅ b) ^(a ˅ с)
    a ^ (b ˅ c) ≡ (a ^ b) ˅ (a ^ c)
  3. Negation of negation:
    ¬(¬a) ≡ a
  4. Consistency:
    a ^ ¬а ≡ false
  5. Exclusive third:
    a ˅ ¬а ≡ true
  6. De Morgan's laws:
    ¬(a ˅ b) ≡ ¬a ˄ ¬b
    ¬(a ˄ b) ≡ ¬a ˅ ¬b
  7. Simplification:
    a ˄ a ≡ a
    a ˅ a ≡ a
    a ˄ true ≡ a
    a ˄ false ≡ false
  8. Absorption:
    a ˄ (a ˅ b) ≡ a
    a ˅ (a ˄ b) ≡ a
  9. Replacement of implication
    a → b ≡ ¬a ˅ b
  10. Replacement of identity
    a ≡ b ≡(a ˄ b) ˅ (¬a ˄ ¬b)

Representation of logical functions

Any logical function of n variables - F(x 1, x 2, ... x n) can be specified by a truth table. Such a table contains 2n sets of variables, for each of which the value of a function on this set is specified. This method is good when the number of variables is relatively small. Already for n > 5 the representation becomes poorly visible.

Another way is to define the function by some formula using known fairly simple functions. A system of functions (f 1, f 2, ... f k) is called complete if any logical function can be expressed by a formula containing only functions f i.

The system of functions (¬, ˄, ˅) is complete. Laws 9 and 10 are examples demonstrating how implication and identity are expressed through negation, conjunction and disjunction.

In fact, a system of two functions – negation and conjunction or negation and disjunction – is also complete. From De Morgan's laws follow ideas that allow one to express a conjunction through negation and disjunction and, accordingly, to express a disjunction through negation and conjunction:

(a ˅ b) ≡ ¬(¬a ˄ ¬b)
(a ˄ b) ≡ ¬(¬a ˅ ¬b)

Paradoxically, a system consisting of just one function is complete. There are two binary functions - anticonjunction and antidisjunction, called the Peirce arrow and the Schaeffer stroke, representing a hollow system.

The basic functions of programming languages ​​usually include identity, negation, conjunction and disjunction. In Unified State Examination problems, along with these functions, implication is often found.

Let's look at a few simple problems involving logical functions.

Problem 15:

A fragment of the truth table is given. Which of the three functions given corresponds to this fragment?

X 1 X 2 X 3 X 4 F
1 1 0 0 1
0 1 1 1 1
1 0 0 1 0
  1. (X 1 → X 2) ˄ ¬ X 3 ˅ X 4
  2. (¬ X 1 ˄ X 2) ˅ (¬ X 3 ˄ X 4)
  3. ¬ X 1 ˅ X 2 ˅ (X 3 ˄ X 4)

Function number 3.

To solve the problem, you need to know the truth tables of basic functions and remember the priorities of operations. Let me remind you that conjunction (logical multiplication) has higher priority and is executed earlier than disjunction (logical addition). During calculations, it is easy to notice that functions with numbers 1 and 2 in the third set have the value 1 and for this reason do not correspond to the fragment.

Problem 16:

Which of the given numbers satisfies the condition:

(digits, starting from the most significant digit, are in descending order) → (number - even) ˄ (low digit - even) ˄ (high digit - odd)

If there are several such numbers, indicate the largest.

  1. 13579
  2. 97531
  3. 24678
  4. 15386

The condition is satisfied by the number number 4.

The first two numbers do not satisfy the condition for the reason that the lowest digit is odd. A conjunction of conditions is false if one of the terms of the conjunction is false. For the third number, the condition for the highest digit is not met. For the fourth number, the conditions imposed on the low and high digits of the number are met. The first term of the conjunction is also true, since the implication is true if its premise is false, which is the case in in this case.

Problem 17: Two witnesses gave the following testimony:

First witness: If A is guilty, then B is even more guilty, and C is innocent.

Second witness: Two are guilty. And one of the remaining ones is definitely guilty and guilty, but I can’t say who exactly.

What conclusions about the guilt of A, B and C can be drawn from the testimony?

Answer: From the testimony it follows that A and B are guilty, and C is innocent.

Solution: Of course, the answer can be given based on common sense. But let's look at how this can be done strictly and formally.

The first thing to do is to formalize the statements. Let's introduce three logical variables - A, B and C, each of which has the value true (1) if the corresponding suspect is guilty. Then the testimony of the first witness is given by the formula:

A → (B ˄ ¬C)

The testimony of the second witness is given by the formula:

A ˄ ((B ˄ ¬C) ˅ (¬B ˄ C))

The testimony of both witnesses is assumed to be true and represents the conjunction of the corresponding formulas.

Let's build a truth table for these readings:

A B C F 1 F 2 F 1 ˄ F 2
0 0 0 1 0 0
0 0 1 1 0 0
0 1 0 1 0 0
0 1 1 1 0 0
1 0 0 0 0 0
1 0 1 0 1 0
1 1 0 1 1 1
1 1 1 0 0 0

The summary evidence is true in only one case, leading to a clear answer - A and B are guilty, and C is innocent.

From the analysis of this table it also follows that the testimony of the second witness is more informative. From the truth of his testimony, only two possible options follow - A and B are guilty, and C is innocent, or A and C are guilty, and B is innocent. The testimony of the first witness is less informative - there are 5 various options, corresponding to his testimony. Together, the testimony of both witnesses gives a clear answer about the guilt of the suspects.

Logical equations and systems of equations

Let F(x 1, x 2, …x n) be a logical function of n variables. The logical equation looks like:

F(x 1, x 2, …x n) = C,

The constant C has the value 1 or 0.

A logical equation can have from 0 to 2 n different solutions. If C is equal to 1, then the solutions are all those sets of variables from the truth table for which the function F takes the value true (1). The remaining sets are solutions of the equation with C equal to zero. You can always consider only equations of the form:

F(x 1 , x 2 , …x n) = 1

Indeed, let the equation be given:

F(x 1, x 2, …x n) = 0

In this case, we can go to the equivalent equation:

¬F(x 1 , x 2 , …x n) = 1

Consider a system of k logical equations:

F 1 (x 1, x 2, …x n) = 1

F 2 (x 1, x 2, …x n) = 1

F k (x 1 , x 2 , …x n) = 1

The solution to a system is a set of variables on which all equations of the system are satisfied. In terms of logical functions, to obtain a solution to a system of logical equations, one should find a set on which the logical function Ф is true, representing the conjunction of the original functions F:

Ф = F 1 ˄ F 2 ˄ … F k

If the number of variables is small, for example, less than 5, then it is not difficult to construct a truth table for the function Ф, which allows us to say how many solutions the system has and what are the sets that provide solutions.

In some USE problems on finding solutions to a system of logical equations, the number of variables reaches 10. Then constructing a truth table becomes an almost impossible task. Solving the problem requires a different approach. For an arbitrary system of equations, there is no general method other than enumeration that allows solving such problems.

In the problems proposed on the exam, the solution is usually based on taking into account the specifics of the system of equations. I repeat, apart from trying out all the options for a set of variables, there is no general way to solve the problem. The solution must be built based on the specifics of the system. It is often useful to carry out a preliminary simplification of a system of equations using known laws of logic. Another useful technique for solving this problem is as follows. We are not interested in all sets, but only those on which the function Ф has the value 1. Instead of building a complete truth table, we will build its analogue - a binary decision tree. Each branch of this tree corresponds to one solution and specifies a set on which the function Ф has the value 1. The number of branches in the decision tree coincides with the number of solutions to the system of equations.

I will explain what a binary decision tree is and how it is built using examples of several problems.

Problem 18

How many different sets of values ​​of the logical variables x1, x2, x3, x4, x5, y1, y2, y3, y4, y5 are there that satisfy the system of two equations?

Answer: The system has 36 different solutions.

Solution: The system of equations includes two equations. Let's find the number of solutions for the first equation, depending on 5 variables - x 1, x 2, ...x 5. The first equation can in turn be considered as a system of 5 equations. As has been shown, the system of equations actually represents the conjunction of logical functions. The converse is also true: a conjunction of conditions can be considered as a system of equations.

Let's build a decision tree for the implication (x1→ x2) - the first term of the conjunction, which can be considered as the first equation. This is what a graphical representation of this tree looks like:

The tree consists of two levels according to the number of variables in the equation. The first level describes the first variable X 1 . Two branches of this level reflect the possible values ​​of this variable - 1 and 0. At the second level, the branches of the tree reflect only those possible values ​​of the variable X 2 for which the equation is true. Since the equation specifies an implication, a branch on which X 1 has the value 1 requires that on that branch X 2 has the value 1. A branch on which X 1 has the value 0 produces two branches with the values ​​of X 2 equal to 0 and 1 The constructed tree defines three solutions, on which the implication X 1 → X 2 takes the value 1. On each branch, a corresponding set of variable values ​​is written out, giving a solution to the equation.

These sets are: ((1, 1), (0, 1), (0, 0))

Let's continue building the decision tree by adding the following equation, the following implication X 2 → X 3 . The specificity of our system of equations is that each new equation of the system uses one variable from the previous equation, adding one new variable. Since the variable X 2 already has values ​​in the tree, then on all branches where the variable X 2 has a value of 1, the variable X 3 will also have a value of 1. For such branches, the construction of the tree continues to the next level, but new branches do not appear. The single branch where the variable X 2 has the value 0 will branch into two branches where the variable X 3 will receive the values ​​0 and 1. Thus, each addition of a new equation, given its specifics, adds one solution. Original first equation:

(x1→x2) /\ (x2→x3) /\ (x3→x4) /\ (x4→x5) = 1
has 6 solutions. Here's what the complete decision tree for this equation looks like:

The second equation of our system is similar to the first:

(y1→y2) /\ (y2→y3) /\ (y3→y4) /\ (y4→y5) = 1

The only difference is that the equation uses Y variables. This equation also has 6 solutions. Since each solution for the variables X i can be combined with each solution for the variables Y j , the total number of solutions is 36.

Please note that the constructed decision tree gives not only the number of solutions (according to the number of branches), but also the solutions themselves written on each branch of the tree.

Problem 19

How many different sets of values ​​of the logical variables x1, x2, x3, x4, x5, y1, y2, y3, y4, y5 are there that satisfy all the conditions listed below?

(x1→x2) /\ (x2→x3) /\ (x3→x4) /\ (x4→x5) = 1
(y1→y2) /\ (y2→y3) /\ (y3→y4) /\ (y4→y5) = 1
(x1→ y1) = 1

This task is a modification of the previous task. The difference is that another equation is added that relates the variables X and Y.

From the equation X 1 → Y 1 it follows that when X 1 has the value 1 (one such solution exists), then Y 1 also has the value 1. Thus, there is one set on which X 1 and Y 1 have the values ​​1. When X 1 equal to 0, Y 1 can have any value, both 0 and 1. Therefore, each set with X 1 equal to 0, and there are 5 such sets, corresponds to all 6 sets with Y variables. Therefore, the total number of solutions is 31 .

Problem 20

(¬X 1 ˅ X 2) ˄ (¬X 2 ˅ X 3) ˄ (¬X 3 ˅ X 4) ˄ (¬X 4 ˅ X 5) ˄ (¬X 5 ˅ X 1) = 1

Solution: Remembering the basic equivalences, we write our equation as:

(X 1 → X 2) ˄ (X 2 → X 3) ˄ (X 3 → X 4) ˄ (X 4 → X 5) ˄ (X 5 → X 1) = 1

The cyclic chain of implications means that the variables are identical, so our equation is equivalent to the equation:

X 1 ≡ X 2 ≡ X 3 ≡ X 4 ≡ X 5 = 1

This equation has two solutions when all X i are either 1 or 0.

Problem 21

(X 1 → X 2) ˄ (X 2 → X 3) ˄ (X 3 → X 4) ˄ (X 4 → X 2) ˄ (X 4 → X 5) = 1

Solution: Just as in problem 20, we move from cyclic implications to identities, rewriting the equation in the form:

(X 1 → X 2) ˄ (X 2 ≡ X 3 ≡ X 4) ˄ (X 4 → X 5) = 1

Let's build a decision tree for this equation:

Problem 22

How many solutions does the following system of equations have?

((X 1 ≡X 2) ˄ (X 3 ≡X 4)) ˅(¬(X 1 ≡X 2) ˄ ¬(X 3 ≡X 4)) = 0

((X 3 ≡X 4) ˄ (X 5 ≡X 6)) ˅(¬(X 3 ≡X 4) ˄ ¬(X 5 ≡X 6)) = 0

((X 5 ≡X 6) ˄ (X 7 ≡X 8)) ˅(¬(X 5 ≡X 6) ˄ ¬(X 7 ≡X 8)) = 0

((X 7 ≡X 8) ˄ (X 9 ≡X 10)) ˅(¬(X 7 ≡X 8) ˄ ¬(X 9 ≡X 10)) = 0

Answer: 64

Solution: Let's move from 10 variables to 5 variables by introducing the following change of variables:

Y 1 = (X 1 ≡ X 2); Y 2 = (X 3 ≡ X 4); Y 3 = (X 5 ≡ X 6); Y 4 = (X 7 ≡ X 8); Y 5 = (X 9 ≡ X 10);

Then the first equation will take the form:

(Y 1 ˄ Y 2) ˅ (¬Y 1 ˄ ¬Y 2) = 0

The equation can be simplified by writing it as:

(Y 1 ≡ Y 2) = 0

Moving on to traditional form, we write the system after simplifications in the form:

¬(Y 1 ≡ Y 2) = 1

¬(Y 2 ≡ Y 3) = 1

¬(Y 3 ≡ Y 4) = 1

¬(Y 4 ≡ Y 5) = 1

The decision tree for this system is simple and consists of two branches with alternating variable values:


Returning to the original X variables, note that for each value in the Y variable there are 2 values ​​in the X variables, so each solution in the Y variables generates 2 5 solutions in the X variables. The two branches generate 2 * 2 5 solutions, so the total number of solutions is 64.

As you can see, each problem of solving a system of equations requires its own approach. General reception is to perform equivalent transformations to simplify equations. A common technique is to construct decision trees. The approach used is partially reminiscent of constructing a truth table with the peculiarity that not all sets are constructed possible values variables, but only those on which the function takes the value 1 (true). Often in the proposed problems there is no need to build a complete decision tree, since already initial stage it is possible to establish a pattern of the appearance of new branches at each subsequent level, as was done, for example, in problem 18.

In general, problems involving finding solutions to a system of logical equations are good mathematical exercises.

If the problem is difficult to solve manually, then you can entrust the solution to the computer by writing an appropriate program for solving equations and systems of equations.

It is not difficult to write such a program. Such a program will easily cope with all the tasks offered in the Unified State Exam.

Oddly enough, the task of finding solutions to systems of logical equations is difficult for a computer, and it turns out that a computer has its limits. A computer can quite easily cope with tasks where the number of variables is 20-30, but it will begin to think about problems for a long time bigger size. The fact is that the function 2 n, which specifies the number of sets, is an exponential that grows rapidly as n increases. So fast that an ordinary personal computer cannot cope with a task that has 40 variables in a day.

Program in C# language for solving logical equations

Writing a program for solving logical equations is useful for many reasons, if only because you can use it to check the correctness of your own solution to Unified State Exam test problems. Another reason is that such a program is an excellent example of a programming task that meets the requirements for category C tasks in the Unified State Exam.

The idea of ​​building a program is simple - it is based on a complete search of all possible sets of variable values. Since for a given logical equation or system of equations the number of variables n is known, then the number of sets is also known - 2 n which need to be sorted out. Using the basic functions of the C# language - negation, disjunction, conjunction and identity, it is not difficult to write a program that, for a given set of variables, calculates the value of the logical function corresponding to a logical equation or system of equations.

In such a program, you need to build a loop based on the number of sets, in the body of the loop, using the number of the set, form the set itself, calculate the value of the function on this set, and if this value is 1, then the set gives a solution to the equation.

The only difficulty that arises when implementing the program is related to the task of generating the set of variable values ​​itself based on the set number. The beauty of this problem is that this seemingly difficult task actually comes down to a simple problem that has already arisen many times. Indeed, it is enough to understand that the set of variable values ​​corresponding to the number i, consisting of zeros and ones, represents the binary representation of the number i. So difficult task obtaining a set of variable values ​​by set number comes down to the well-known problem of converting a number to the binary system.

This is what a function in C# looks like that solves our problem:

///

/// program for counting the number of solutions

/// logical equation (system of equations)

///

///

/// logical function - method,

/// whose signature is specified by the DF delegate

///

/// number of variables

/// number of solutions

static int SolveEquations(DF fun, int n)

bool set = new bool[n];

int m = (int)Math.Pow(2, n); //number of sets

int p = 0, q = 0, k = 0;

//Complete search by number of sets

for (int i = 0; i< m; i++)

//Formation of the next set - set,

//specified by the binary representation of the number i

for (int j = 0; j< n; j++)

k = (int)Math.Pow(2, j);

//Calculate the value of the function on the set

To understand the program, I hope the explanations of the program's idea and comments in its text are sufficient. I will only focus on explaining the title of the given function. The SolveEquations function has two input parameters. The fun parameter specifies a logical function corresponding to the equation or system of equations being solved. The n parameter specifies the number function variables fun. As a result, the SolveEquations function returns the number of solutions of the logical function, that is, the number of those sets on which the function evaluates to true.

It is common for schoolchildren when some function F(x) has an input parameter x that is a variable of arithmetic, string or logical type. In our case, a more powerful design is used. The SolveEquations function belongs to the functions higher order– functions of type F(f), whose parameters can be not only simple variables, but also functions.

The class of functions that can be passed as a parameter to the SolveEquations function is specified as follows:

delegate bool DF(bool vars);

This class owns all functions that are passed as a parameter a set of values ​​of logical variables specified by the vars array. The result is a Boolean value representing the value of the function on this set.

Finally, here is a program that uses the SolveEquations function to solve several systems of logical equations. The SolveEquations function is part of the ProgramCommon class below:

class ProgramCommon

delegate bool DF(bool vars);

static void Main(string args)

Console.WriteLine("And Functions - " +

SolveEquations(FunAnd, 2));

Console.WriteLine("The Function has 51 solutions - " +

SolveEquations(Fun51, 5));

Console.WriteLine("The Function has 53 solutions - " +

SolveEquations(Fun53, 10));

static bool FunAnd(bool vars)

return vars && vars;

static bool Fun51(bool vars)

f = f && (!vars || vars);

f = f && (!vars || vars);

f = f && (!vars || vars);

f = f && (!vars || vars);

f = f && (!vars || vars);

static bool Fun53(bool vars)

f = f && ((vars == vars) || (vars == vars));

f = f && ((vars == vars) || (vars == vars));

f = f && ((vars == vars) || (vars == vars));

f = f && ((vars == vars) || (vars == vars));

f = f && ((vars == vars) || (vars == vars));

f = f && ((vars == vars) || (vars == vars));

f = f && (!((vars == vars) || (vars == vars)));

Here's what the solution results for this program look like:

10 tasks for independent work

  1. Which of the three functions are equivalent:
    1. (X → Y) ˅ ¬Y
    2. ¬(X ˅ ¬Y) ˄ (X → ¬Y)
    3. ¬X ˄Y
  2. Given is a fragment of the truth table:
X 1 X 2 X 3 X 4 F
1 0 0 1 1
0 1 1 1 1
1 0 1 0 0

Which of the three functions does this fragment correspond to:

  1. (X 1 ˅ ¬X 2) ˄ (X 3 → X 4)
  2. (X 1 → X 3) ˄ X 2 ˅ X 4
  3. X 1 ˄ X 2 ˅ (X 3 → (X 1 ˅ X 4))
  4. The jury consists of three people. The decision is made if the chairman of the jury votes for it, supported by at least one of the jury members. Otherwise, no decision is made. Construct a logical function that formalizes the decision-making process.
  5. X wins over Y if four coin tosses result in heads three times. Define a logical function that describes the payoff of X.
  6. Words in a sentence are numbered starting from one. A sentence is considered correctly constructed if the following rules are met:
    1. If an even-numbered word ends with a vowel, then the next word, if it exists, must begin with a vowel.
    2. If an odd-numbered word ends with a consonant, then the next word, if it exists, must begin with a consonant and end with a vowel.
      Which of the following sentences are correctly constructed:
    3. Mom washed Masha with soap.
    4. A leader is always a model.
    5. Truth is good, but happiness is better.
  7. How many solutions does the equation have:
    (a ˄ ¬ b) ˅ (¬a ˄ b) → (c ˄ d) = 1
  8. List all solutions to the equation:
    (a → b) → c = 0
  9. How many solutions does the following system of equations have:
    X 0 → X 1 ˄ X 1 → X 2 = 1
    X 2 → X 3 ˄ X 3 → X 4 = 1
    X 5 → X 6 ˄ X 6 → X 7 = 1
    X 7 → X 8 ˄ X 8 → X 9 = 1
    X 0 → X 5 = 1
  10. How many solutions does the equation have:
    ((((X 0 → X 1) → X 2) → X 3) →X 4) →X 5 = 1

Answers to problems:

  1. The functions b and c are equivalent.
  2. The fragment corresponds to function b.
  3. Let the logical variable P take the value 1 when the chairman of the jury votes “for” the decision. Variables M 1 and M 2 represent the opinions of the jury members. The logical function that specifies making a positive decision can be written as follows:
    P ˄ (M 1 ˅ M 2)
  4. Let the logical variable P i take the value 1 when the i-th coin toss lands on heads. The logical function that specifies the payoff X can be written as follows:
    ¬((¬P 1 ˄ (¬P 2 ˅ ¬P 3 ˅ ¬P 4)) ˅
    (¬P 2 ˄ (¬P 3 ˅ ¬P 4)) ˅
    (¬P 3 ˄ ¬P 4))
  5. Sentence b.
  6. The equation has 3 solutions: (a = 1; b = 1; c = 0); (a = 0; b = 0; c = 0); (a = 0; b = 1; c = 0)

Methods for solving systems of logical equations

Kirgizova E.V., Nemkova A.E.

Lesosibirsk Pedagogical Institute –

branch of Siberian Federal University, Russia

The ability to think consistently, reason convincingly, build hypotheses, and refute negative conclusions does not come on its own; this skill is developed by the science of logic. Logic is a science that studies methods for establishing the truth or falsity of some statements on the basis of the truth or falsity of other statements.

Mastering the basics of this science is impossible without solving logical problems. Testing the development of skills to apply one's knowledge in a new situation is carried out through passing. In particular, this is the ability to decide logic problems. Tasks B15 in the Unified State Examination are tasks of increased complexity, since they contain systems of logical equations. You can select various ways solving systems of logical equations. This is reduction to one equation, construction of a truth table, decomposition, sequential solution of equations, etc.

Task:Solve a system of logical equations:

Let's consider reduction method to one equation . This method involves transforming logical equations so that their right-hand sides are equal to the truth value (that is, 1). To do this, use the logical negation operation. Then, if the equations contain complex logical operations, we replace them with basic ones: “AND”, “OR”, “NOT”. The next step is to combine the equations into one, equivalent to the system, using the logical operation “AND”. After this, you should transform the resulting equation based on the laws of logical algebra and get specific solution systems.

Solution 1:Apply inversion to both sides of the first equation:

Let’s imagine the implication through the basic operations “OR” and “NOT”:

Since the left sides of the equations are equal to 1, we can combine them using the “AND” operation into one equation that is equivalent to the original system:

We open the first bracket according to De Morgan's law and transform the result obtained:

The resulting equation has one solution: A= 0, B =0 and C =1.

The next method is constructing truth tables . Since logical quantities have only two values, you can simply go through all the options and find among them those for which a given system of equations is satisfied. That is, we are building one general table truth for all equations of the system and find the line with the required values.

Solution 2:Let's create a truth table for the system:

0

0

1

1

0

1

The line for which the task conditions are met is highlighted in bold. So A =0, B =0 and C =1.

Way decomposition . The idea is to fix the value of one of the variables (set it equal to 0 or 1) and thereby simplify the equations. Then you can fix the value of the second variable, and so on.

Solution 3: Let A = 0, then:

From the first equation we get B =0, and from the second – C=1. Solution of the system: A = 0, B = 0 and C = 1.

You can also use the method sequential solution of equations , at each step adding one variable to the set under consideration. To do this, it is necessary to transform the equations so that the variables are entered in alphabetical order. Next, we build a decision tree, sequentially adding variables to it.

The first equation of the system depends only on A and B, and the second equation on A and C. Variable A can take 2 values ​​0 and 1:


From the first equation it follows that , so when A = 0 and we get B = 0, and for A = 1 we have B = 1. So, the first equation has two solutions with respect to the variables A and B.

Let us depict the second equation, from which we determine the values ​​of C for each option. When A =1, the implication cannot be false, that is, the second branch of the tree has no solution. At A= 0 we get the only solution C= 1 :

Thus, we obtained the solution to the system: A = 0, B = 0 and C = 1.

In the Unified State Exam in computer science, it is very often necessary to determine the number of solutions to a system of logical equations, without finding the solutions themselves; there are also certain methods for this. The main way to find the number of solutions to a system of logical equations is replacing variables. First, you need to simplify each of the equations as much as possible based on the laws of logical algebra, and then replace the complex parts of the equations with new variables and determine the number of solutions new system. Next, return to the replacement and determine the number of solutions for it.

Task:How many solutions does the equation have ( A → B ) + (C → D ) = 1? Where A, B, C, D are logical variables.

Solution:Let's introduce new variables: X = A → B and Y = C → D . Taking into account new variable equation will be written in the form: X + Y = 1.

The disjunction is true in three cases: (0;1), (1;0) and (1;1), while X and Y is an implication, that is, it is true in three cases and false in one. Therefore, the case (0;1) will correspond to three possible combinations of parameters. Case (1;1) – will correspond to nine possible combinations of parameters of the original equation. So, total possible solutions of this equation 3+9=15.

The next way to determine the number of solutions to a system of logical equations is binary tree. Let's consider this method For example.

Task:How many different solutions does the system of logical equations have:

The given system of equations is equivalent to the equation:

( x 1 x 2 )*( x 2 x 3 )*…*( x m -1 x m) = 1.

Let's pretend thatx 1 – is true, then from the first equation we obtain thatx 2 also true, from the second -x 3 =1, and so on until x m= 1. So the set (1; 1; …; 1) of m units is the solution of the system. Let it nowx 1 =0, then from the first equation we havex 2 =0 or x 2 =1.

When x 2 true, we obtain that the remaining variables are also true, that is, the set (0; 1; ...; 1) is a solution to the system. Atx 2 =0 we get that x 3 =0 or x 3 =, and so on. Continuing to the last variable, we find that the solutions to the equation are the following sets of variables ( m +1 solution, in each solution m variable values):

(1; 1; 1; …; 1)

(0; 1; 1; …; 1)

(0; 0; 0; …; 0)

This approach is well illustrated by constructing a binary tree. The number of possible solutions is the number of different branches of the constructed tree. It is easy to see that it is equal m +1.

Variables

Tree

Number of solutions

x 1

x 2

x 3

In case of difficulties in reasoning and building a decision tree, you can search for a solution using truth tables, for one or two equations.

Let's rewrite the system of equations in the form:

And let’s create a truth table separately for one equation:

x 1

x 2

(x 1 → x 2)

Let's create a truth table for two equations:

x 1

x 2

x 3

x 1 → x 2

x 2 → x 3

(x 1 → x 2) * (x 2 → x 3)

Next, you can see that one equation is true in the following three cases: (0; 0), (0; 1), (1; 1). A system of two equations is true in four cases (0; 0; 0), (0; 0; 1), (0; 1; 1), (1; 1; 1). In this case, it is immediately clear that there is a solution consisting of only zeros and more m solutions in which one unit is added at a time, starting from the last position until all possible places are filled. It can be assumed that the general solution will have the same form, but for such an approach to become a solution, proof is required that the assumption is correct.

To summarize all of the above, I would like to draw your attention to the fact that not all of the methods discussed are universal. When solving each system of logical equations, one should take into account its features, on the basis of which the solution method should be chosen.

Literature:

1. Logical problems / O.B. Bogomolov – 2nd ed. – M.: BINOM. Laboratory of Knowledge, 2006. – 271 p.: ill.

2. Polyakov K.Yu. Systems of logical equations / Educational and methodological newspaper for computer science teachers: Informatics No. 14, 2011.

There are various ways to solve systems of logical equations. This is reduction to one equation, construction of a truth table and decomposition.

Task: Solve a system of logical equations:

Let's consider reduction method to one equation . This method involves transforming logical equations so that their right-hand sides are equal to the truth value (that is, 1). To do this, use the logical negation operation. Then, if the equations contain complex logical operations, we replace them with basic ones: “AND”, “OR”, “NOT”. The next step is to combine the equations into one, equivalent to the system, using the logical operation “AND”. After this, you should transform the resulting equation based on the laws of logical algebra and obtain a specific solution to the system.

Solution 1: Apply inversion to both sides of the first equation:

Let’s imagine the implication through the basic operations “OR” and “NOT”:

Since the left sides of the equations are equal to 1, we can combine them using the “AND” operation into one equation that is equivalent to the original system:

We open the first bracket according to De Morgan's law and transform the result obtained:

The resulting equation has one solution: A =0, B=0 and C=1.

The next method is constructing truth tables . Since logical quantities have only two values, you can simply go through all the options and find among them those for which a given system of equations is satisfied. That is, we build one common truth table for all equations of the system and find a line with the required values.

Solution 2: Let's create a truth table for the system:

0

0

1

1

0

1

The line for which the task conditions are met is highlighted in bold. So A=0, B=0 and C=1.

Way decomposition . The idea is to fix the value of one of the variables (set it equal to 0 or 1) and thereby simplify the equations. Then you can fix the value of the second variable, and so on.

Solution 3: Let A = 0, then:

From the first equation we get B = 0, and from the second - C = 1. Solution of the system: A = 0, B = 0 and C = 1.

In the Unified State Exam in computer science, it is very often necessary to determine the number of solutions to a system of logical equations, without finding the solutions themselves; there are also certain methods for this. The main way to find the number of solutions to a system of logical equations isreplacing variables. First, you need to simplify each of the equations as much as possible based on the laws of logical algebra, and then replace the complex parts of the equations with new variables and determine the number of solutions to the new system. Next, return to the replacement and determine the number of solutions for it.

Task: How many solutions does the equation (A →B) + (C →D) = 1 have? Where A, B, C, D are logical variables.

Solution: Let's introduce new variables: X = A →B and Y = C →D. Taking into account the new variables, the equation will be written as: X + Y = 1.

The disjunction is true in three cases: (0;1), (1;0) and (1;1), while X and Y are implications, that is, it is true in three cases and false in one. Therefore, the case (0;1) will correspond to three possible combinations of parameters. Case (1;1) – will correspond to nine possible combinations of parameters of the original equation. This means that the total possible solutions to this equation are 3+9=15.

The next way to determine the number of solutions to a system of logical equations is binary tree. Let's look at this method using an example.

Task: How many different solutions does the system of logical equations have:

The given system of equations is equivalent to the equation:

(x 1 x 2 )*(x 2 x 3 )*…*(x m -1 x m) = 1.

Let's pretend that x 1 – is true, then from the first equation we obtain that x 2 also true, from the second - x 3 =1, and so on until x m= 1. This means that the set (1; 1; …; 1) of m units is a solution to the system. Let it now x 1 =0, then from the first equation we have x 2 =0 or x 2 =1.

When x 2 true, we obtain that the remaining variables are also true, that is, the set (0; 1; ...; 1) is a solution to the system. At x 2 =0 we get that x 3 =0 or x 3 =, and so on. Continuing to the last variable, we find that the solutions to the equation are the following sets of variables (m +1 solution, each solution contains m values ​​of the variables):

(1; 1; 1; …; 1)

(0; 1; 1; …; 1)

(0; 0; 0; …; 0)

This approach is well illustrated by constructing a binary tree. The number of possible solutions is the number of different branches of the constructed tree. It is easy to see that it is equal to m +1.

Tree

Number of solutions

x 1

x 2

x 3

In case of difficulties in reasoning research and constructionof solutions you can search for a solution with using truth tables, for one or two equations.

Let's rewrite the system of equations in the form:

And let’s create a truth table separately for one equation:

x 1

x 2

(x 1 → x 2)

Let's create a truth table for two equations:

x 1

x 2

x 3

x 1 → x 2

x 2 → x 3

(x 1 → x 2) * (x 2 → x 3)