Boolean operations are essential for mathematics because they're used for proving of different theorems. These operations are also widely applied in Computer Science, since many logical expressions and constructions are used in boolean conditions. Here you'll learn properties of these operations which will help you to simplify logical expressions.
Operation with constant 0 and 1
The operator of conjunction can be denoted by all the following symbols: and the operator of disjunction can be denoted using all the following symbols: .
At first, let's focus on the identity law.
It states that any variable remains unchanged in the operation OR with or AND with .
Let's build truth tables of these operations:
0 | 0 | 0 |
1 | 1 | 1 |
So, now it's obvious that the results of these two operations depend only on the value of and are equal to it.
Here's an example of the identity law. Imagine that while you were solving a coding problem, you wrote a condition for an integer like the following one:
if a > 0 and (a == a) then
...Is this condition efficient? Of course not! For any integer number and the second statement is always true. It means that this logical statement can be simplified using the second statement of the identity law: .
Let's move on to the annulment law.
The result of the AND operation between a variable and is , while the result of the OR operation with is .
Here are truth tables of these operations:
1 | 0 | 1 |
0 | 0 | 1 |
As you can see, the results don't depend on the value of and only depend on the value of the second variable: 0 in the first case and 1 in the second.
Here's an example of application of the annulment law. Imagine that you're coding, and you have a condition for an integer variable like:
if (a/a == 1) or a > 3 then
...For any integer number , so the first statement is always true. So, the whole logical statement is . The result is always equal to according to the annulment law. Many programming languages were built using this law, so the value of the second logical statement won't be calculated because its value doesn't affect the result.
Double negation
Now we can focus on the double negation law. This law states that the double negation of an expression is equal to this expression.
This law may seem confusing, but if you build the truth table of this operation, everything will become clear.
1 | 0 | 1 |
0 | 1 | 0 |
As you see from the table, the result of this operation is equal to the value of .
Here's also a visual illustration of this law.
Complement and idempotent laws
First, we should define the universal set. It is the set of all elements under consideration. For instance, if you have two sets and the universal set will include all the elements of these two sets: .
Now we can move on to the complement and idempotent laws. The complement law states that
Let's use Venn diagrams to visualize these laws.
You see that there are no elements which belong to the set and at the same time and that all elements of these sets together make the universal set.
The idempotent law states that
Let's once again build the truth table of these operations:
0 | 0 | 0 |
1 | 1 | 1 |
As you see from the table, the result is equal to the value of .
Here's how this law can be applied. Imagine that you have a set . If you try to find an intersection of and you'll get a set with elements which belong to and at the same time and this set will be , so it is equal to the set . And the same thing will happen if you try to find the union of the set and .
Commutative law
Let's move on to the commutative law. This law states that changing the sequence of the variables does not have any effect on the result.
Here's an example of application of this law.
Any alphabet can be represented as a set. Let be the English alphabet and be the German alphabet.
Let's find the intersection of these sets.
If we begin with the set , we'll try to find every element of this set in the set . Here we won't face any problems and get a new set which represents the intersection of and . If we begin with the set , we'll try to find every element of this set in the set . We won't be able to find , so we won't include them into the set which represents the intersection of and and we'll get . As you can see, . So, the result doesn't change if we change the sequence of the sets.
Complex laws
Now we're ready to focus on more complex laws.
The first law is the distributive law.
This law states that
Here are Venn diagrams of this law. The first statement looks like this:
And the second statement looks as below:
Let's move on to the associative law.
This law states that
Here are some illustrations of this law. The first statement:
And the second one:
And now we can move to the absorptive law.
This law states that
Here are Venn diagrams of this law:
And last but not least, let's focus on de Morgan's laws.
These laws state that
We won't prove these laws. Here's an illustration to help you to understand these laws:
Application of boolean algebra laws
Remember how we discussed the usefulness of boolean laws for simplifying expressions? Let's simplify the following complex expression that your friend ended up with while solving a coding problem.
Given
Let's begin with applying the second de Morgan's law and the double negation law to the last term:
Now we get the following expression:
We can change the sequence of the variables according to the commutative law:
Now let's apply the second statement of the absorptive law to the first two terms:
Now we get:
Let's apply the first statement of the distributive law:
Now let's apply the second statement of the complement law:
So, finally we get according to the second statement of the identity law that:
You see that we've just simplified a big and a little bit terrifying logical expression and got a small and easy to understand logical expression!
Conclusion
Let's sum up all the laws which you've just learned.
The identity law: and
The annulment law: and
The double negation law:
The complement law: and
The idempotent law: and
The commutative law: and
The distributive law:
The associative law:
The absorptive law:
De Morgan's laws:
Now that you know all these rules, it's time to put them into practice!