The basic concepts of mathematical logic. "Logic values, operations, expressions over logical values.

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 with logic 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:

Example 2: 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

Direct relationship to programming has a discipline called mathematical logic. The basis of mathematical logic is the logic algebra, or the calculation of statements. Under the statement means any statement in respect of which one can unambiguously say, it is truly or false. For example, "Moon - Satellite of Earth" - True; "5\u003e 3" - truly; "Moscow - the capital of China" - falsely; "1 \u003d 0" - false. Truth or lies are logical values. The logical values \u200b\u200bof the above statements are uniquely defined; In other words, their values \u200b\u200bare logical constants.

Logical meaning of inequality x< 0, где х - переменная, является переменной величиной. В зависимости от значения х оно может быть либо истиной, либо ложью. В связи с этим возникает понятие логической переменной.

The foundations of the formal apparatus of mathematical logic created in the middle of the XIX century. English Mathematics George Bul. In his honor, the calculus of statements is called Boolean algebra, and the logical values \u200b\u200bare boolean.

Single statements can be combined into compound logical formulas using logical operations.

There are three main logical operations: denial, conjunction (logical multiplication) and disjunction (logical addition).

The negation operation is indicated in the mathematical logic of the ¬ and read as a particle not. This is a single operation.

For example, ¬ (x \u003d y) is read "not (x equal to y)". As a result, the truth is, if x is not equal to, and lies, if x is equal to. The denial changes the value of the logical value to the opposite.

The conjunction operation is indicated by the & and read as a particle and. This is a double operation. For example, (x\u003e 0) & (x< 1) читается «х больше 0 и х меньше 1». Данная логическая формула примет значение истина, если х

(0.1), and false - otherwise. Consequently, the result of conjunction is truth if both operands are true. The sign of the operation of disjunction V is read as a particle or. For example, (x \u003d 0) v (x \u003d 1) read "x equal to 0 or x equal to 1". The formula gives truth if X is a binary digit (0 or 1). Consequently, the disjunction results in the truth, if at least one operand is truth.

In Pascal, logical values \u200b\u200bare designated by the service words false (false) and true (truth), and the logical type identifier is Boolean.

In addition to the values \u200b\u200b(constants and variables) of the type Boolean, the Logic values \u200b\u200bof FALSE, TRUE take the results of the relationship operations.

Relations operations (Fig. 18) compare two operands and determine, truly or falsely, the corresponding relationship between them.


Examples of recording relationships: x<у; a+b>\u003d C / D; ABS (M-N)<=l. Примеры вычисления значений отношений:

Logical operations are performed above the operands of the Bulev type. There are four logical operations: not - denial; And - logical multiplication (conjunction); OR - logical addition (disjunction). In addition to these three mandatory operations in Turbo Pascal, there is still an operation - excluding or. Her sign - the service word HOR. This is a double operation, which as a result gives the value of truth if both operands have different logical values.

Operations are listed in descending order of priorities. The results of logical operations for different values \u200b\u200bof the operands are shown in Table. 3.5.

Table 3.5


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<=X) And (X<=50)

A logical expression is a logical formula written in programming language. The logical expression consists of logical operands associated with logical operations and round brackets. The result of the calculation of a logical expression is the Boolean value (False or True). Logical operands may be logical constants, variables, functions, relations operations. One separate logic operand is the simplest form of a logical expression.

Examples of logical expressions (here d, b, C - logical variables; x, y - real variables; k - a whole variable):

If D \u003d True; B \u003d false; C \u003d True; x \u003d 3.0; y \u003d 0.5; k \u003d 5, the results of the calculation will be as follows:

The example used the ODD (k) logical function. This is a function from the whole argument k, which takes True if K value is odd, and false, if K is even.

The logical assignment operator has the structure shown in Fig. nineteen.


Examples of logical assignment operators:

2) B: \u003d (x\u003e y) and (k<>0);

3) C: \u003d D or b and not (ODD (K) and D).

Programming branching on Pascal

The main topics of the paragraph:

♦ branch operator on Pascal;
♦ Programming full and incomplete branch;
♦ Programming nested branches;
♦ logical operations;
♦ Complex logical expressions.

Branch Operator on Pascal

In the Pascal language there is a branch operator. Another name is the conditional operator, the format of the full branch statement is as follows:

if.<логическое выражение> Then.<оператор1>

eLSE.<оператор2>

Here if - "if", then - "That", ELSE - "Other".

Programming full and incomplete branching

Compare the recording of the BIID1 algorithm from the previous paragraph with the corresponding program.

Very similar to the translation from the Russian language into English. Pay attention to the following difference: there is no special official word in the program denoting the end of branching. Here, a sign of the end of the branch operator is a comma point. (Of course, it is not necessary to leave an empty string in the program at all. Here it is done only for clarity.)

A simple form of a logical expression is the relationship operation. As in Aya, all kinds of relationships are allowed in Pascal (their signs are indicated below):

< (меньше); >\u003d (more or equal);
\u003e (more); \u003d (equal);
<= (меньше или равно); <> (not equal).

And now we will program the BID2 algorithm in the Pascal, in which the incomplete branching is used.

Everything is very similar. The branch of ELSE in the branch statement may be absent.

Programming nested branches

We write a program for determining the larger of three numbers in Pascal, a block diagram that is shown in Fig. 6.6. The structure of this algorithm is nested branches. Algorithm on AA (BIT2) is given in the previous paragraph.

Pay attention to the fact that in front of the else point with comma is not put. The entire branching part of the structure of the algorithm ends at the point with a comma after the operator d: \u003d c.

We will form a program to streamline the values \u200b\u200bof two variables.

This example illustrates the following Pascal rule: if there are several consecutive operators on some of the branches of the branch operator, they need to be recorded between the BEGIN and END service words. Design of this type:

begin.<последовательность операторов> End.

called a composite operator. Therefore, in the general form of branch described above<оператор1> and<оператор2> May be simple (one) and composite operators.

Logical operations

Finally, we will make another one, the third option of the program for determining a larger number of three.

It is not difficult to understand the meaning of this program. Here are three consecutive incomplete branches. And branching conditions are complex logical expressions that include a logical operation and (and). With logical operations, you met, working with databases and with spreadsheets.

Recall that the operation and is called logical multiplication or conjunction. Its result is "truth", if the values \u200b\u200bof both operands are "Truth". Obviously, if a\u003e in and a\u003e s, then it is most important and so on. In Pascal, there are all three main logical operations:

and - and (conjunction),
or - or (disjunction),
not - not (denial).

Complex logical expressions

Pay attention to the fact that the relationship associated with logical operations is in brackets. So you have to do always! For example, it is required to determine whether there is among numbers A, B, with at least one negative one. This task is the following branch operator:

iF (A.<0) or (B<0) or (C<0)
Then Write ("Yes") ELSE WRITE ("NO");

The expression that is true for a negative number can also be written as follows:

Briefly about the main thing

The branch operator (conditional operator) Pascal has the form:

if.<логическое выражение>
Then.<оператор1> ELSE.<оператор2>

On the branches of the conditional operator, simple or composite operators may be. The composite operator is a sequence of operators concluded between the BEGIN and END service words.

In difficult logical expressions Logic operations are used: and, or, not.

Questions and tasks

1. How is the full and incomplete branching program?
2. What is a composite operator? In what cases is the composite operator used in the branch statement?
3. Perform all the programs in this paragraph on the computer.
4. Make up at least three variants of the definition program of the smallest of three numbers.
5. Make a sorting program by increasing values \u200b\u200bin three variables: A, B, C.
6. Make a program for calculating the roots of the square equation according to the values \u200b\u200bof its coefficients.

Edited date: Monday, 30 December 2019

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 is a 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 the basic course of informatics, students are first found 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, the relational database of optional contains information about visiting students of three electives on geology, flower growing and dancing. 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.

1. Logic values, operations, expressions. Logical expressions as conditions in branching and cyclic algorithms.

In order to understand the work of branching and cyclic algorithms, consider the concept of a logical expression.

In some cases, the choice of actions in the program should depend on how the values \u200b\u200bof some variables relate.

For example, the calculation of the roots of the square equation is made differently depending on the discriminant (remember mathematics).

As a result of comparing the values \u200b\u200bof two expressions, two answers are possible: comparison true or false?

For example:

2 + 3\u003e 3 + 1 - yes (truly)

0 < -5 - нет (ложно)

Expressions of this kind we will call logical expressions.

A logical expression, like a mathematical expression, is executed (calculated), but the result is not a number, but a logical value: truth (true) or false (false). Logic value- It is always the answer to the question, is true of this statement.

We know six comparison operations:

With the help of these operations, we will compile logical expressions. And in the expressions, there are only constants, but also variables.

How operations are performed for numerical values \u200b\u200bare clear from mathematics. How are symbolic values \u200b\u200bcompare? The ratio "equally" is true for two symbolic values, if their lengths are the same and all the corresponding characters coincide. It should be borne in mind that the gap is also a symbol.

Symbimal values \u200b\u200bcan be compared in relations\u003e<, >=, <=. Здесь упорядоченность слов (последовательности символов) определяется по алфавитному принципу.

"Cat" \u003d "Cat"

"cat"< «лис»

"Cat"\u003e "House"

An expression consisting of one logical value or one relationship will be called a simple logical expression.

There are often tasks that use not separate conditions, but a combination of related conditions (relationships). For example, in the store you need to choose shoes whose size is R \u003d 45, color Color \u003d White, price price no more than 400 rubles.

Another example: a schoolboy found out that he could buy a chocolate unit if it costs 3 rubles. or 3 rubles. 50Kop.

In the first example, we are dealing with three relations associated with the Union "and" and the "non-" particle, in the second - with two relations associated with the Union "or". Similar conditions let's call compound, and for their designation in the algorithm we will agree to use alliances " and", "or", "not", Which we will consider as signs of logical operations that make it possible to create composite from simple conditions, just as from simple variables and constants using +, - etc., and so on. You can create algebraic expressions.

So the conditions of our examples in the algorithm may look like this:

first: (R \u003d 45) and (Color \u003d White) and (not (Price\u003e 400))

second: (price \u003d 3) or (price \u003d 3.5)

An expression containing logical operations will be called a complex logical expression.

Combining two (or several) statements in one with the help of the Union "and" is called operation logical multiplication or conjunction .

As a result of logical multiplication (conjunction), truth is obtained if all logical expressions are true.

Combining two (or more) statements with the power of the union "or" called operation logical addition or disjunction .

As a result of logical addition (disjunction), truth is obtained if at least one logical expression is true.

Attaching the "not" particle to the statement is called operation logical denial or inversion .

The denial changes the value of a logical value to the opposite: not truth \u003d false; notlie \u003d truth.

If there are several logical operations in a complex logical expression, then the question arises, in which manner will perform their computer. Descending the seniority, logic operations are located in this order:

    denial ( not);

    conjunction ( and);

    disjunction ( or).

In logical expressions, you can use parentheses. As in mathematical formulas, brackets affect the sequence of operations. If there are no brackets, the operations are performed in the order of their seniority.

Example. Let A, B, C be logical values \u200b\u200bthat have the following values: a \u003d truth, B \u003d false, c \u003d truth. It is necessary to determine the results of calculating the following logical expressions:

    a. and B.

    a. or B.

    not A. or B.

    a. and B. or C.

    a. or B. and C.

    not A. or B. and C.

    (A. or b) and (from or b)

    not (A. or b) and (from or b)

    not (A. and B. and c)

We get as a result:

Example. Create an algorithm for calculating:

Algorithm Calculation X.

Start
Enter (A, C)
If (4 * a - c\u003e \u003d 0) and (and<>0) T.
Start
x: \u003d root (4 * a - c) / (2 * a)
conclusion (x)
end
Otherwise
Conclusion ("no solution")
end

The computer will first check the condition (4 * A - C\u003e \u003d 0) and (and<>0) And if it turns out to be true, then calculate X, otherwise the message "no solution" will withdraw.

Example. Create an algorithm to calculate the sum of all numbers from 1 to n.

Algorithm Calculation of the amount of numbers
Variables A, C, X - Real
Start
Enter (N)
x: \u003d 1
So far Start
S: \u003d S + x
x: \u003d x +1
end
Conclusion (s)
end

Until condition X