Boolean Logic
Learning Outcomes
- Combine sets using Boolean logic, using proper notations
- Use statements and conditionals to write and interpret expressions
- Use a truth table to interpret complex statements or conditionals
- Write truth tables given a logical implication, and it’s related statements – converse, inverse, and contrapositive
- Determine whether two statements are logically equivalent
- Use DeMorgan’s laws to define logical equivalences of a statement
Boolean Logic
We can often classify items as belonging to sets. If you went the library to search for a book and they asked you to express your search using unions, intersections, and complements of sets, that would feel a little strange. Instead, we typically using words like “and,” “or," and “not” to connect our keywords together to form a search. These words, which form the basis of Boolean logic, are directly related to set operations with the same terminology.Boolean Logic
Boolean logic combines multiple statements that are either true or false into an expression that is either true or false.- In connection to sets, a boolean search is true if the element in question is part of the set being searched.
Connection to Set Operations
A and B elements in the intersection A ⋂ B A or B elements in the union A ⋃ B Not A elements in the complement AcExample
Suppose we are searching a library database for Mexican universities. Express a reasonable search using Boolean logic.Answer: We could start with the search “Mexico and university”, but would be likely to find results for the U.S. state New Mexico. To account for this, we could revise our search to read: Mexico and university not “New Mexico”
Mexico university -“New Mexico”
Example
Describe the numbers that meet the condition: even and less than 10 and greater than 0Answer: The numbers that satisfy all three requirements are {2, 4, 6, 8}
Which Comes First?
Sometimes statements made in English can be ambiguous. For this reason, Boolean logic uses parentheses to show precedent, just like in algebraic order of operations. The English phrase “Go to the store and buy me eggs and bagels or cereal” is ambiguous; it is not clear whether the requestors is asking for eggs always along with either bagels or cereal, or whether they’re asking for either the combination of eggs and bagels, or just cereal. For this reason, using parentheses clarifies the intent:Eggs and (bagels or cereal) means | Option 1: Eggs and bagels, Option 2: Eggs and cereal |
(Eggs and bagels) or cereal means | Option 1: Eggs and bagels, Option 2: Cereal |
Example
Describe the numbers that meet the condition: odd number and less than 20 and greater than 0 and (multiple of 3 or multiple of 5)Answer: The first three conditions limit us to the set {1, 3, 5, 7, 9, 11, 13, 15, 17, 19} The last grouped conditions tell us to find elements of this set that are also either a multiple of 3 or a multiple of 5. This leaves us with the set {3, 5, 9, 15} Notice that we would have gotten a very different result if we had written (odd number and less than 20 and greater than 0 and multiple of 3) or multiple of 5 The first grouped set of conditions would give {3, 9, 15}. When combined with the last condition, though, this set expands without limits:
{3, 5, 9, 15, 20, 25, 30, 35, 40, 45, …}
Conditionals
Beyond searching, Boolean logic is commonly used in spreadsheet applications like Excel to do conditional calculations. A statement is something that is either true or false.Example
A statement like 3 < 5 is true; a statement like “a rat is a fish” is false. A statement like “x < 5” is true for some values of x and false for others. When an action is taken or not depending on the value of a statement, it forms a conditional.Statements and Conditionals
A statement is either true or false. A conditional is a compound statement of the form “if p then q” or “if p then q, else s”.Excel
Conditional statements are commonly used in spreadsheet applications like Excel. In Excel, you can enter an expression like=IF(A1<2000, A1+1, A1*2)
Notice that after the IF, there are three parts. The first part is the condition, and the second two are calculations. Excel will look at the value in cell A1 and compare it to 2000. If that condition is true, then the first calculation is used, and 1 is added to the value of A1 and the result is stored. If the condition is false, then the second calculation is used, and A1 is multiplied by 2 and the result is stored. In other words, this statement is equivalent to saying “If the value of A1 is less than 2000, then add 1 to the value in A1. Otherwise, multiple A1 by 2”Example
Write an Excel command that will create the condition “A1 < 3000 and A1 > 100”.Answer: Enter “AND(A1<3000, A1>100)”. Likewise, for the condition “A1=4 or A1=6” you would enter “OR(A1=4, A1=6)”
Example
Given the Excel expression:IF(A1 > 5, 2*A1, 3*A1)
Find the following:- the result if A1 is 3, and
- the result if A1 is 8
Answer: This is equivalent to saying
If A1 >5, then calculate 2*A1. Otherwise, calculate 3*A1
If A1 is 3, then the condition is false, since 3 > 5 is not true, so we do the alternate action, and multiple by 3, giving 3*3 = 9 If A1 is 8, then the condition is true, since 8 > 5, so we multiply the value by 2, giving 2*8=16Example
An accountant needs to withhold 15% of income for taxes if the income is below $30,000, and 20% of income if the income is $30,000 or more. Write an Excel expression that would calculate the amount to withhold.Answer: Our conditional needs to compare the value to 30,000. If the income is less than 30,000, we need to calculate 15% of the income: 0.15*income. If the income is more than 30,000, we need to calculate 20% of the income: 0.20*income. In words we could write “If income < 30,000, then multiply by 0.15, otherwise multiply by 0.20”. In Excel, we would write: =IF(A1<30000, 0.15*A1, 0.20*A1)
Example
A parent might say to their child “if you clean your room and take out the garbage, then you can have ice cream.” Under what circumstances will this conditional be true?Answer: Here, there are two simpler conditions:
- The child cleaning her room
- The child taking out the garbage
Example
In a spreadsheet, cell A1 contains annual income, and A2 contains number of dependents. A certain tax credit applies if someone with no dependents earns less than $10,000 and has no dependents, or if someone with dependents earns less than $20,000. Write a rule that describes this.Answer: There are two ways the rule is met: income is less than 10,000 and dependents is 0, or income is less than 20,000 and dependents is not 0. Informally, we could write these as (A1 < 10000 and A2 = 0) or (A1 < 20000 and A2 > 0) Notice that the A2 > 0 condition is actually redundant and not necessary, since we’d only be considering that or case if the first pair of conditions were not met. So this could be simplified to (A1 < 10000 and A2 = 0) or (A1 < 20000) In Excel’s format, we’d write = IF ( OR( AND(A1 < 10000, A2 = 0), A1 < 20000), “you qualify”, “you don’t qualify”)
Licenses & Attributions
CC licensed content, Original
- Revision and Adaptation. Provided by: Lumen Learning License: CC BY: Attribution.
CC licensed content, Shared previously
- Question ID 25462, 25592. Authored by: Lippman, David. License: CC BY: Attribution. License terms: IMathAS Community License CC-BY + GPL.
- Math in Society. Authored by: Lippman, David. Located at: http://www.opentextbookstore.com/mathinsociety/. License: CC BY: Attribution.
- Question ID 108578, 108573. Authored by: Hartley,Josiah. License: CC BY: Attribution. License terms: IMathAS Community License CC-BY + GPL.