Logical operation. Basic logic operations

Computer science as a science about the methods of collecting, organizing and processing various data begins its development in the middle of the twentieth century. Although some historians believe that the formation of computer science began in the 17th century, with the invention of the first mechanical calculator, most associate it with the era of more advanced computing. In the 40s of the 20th century, with the advent of the first computers, computer science received a new impetus in development.

The subject of computer science

It was with the advent of the first computers that there was a need to develop new methods for organizing, calculating and processing large data arrays, as well as in developing algorithms that would allow to use the full potential of new computers. Computer science received the status of an independent scientific discipline and moved from the plane of mathematical calculations to the study of computing as a whole.

logical operation

All modern computer science is based on logical operations. They can be called a fundamental component. In programming computer systems, the concept of a logical operation is a certain action, after which a new concept or value is generated, which is formed on the basis of existing concepts. The set of such actions may vary depending on the processor element that must execute the commands. However, there are some operations that are common to almost all existing systems. These are operations that work with the content of the meanings themselves, for example, negation, or those that change the quantitative characteristic of a concept — addition, subtraction, multiplication, division.

Types of operands of logical operations

Since the algebra of logic implies work on abstract concepts, generalized data types act as operands of all logical operations. The classic elements that the propositional algebra works with are propositions, false or true. In electronics and programming, the Boolean variables true and false or the integer values ​​1 (true) and 0 (false) are used to describe these terms. The combination of these values, no matter how incredible it may sound, is tied to the work of the most complex and large-scale systems. All program code that runs on a computer or any digital device is dynamically translated into a sequence of ones and zeros - a universal code that can be processed by any processor.

Types of logical operations

As mentioned earlier, in the classical Boolean algebra there are 2 types of functions. Basic logical operations on binary data types are actions that affect the statement itself (unary, or unary, operation). This also includes operations that generate new statements based on existing values ​​(binary operations, or double). The order of logical operations is the same as when performing any mathematical calculations: from left to right, taking into account the brackets.

basic logic operations

The simplest and one of the most famous functions of Boolean logic is the negation function. This simplest logical operation is the opposite value of the input operand. In electronics, this action is sometimes called inversion. For example, if you invert the proposition “truth”, then the result will be “false”. And vice versa - negation of the meaning of “false” will result in the meaning of “truth”. Such a logical operation in programming is very often used to branch algorithms and implement the “choice” of a subsequent set of instructions based on existing results or changed conditions.

Binary operations

In programming and computer science, a limited set of binary (binary) operations is used. They got their name from the Latin word bi, meaning "two", and are a type of function that takes two arguments at the input and as a result returns one new value. Truth tables are used to describe all functions of Boolean algebra.

What are they needed for

This system is compiled for a certain number of input operands and describes all the resulting values ​​that a given logical operation can return with a specified set of input parameters.

The most commonly used functions in computer science and computer technology are the operations of logical addition (disjunction) and logical multiplication (conjunction).

Conjunction

The logical operation “AND” is a function for selecting the smallest of two or n input operands. At the input, this function can have two (binary function), three values ​​(ternary) or an unlimited number of operands (n-ary operation). When calculating the result of the function, it will be the smallest of the provided input values.

logical operations and or

An analog in ordinary algebra is the multiplication function. Therefore, the conjunction operation is often called logical multiplication. When writing a function, the sign is either the multiplication sign (dot) or the ampersant. If you compile a truth table for this function, you will see that the function takes the value “true”, or 1, only if all input operands are true. If at least one of the input parameters is equal to zero, or to the value “false”, then the result of the function will also be “false”.

concept of logical operation

This reflects the analogy with arithmetic multiplication: multiplying any number and a set of numbers by 0 as a result will always return 0. This logical operation is commutative: the order in which it receives the input parameters does not affect the final result of the calculation.

Another property of this function is associativity, or combination. This property allows not to take into account the calculation order when calculating the sequence of binary operations. Therefore, for 3 or more consecutive logical multiplication operations, there is no need to consider brackets. In programming, this function is often used to make sure that specific commands are executed only when a set of certain conditions is met.

Disjunction

The logical operation "OR" is a type of Boolean function, which is an analogue of algebraic addition. Other names for this function are logical addition, disjunction. Just like the logical multiplication operation, a disjunction can be binary (calculate the value based on two arguments), ternary or n-ary.

logical operation order

The truth table for a given logical operation is a kind of alternative to conjunction. The logical operation "OR" calculates the maximum result among the arguments provided. The disjunction takes the value false at the output, or 0 only if all input parameters come with the values ​​0 (false). In any other case, the output will receive the value “true”, or 1. To write this function, the mathematical sign of addition (“plus”) or two vertical stripes are most often used. The second option is common in most programming languages ​​and is preferable because it allows you to clearly separate the logical operation from the arithmetic one.

General properties of logical operations

Basic logical operations, whether unary, binary, ternary or other functions, are subject to certain rules and properties that describe their behavior. One of the fundamental properties possessed by the logical functions described above is commutativity.

logical operation and

This property ensures that the function value does not change from rearranging operand locations. Not all operations have this property. Unlike conjunctions and disjunctions, which satisfy the commutativity requirements, the matrix multiplication function is not, and permutation of the factors in this operation will entail a change in the result, as well as exponentiation.

Additional aspect

Another important property that is often used in electronics and circuitry is the subordination of pairs of logical operations to the laws of de Morgan.

logical operation or

These laws connect pairs of logical operations using the logical negation function, that is, they allow you to express one logical operation using another. For example, the conjunction negation function can be expressed using the disjunction of the negations of individual operands. With the help of these laws, the logical operations "AND", "OR" can be mutually expressed and implemented with minimal hardware costs. This property is extremely useful in circuitry, as it allows you to save resources when calculating and forming microcircuits.

Source: https://habr.com/ru/post/K6301/


All Articles