Logic variables of expression. "Logic quantities, operations, expressions. Rules for performing logical operations

Statement (judgment) - this is a narrative offer in which something is approved or denied. Regarding any statement, it can be said true or false. For example:

"Ice - solid state of water" - a true statement.

"Triangle, this geometric figure"- True statement.

"Paris - the capital of China" is a false statement.

6 < 5 - ложное высказывание.

Logic quantities:concepts expressed by the words: Truth, False (True, False). Consequently, the truth of statements is expressed through logical values.

Logical constant:Truth or false.

Logical variable:symbolically designated logical value. Therefore, if it is known that A, B, X, Y andave. - variables of logical quantities, then this means that they can take values \u200b\u200bonly truth or false.

Logical expression- Simple or complex statement. A complex statement is based on simple using logical operations (ligaments).

Logic operations.In mathematical logic, five main logical operations are defined: conjunction, disjunction, denial, implication, equivalence. The first three of them make up full system of operations,as a result, other operations can be expressed through them (normalized). These three operations are usually used in computer science.

Conjunction(logical multiplication). In Russian, it is expressed by the Union of I. In mathematical logic, signs are used & or . Conjunction - double operation; Recorded in the form: BUT IN.The value of such an expression will be false if the value of at least one of the operands is false.

Disjunction (logical addition). In Russian, this conjunction corresponds to the Union or. In mathematical logic, it is indicated by the V sign. Disjunction - double operation; Recorded in the form: A.v. IN.The value of such an expression will be true if the value of at least one of the operands is true.

Negation.In Russian, this bundle corresponds to a particle not (in some statements, the turnover is applied "incorrectly ..."). Denial - unary (single) operation; Recorded in the form: Or or.

Logical formula (logical expression) - the formula containing only logical values \u200b\u200band signs of logical operations. The result of calculating the logical formula is true or false.

Example 1. Consider a complex statement: "The number 6 is divided into 2, and the number 6 is divided into 3". Represent this statement in the form of a logical formula. Denote by BUTa simple statement "Number 6 is divided into 2", and through INa simple statement "Number 6 is divided into 3". Toon the appropriate logical formula has the form: BUT& IN.Obviously, its value is truth. Example 2. Consider a complex statement: "In the summer I will go to the village or a tourist trip."


Denote by BUTsimple saying "In the summer I will go, I will go the village", and through IN- Simple saying "Summer I will go to a tourist trip." Then the logical form of a complex statement has the form

Example 3. Consider saying: "It is not true that 4 is divided into 3".

Denote by BUTa simple statement "4 is divided into 3". Then the logical form of denial of this statement has the form BUT

The rules for performing logical operations are reflected in the following table, which is called the truth table.

The sequence of operations in logical formulas is determined by the seniority of operations. In the order of descending of seniority, logic operations are located as follows: denial, conjunction, disjunction.In addition, the procedure for operation affects brackets that can be used in logical formulas.

Applications of mathematical logic in the basic course

Mathematical logic in databases. When studying basic course Informatics students first occur with elements of mathematical logic in the "database" topic (database). In relational database, logical values \u200b\u200bare logical type fields. The logical type is used along with other types of fields, and students must learn to allocate it.

The first concept of a logical value can be given as an answer to an alternative question. For example: "Does this book in the library?" Or "Does the applicant entered the university", or "It's raining on the street?" etc. Answers to such questions can only be "yes" or "no". Synonyms are "Truth", "Lie"; "TRUE", "FALSE". If the table field only will receive such values, then it is assigned a logical type.

For example, relational base These optional contains information about visiting students of three electives on geology, flower growing and dance. At the relational language, its structure is described as follows:

Optional (Student. Geology, flower growing, dancing)

Geology fields, flowerness and dancing will have a logical type. The value of the truth for each field is indicating that the student visits this option, and the false - does not visit.

Logical expressions are used in database queries as search conditions. Logical expressions are divided into simple and complex. In simple expressions, only one table field is always used, and logic operations do not apply. In complex logical expressions, logical operations are used. A simple logical expression represents either the name of the logical type field, or attitude(In mathematics they say "inequality"). Relations for numerical values \u200b\u200bretain the meaning of mathematical inequalities; When calculating relations for symbolic values, a lexicographic order is taken into account; Dates are compared in the order of their calendar sequence.

The main problem is to teach students a formal presentation of the search conditions in the form of logical expressions. For example, from the phrase "Find all the books underlying the fifth shelves" need to go to logical expression: regiment\u003e 5; Or the condition to "choose all the physics impressive" to present in the form: Physics< 3; или «выбрать все дни, когда шел дождь» ОСАДКИ = «дождь».

Special attention should be paid to the use of logic fields in search terms. Usually, relationships are not applied to them. The logical field itself is a logical value: "Truth" or "Lie". For example, the condition "choose all students attending dances will be present in one name of the logical field of dancing.

Complex logical expressions contain logical operations. Three main operations of mathematical logic are considered: conjunction (s), disjunction (or), denial (not).

Usually, when explaining this issue, the teacher is repelled from the semantic meaning of statements in Russian containing alliances and, or, not a particle. For example, a statement: "Today will be the control on algebra and physics" fairly, if both control and falsely, if at least one does not take place. Another statement: "Today will be the control on algebra or physics" will be true if at least one test work will take place. And finally, the statement: "Today it will not be the control" True, if the control will not take place, i.e. if the statement that today will be the control, it turns out false. From such examples, the teacher makes conclusions about the rules for performing logical operations:if a A and B -logical values, then expression

A and B.true only if both operands are true;

BUTor INfalse only if both operands are false;

Not BUTchanges the value of a logical value to the opposite: not true - false; Not false - truth.

The statement (judgment) is a narrative proposal in which something is approved or denied. Regarding any statement, it is true that it is true or false.

Logic values: concepts expressed by the words: Truth (True), False (False).

Logical constant: Truth (True), FALSE (FALSE).

Logical variable: symbolically indicated logical value. Therefore, if it is known that a, in, x, y, etc. - logical values, then it means that they can take values \u200b\u200bonly truth or lies.

Logical expression: Simple or complex statement. Complex statements are built from simple using logical operations (ligaments).

Logical operations

Conjunction (logical multiplication). In Russian, expressed by the Union I.

In mathematical logic, signs & conjunction are used - a double operation, written in the form A ^ B (A, B - Operands). The value of such an expression will be false if at least the value of one of the operands is false.

Disjunction (logical addition). In Russian, expressed by the Union or.

In mathematical logic, the signs of disjunction are used - the double operation is written in the form of AV. The value of such an expression will be truth if at least the value of one of the operands is true.

Negation. In Russian, it is expressed by the Union not (in some statements the turnover is applied - it is not true that ...).

In mathematical logic, the negation signs are used - a single (unary) operation is recorded as a or or.

Logical formula (logical expression) - a formula containing only logical values \u200b\u200band signs of logical operations. The result of calculating the logical formula is true or false. In logical formulas, truth is often represented as 1, lies like 0.

The rules for performing logical operations are reflected in the truth table.

Tank truth

The sequence of logical operations in logical formulas is determined by the seniority of operations. The highest operational operation is denial (it is performed earlier than others), then there is a conjunction (s), and then disjunction (or).

Logic

In a convenient way to represent logical expressions are logic schemes. This is how three main logical operations are depicted on such schemes.

The following notation is used in this table:

1 - truth, 0 - lie, and, or, not - logical operations.

Example1: Draw a diagram for a logical expression 1 or 0 and 1. Then calculate the value of the logical expression.

Solution: Scheme - Calculation:

Example2: Dana. logic scheme. Build a logical expression. Then calculate the value of the logical expression.

Solution: Dana Scheme -

Make a formula - (1 or 0) and 1. Calculate the value according to the scheme 1 or 0 \u003d 1,

then 1 and 1 \u003d 1. So (1 or 0) and 1 \u003d 1.

Logic information and logic basics


With elements of mathematical logic, you have already met in the course of informatics of the main school, studying ways to write requests to the database and conditional function IF A In spreadsheets, the basics of algorithm and programming. We repeat the basic concepts of logic in order to further deepen your knowledge to use it for programming.

The main concepts of logic include: statement, logical value, logical operations, logical expressions and formulas.

Statement (judgment) - This is a narrative offer in which something is approved or denied. Regarding any statement, it can be said true or false.

For example, the statement "The street is raining" will be true or false depending on the state of the weather in this moment. The truth of the statement "meaning and more than in" recorded in the form of inequality: A\u003e B will depend on the values \u200b\u200bof variables A and V.

Logic values - Concepts expressed by the words: Truth, False (True, False). Hence, the truth of statements is expressed through logical values.

Logical constant: Truth or false.

Logical variable: Symbolically designated logical value. Therefore, if it is known that a, in, x, y, etc. - variables of logic values, then, it means that they can take values \u200b\u200bonly truth or false.

Logical expression - Simple or complex statement. A complex statement is based on simple using logical operations (ligaments).

Logical operations

Conjunction (logical multiplication). In Russian, it is expressed by the Union I. In mathematical logic, signs are used & or ∧. Conjunction - double operation; It is written in the form: A & B. The value of such an expression will be false if the value of at least one of the operands is false.

Disjunction (logical addition). In Russian, this conjunction corresponds to the Union or. In mathematical logic, it is indicated by the sign v.. Disjunction - double operation; It is written in the form: A v. The value of such an expression will be truth if the value of at least one of the operands is true.

Negation. In Russian, this bundle corresponds to a particle not (in some statements, turnover is applied "incorrectly that ..."). Denial - unary (single) operation; Recorded in the form: ¬ a or ā.

The rules for performing the considered logical operations are reflected in the following table, which is called the truth table of the logical operations (here and means "truth", L - "Lie"):

Logical formula- Formula containing only logical values \u200b\u200band signs of logical operations. The result of calculating the logical formula is true or false.

The sequence of operations in logical formulas is determined by the seniority of operations. In the order of descending of seniority, logic operations are located as follows: denial, conjunction, disjunction . In addition, the procedure for performing operations is influenced by brackets that can be used in logical formulas.

For example: (A & B) V (¬ A & B) V (¬ A & ¬ B).

Example. Calculate the value of the logical formula:

¬ x & y v x & z,

if logical variables have the following values: X. \u003d False Y. \u003d Truth Z. \u003d Truth.

Decision. Note the number from above the procedure for performing operations in the formula:

Using the truth table, calculate the formula for steps:

1) lie \u003d truth; 2) Truth & Truth \u003d Truth; 3) lies & truth \u003d lies; 4) Truth V lies \u003d truth. Answer: Truth.

Logic functions on the field of numerical values

The algebra of the numbers intersects with algebra logic in cases where you have to check the identity of the values \u200b\u200bof algebraic expressions with some set. For example, the belonging of the value of the numerical variable x the set of positive numbers is expressed through statement: "X more zero." It is symbolically written so: x\u003e 0. In algebra, such an expression is called inequality. In logic - attitude.

The ratio X\u003e 0 may be true or false. If X is a positive value, then it is true, if negative, then false. In general, the attitude has the following structure:

< выражение 1 > < знак отношения > < выражение 2 >

Here expressions 1 and 2 are some mathematical expressions that take numeric values. In a particular case, the expression may be one constant or one variable value. Relationship signs can be as follows:

So, the attitude is a simple statement, which means a logical value. It can be as permanent: 5\u003e 0 - always truth, 3 * 6: 2 - always lie; So and variable: A< b, х + 1 = с - d. Если в отношение входят переменные числовые величины, то и значение отношения будет логической переменной.

The relationship can be considered as a logical function from numerical arguments. For example: F (x) \u003d (x\u003e 0) or p (x, y) \u003d \u003d (x< у). Аргументы определены на бесконечном множестве действительных чисел, а значения функции - на множестве, состоящем из двух логических величин: ИСТИНА, ЛОЖЬ.

Logic functions from numerical arguments are also called the term predicate. In algorithms, predicates play the role of the conditions under which branching and cycles are built. Predicates can be both simple logical functions that do not contain logical operations and complex containing logical operations.

Example 1. Write a predicate (logical function) from two real arguments x and y, which will take the value of truth if the point on the coordinate plane with coordinates x and y lies inside the unit circle with the center at the beginning of the coordinates (Fig. 3.12).

It is clear from the geometrical considerations that for all points lying inside a single circle, will be the true value of the next logical function:

F (x, y) \u003d (x 2 + in 2< 1).

For the values \u200b\u200bof the coordinates of the points lying on the circle and outside it, the value of the function f will be false.

Example 2. Write the predicate that will take the value of truth if the point on the coordinate plane with the x and y coordinates lies inside the ring with the center at the beginning of the coordinates and radius R1 and R2.

Since R1 and R2 values \u200b\u200bare variable values, the desired logical function will have four arguments: X, y, R1, R2. Two situations are possible:

1) R1 2< X 2 + У 2 < R2 2 и R1 < R2: R1 - внутренний радиус, R2 - внешний радиус;

2) R2 2< X 2 + У 2 < R1 2 и R2 < R1: R2 - внутренний радиус, R1 - внешний радиус.

By combining both these approvals and writing them on the rules of logic algebra, we obtain the following logical function:

F (x, y, r1, r2) \u003d (((x 2 + in 2)\u003e r1 2) & ((x 2 + y 2)< R2 2) & R1 < R2) v (((X 2 + У 2) > R2 2) & ((x 2 + in 2)< R1 2) & R2 < R1).

Example 3. Write a predicate that will take the value of truth if the point on the coordinate plane with the x and y coordinates lies inside the figure limited by the bold lines in Fig. 3.13.

The figure is limited by three boundaries described by the equations:

Y \u003d -x - left border, linear function;

Y \u003d 1 - upper boundary, constant;

Y \u003d x 2 - right border, parabola.

The area under consideration is the intersection of three semi-positions described by inequalities:

In the inner points, all these three relationships are one and temporary true. Therefore, the desired predicate is:

F (x, y) \u003d (y\u003e -x) & (y< 1) & (У > X 2).

Logic expressions on Pascal

It has already been said that there is a logical data type in Pascal.

Logical constants: true. (true), false (False).

Logic variables: Describes with type Boolean..

Relationship operations: Compare two operands and determine, truly or falsely, the corresponding relationship between them. Relationship Signs: \u003d (Equal),<> (not equal),\u003e (more),< (меньше), >\u003d (more or equal),<= (меньше или равно).

Logic operations: not. - denial, and. - logical multiplication (conjunction), or. - logical addition (disjunction), ho - excluding or. Tatac of truth for these operations (T - true.; F - false):

Logical expression It may consist of logical constants and variables, relationships, logical operations. A logical expression takes True or False.

For example, the logical formula ¬ X & in V X & Z on the Pascal will be recorded in the form of the following logical expression:

not. X. and. Y. or. X. and. Z,

where X, Y, Z - Variable type Boolean..

Logical operations are located in the following order descending seniority (priority): 1) not., 2) and., 3) oR, XOR. Relationship operations have the lowest priority. Therefore, if the operands of the logical operation are relationships, they should be concluded in parentheses. For example, mathematical inequality 1 ≤ x ≤ 50 corresponds to the following logical expression:

(1 <= Х) and. (H.<= 50)

Logical function oDD (X) Takes up value true.if the value of the integer argument h. is odd, otherwise - false.

To properly record a complex logical expression (predicate), it is necessary to take into account the relative priorities of arithmetic, logical operations and relationship operations, since they can all be present in logical terms. Descending the priority of the operations are located in the following order.

1. Arithmetic operations: - (minus unary) *, / +, - 2. Logic operations: not. and. oR, XOR 3. Relationship operations: \u003d,<>, >, <, >=, <=

Once again, note that in a logical expression corresponding to the predicate from Example 3:

(Y\u003e -X) and. (Y.< 1) and. (Y\u003e x * x),

operations of the relationship are in brackets, since they are younger than logical operations, and must be executed earlier.


Questions and tasks

1. What type of value is obtained when calculating the ratio (inequality) between numbers?

2. What is predicate? Give examples.

3. Record the logic algebra in the language of the Logic functions that will take the value of truth if the following statements are valid, and false - otherwise:

A) all numbers X, Y, Z equal to each other; b) from numbers X, Y, Z only two are equal to each other; c) each of the numbers X, Y, Z positively; d) only one of the numbers X, U, Z positively; d) values \u200b\u200bof numbers X, U, Z Ordered ascending.

4. All formulas obtained in solving the previous task, write down in the form of logical expressions on the Pascal.

5. Build a truth table for a logical formula:

¬x & y v x & z.

Explanation: The truth table should calculate the values \u200b\u200bof the formula for all variants of the values \u200b\u200bof logical variables: X, U, Z. Consequently, the table will contain 2 3 \u003d 8 rows and 4 columns: values X, U, Z And the result. You can add additional columns to the table containing the results of intermediate operations.

6. Calculate the values \u200b\u200bof the following logical expressions recorded on Pascal:

Explanations: oDD (X) - the logical function of determining the parity of the argument is equal to true.if x is odd and equal falseif X is even; trunc (x) - an integer function from a real argument that returns the nearest integer that does not exceed x module.

Programming branching