10 logical values ​​of the expression operation. “Logical quantities, operations, expressions. Boolean values, operations, expressions

💖 Like it? Share the link with your friends

Directly related to programming is a discipline called mathematical logic. The basis of mathematical logic is the algebra of logic, or propositional calculus. A proposition is any statement about which it can be unequivocally said whether it is true or false. For example, "The moon is a satellite of the Earth" is true; "5 > 3" - true; "Moscow is the capital of China" is false; "1 = 0" is false. True or false are boolean values. The logical meanings of the statements above are uniquely defined; in other words, their values ​​are boolean constants.

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

The foundations of the formal apparatus of mathematical logic were created in the middle of the 19th century. English mathematician George Boole. In his honor, the propositional calculus is called Boolean algebra, and logical quantities are called Boolean.

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

Available three basic logical operations: negation, conjunction (logical multiplication) and disjunction (logical addition).

negation operation is denoted in mathematical logic by the symbol ¬ and is read as a particle not. This is a single operation.

For example, ¬ (x = y) reads "not (x equals y)". The result is true if x is not equal to y, and false if x is equal to y. Negation reverses the value of a boolean value.

The conjunction operation is denoted by & and is read as a particle and . This is a double operation. For example, (x > 0) & (x< 1) читается «х больше 0 и х меньше 1». Данная логическая формула примет значение истина, если х (0,1), и ложь - в противном случае. Следовательно, результат конъюнкции - истина, если истинны оба операнда. The sign of the disjunction operation v read as a particle or. For example, (x = 0) v (x = 1) reads "x is 0 or x is 1". The formula evaluates to true if x is a binary digit (0 or 1). Therefore, the disjunction evaluates to true if at least one operand is true.

In Pascal, logical values ​​are denoted by the function words false (false) and true (true), and the boolean type identifier is boolean.

In addition to values ​​(constants and variables) of the boolean type, the logical values ​​false, true accept the results of relational operations.

Relational operations (Figure 18) compare two operands and determine whether the corresponding relation between them is true or false.

Boolean operations are performed on boolean type operands. There are four logical operations: Not - negation; And - logical multiplication (conjunction); Or - logical addition (disjunction). In addition to these three mandatory operations, Turbo Pascal has another operation - XOR . Her sign is the service word Hor. This is a binary operation that evaluates to true if both operands have different boolean values.

Relational operations have the lowest precedence. Therefore, if the operands of a logical operation are relations, then they should be enclosed in parentheses. For example, the 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 a programming language. A logical expression consists of logical operands linked by logical operators and parentheses. The result of evaluating a logical expression is a boolean value (false or true). Logical operands can be logical constants, variables, functions, relational operations. One single boolean operand is the simplest form of a boolean expression.

Examples of logical expressions (here d, b, c are boolean variables; x, y are real variables; k is an integer variable):

If d=true; b=false; c=true; x=3.0; y=0.5; k=5, then the calculation results will be as follows:

The example uses the logical function odd(k). This is a function of an integer argument k that evaluates to true if k is odd and false if k is even.

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

Description of the presentation LOGICAL VALUES, OPERATIONS, EXPRESSIONS. (Grade 10) by slides

The basic concepts of logic include: Statement Boolean value Logical operations Logical expressions Formulas

A statement (judgment) is a declarative sentence in which something is affirmed or denied. Any statement can be said to be true or false. For example: "It's raining outside" will be true or false depending on the state of the weather at the moment. The truth of the statement "The value is greater than", written in the form of inequality: > , will depend on the values ​​of the variables and.

Which of the sentences are statements? Determine their truth. How long is this tape? Listen to the message. Do morning exercises! Name the input device. Who is absent? Paris is the capital of England. The number 11 is prime. 4 + 5 = 10. You can't even pull a fish out of a pond without difficulty. Add the numbers 2 and 5. Some bears live in the north. All bears are brown. What is the distance from Moscow to Leningrad?

Logical values ​​are concepts expressed by the words: TRUE, FALSE (true, false). Therefore, the truth of the proposition is expressed in terms of logical quantities. Boolean variable: A symbolically denoted boolean value. For example: if it is known that A, B, X, Y, etc. are variable logical values, then they can only take the value TRUE or FALSE. A logical expression is a simple or compound statement. A complex statement is built on simple ones using logical operations (connections)

Logical operations Conjunction (logical multiplication) A two-place operation, written as A & B. The value of such an expression will be FALSE if the value of at least one operand is false. Disjunction (logical addition) A two-place operation, written as A V B. The value of such an expression will be TRUE if the value of at least one operand is true. Negation is a unary (one-place) operation. Written as ¬ A or Ā.

A logical formula is a formula containing only logical values ​​and signs of logical operations. The result of calculating a logical formula is TRUE or FALSE. The sequence of operations in logical formulas is determined by the precedence of operations. In descending order of precedence, logical operations are arranged as follows: negation, conjunction, disjunction. In addition, the order in which operations are performed is affected by parentheses that can be used in logical formulas. For example: (A&B)v(Ā&B)v(Ā&B)

Example 1: Calculate the value of a logical formula ¬ X & Y v X & Z If the logical variables have the following values: X=FALSE, Y=TRUE, Z=TRUE. Solution: We mark the order of execution of operations in the formula with numbers from above: Using the truth table, calculate the formula in steps: 1. ¬ FALSE = TRUE; 2. TRUE & TRUE = TRUE; 3. FALSE & TRUE = FALSE; 4. TRUE v FALSE = TRUE. ¬ X & Y v X & Z

EXAMPLE 2 Determine the value of the logical expression: not (X > Z) and not (X = Y) if: 1) X = 3, Y = 5, Z = 2; 2) X = 0, Y = 1, Z = 19; 3) X=5, Y=0, Z=-8; 4) X=9, Y=-9, Z=9.

Logical functions on the area of ​​numerical values ​​The algebra of numbers intersects with the algebra of logic in those cases when it is necessary to check whether the values ​​of algebraic expressions belong to a certain set. For example, if the value of the numeric variable X belongs to the set positive numbers expressed through the statement: "X is greater than zero". Symbolically, this is written as follows: X > 0. In algebra, such an expression is called an inequality, and in logic, a relation. The relation X>0 can be true or false. If X is positive, then it is true; if it is negative, then it is false. In general, the relationship has the following structure: Relationship signs: = ; ; >; = ;<=.

A relation is a simple statement, and therefore a logical value. It can be either constant: 5>0 - always TRUE, 3≠ 6: 2 - always FALSE; and variable: a 0) or P(x, y)=(x

Example: Write a predicate (logical function) from two real arguments X and Y , which will be TRUE if the point on the coordinate plane with coordinates X and Y lies inside the unit circle centered at the origin. 1 1 -1 0 Y X Solution: From geometric considerations, it is clear that for all points lying inside the unit circle, the value of the following logical function will be true: F(X, Y)=(X 2 +Y 2<1) Для значений координат точек, лежащих на окружности и вне её, значение функции Y будет ложным.

Pascal logical expressions Logical constants: true (true), false (false). Boolean variables: are declared with Boolean type. Relational operators: compare two operands and determine whether the corresponding relation between them is true or false. Signs of relational operations Logical operations: not – negation; and - logical multiplication (conjunction); or -logical addition (disjunction); xor is an OR exception. Truth table for these operations(T- true, F-false) = ; ; >; = ;<=. A B not A A and B A or B A xor B T T F T F F F T T

A logical expression may consist of logical constants and variables, relations, logical operations. The boolean expression evaluates to true or false. For example, a logical formula in Pascal will be written as the following logical expression: not X and Y or X and Z , where X, Y, Z are Boolean variables. Boolean variables are arranged in the following descending order of precedence (priority): 1) not 2) and 3) or, xor. Relational operations have the lowest precedence. Therefore, if the operands of a logical operation are relations, then they should be enclosed in parentheses. For example, the mathematical inequality 1≤ X ≤ 50 corresponds to the following logical expression: (1<=X) and (X<=50)¬ X & Y v X & Z

The logical function odd(x) is a logical function for determining the parity of the argument, equals true if x is odd, and equals false if x is even; trunc (x) is an integer function of a real argument that returns the nearest integer that does not exceed x in modulo.

For the correct writing of a complex logical expression (predicate), it is necessary to take into account the relative predicates of arithmetic, logical operations and relational operations, since all of them can be present in a logical expression. In descending order of precedence, operations are arranged in the following order: 1. Arithmetic operations: -. (minus unary) *, / +, - 2. Logical operations: not and or, xor 3. Relational operations: =, >, =,<=

Compiled by: Antonova E.P. 2008

slide 2

Boolean values

Logical quantities: concepts expressed in words: TRUE, FALSE (true, false). Consequently, the truth of propositions is expressed in terms of logical quantities. Boolean constant: TRUE or FALSE. Boolean variable: A symbolically designated logical value. If A, B, X, Y, etc. are variable logical values, then this means that they can only take the values ​​TRUE or FALSE. A logical expression is a simple or complex statement. A complex statement is built from simple ones with the help of logical operations (connections).

slide 3

logical operations. Conjunction

Conjunction (logical multiplication). In Russian, it is expressed by the union AND. In mathematical logic, the signs & or / \ are used. Conjunction is a two-place operation; is written as: A /\ B. The value of such an expression will be FALSE if at least one of the operands is false.

slide 4

logical operations. Disjunction

Disjunction (logical addition). In Russian, this bundle corresponds to the union OR. In mathematical logic, it is denoted by v. Disjunction is a two-place operation; is written as: A vB. The value of such an expression will be TRUE if the value of at least one of the operands is true.

slide 5

logical operations. Negation

Negation. In Russian, this bundle corresponds to the particle NOT (in some statements, the phrase “it is not true that ...” is used). Negation is a unary (one-place) operation; is written as: ¬A

Slide 7

Example

Consider the complex statement: "The number 6 is divisible by 2, and the number 6 is divisible by 3." Present this statement as a logical formula. Let us denote by A the simple statement "the number 6 is divisible by 2", and by B the simple statement "the number 6 is divisible by 3". Then the corresponding logical formula looks like: A & B. Obviously, its value is TRUE.

Slide 8

Rules for executing logical operations

  • Slide 9

    Task 1

    Formulate statements in ordinary language for the following logical expressions: 1) (X = 12) and (Y = 12) and (Z = 12); 2) (X 0) or (Y 0); 3) (X x Y 0); 4) (X x Y x Z 0).

    Slide 10

    Task 2

    Determine the value of the logical expression: not (X > Z) and not (X = Y) if: 1) X = 3, Y = 5, Z = 2; 2) X = 0, Y = 1, Z = 19; 3) X=5, Y=0, Z=-8; 4) X = 9, Y = -9, Z = 9.

    slide 11

    Task 3

    Determine the values ​​of the logical variables a, b c, d, if: 1) a and (Mars is a planet) is a true statement; 2) b and (Mars is a planet) is a false statement; 3) with or (the Sun is a satellite of the Earth) - a true statement; 4) d or (the Sun is a satellite of the Earth) is a false statement.

    A statement (judgment) is a declarative sentence in which something is affirmed or denied. Any statement can be said to be true or false.

    Logical values: concepts expressed in words: TRUE (true), FALSE (false).

    Boolean constant: TRUE (true), FALSE (false).

    Boolean variable: A symbolically denoted boolean value. Therefore, if it is known that A, B, X, Y, etc. are logical values, then this means that they can only take the values ​​TRUE or FALSE.

    Boolean expression: simple or compound statement. Complex statements are built from simple ones with the help of logical operations (connections).

    Boolean operations

    Conjunction (logical multiplication). In Russian, it is expressed by the union I.

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

    Disjunction (logical addition). In Russian, it is expressed by the union OR.

    In mathematical logic, signs are used. Disjunction is a two-place operation, written as AB. The value of such an expression will be TRUE if at least one of the operands is true.

    Negation. In Russian, it is expressed by the union NOT (in some statements, a turnover is used - it is not true that ...).

    Signs are used in mathematical logic. Negation is a single (unary) operation, written as A or.

    Logical formula (logical expression) - a formula containing only logical values ​​and signs of logical operations. The result of evaluating a logical formula is TRUE or FALSE. In logical formulas, TRUE is often represented as 1, FALSE as 0.

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

    truth table

    The sequence of execution of logical operations in logical formulas is determined by the precedence of operations. The oldest operation is negation (it is performed before the others), then comes conjunction (and), and then disjunction (or).

    Logic

    Logic diagrams are a convenient way to represent logical expressions. Here is how the three basic logical operations are depicted in such diagrams.

    This table uses the following notation:

    1 - true, 0 - false, and, or, not - logical operations.

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

    Solution: Scheme - Calculation:

    Example2: A logic diagram is given. Build a boolean expression. Then evaluate the value of the boolean expression.

    Solution: Given a scheme -

    Compose the formula - (1 or 0) and 1. Calculate the value according to the scheme 1 or 0 = 1,

    then 1 and 1 = 1. So (1 or 0) and 1 = 1.

    Logical information and the foundations of logic



  • tell friends