Boolean Expressions
Learn to write and evaluate Boolean expressions with 1 and 0, use the order of operations NOT, AND, OR, and build their full truth tables.
Definition
- flips the value: and
- is only when both and are
- is when at least one of them is
Try it now
Worked Examples
Evaluate for and .
Substitute the values
Replace with and with →
Do NOT first
→
Do AND
Both values are , so AND gives
Answer: (true) for , .
Common Mistakes
Working left to right:
Why it's wrong: AND comes before OR, just as multiplication comes before addition. Without parentheses, the AND part is done first.
Correct:
Applying NOT to everything after it: reading as
Why it's wrong: Without parentheses, NOT applies only to the variable directly after it.
Correct: . To negate the whole AND, write .
Adding like numbers:
Why it's wrong: A Boolean expression can only be or . OR asks whether at least one value is , it does not count them.
Correct: , and . The answer is always or .
Calling two expressions equivalent after testing only one or two inputs
Why it's wrong: and give the same value in 6 of the 8 rows, yet they are different.
Correct: Build the full table with rows and compare every row. One row that differs means not equivalent.
Interactive Visual
Truth Table
| A | B | C | ¬C | B ∧ ¬C | A ∨ B ∧ ¬C |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 1 |
1= True0= False
Truth Table
| A | B | A ∨ ¬A ∧ B |
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
1= True0= False
Interactive Sandbox
Expression Calculator
Try these:
History
No calculations yet
Practice Problems
18 problemsIn (no parentheses), which operation is done first?
Why It Matters
- Programming: every if-condition is a Boolean expression, such as (age at least 12 AND NOT banned) OR has a parent. Forget the parentheses and the program lets in the wrong people
- Search and filters: online shops and libraries combine filters like in stock AND (red OR blue)
- Spreadsheets: functions such as AND(), OR() and NOT() decide which rows are highlighted
- Electronics: every chip turns Boolean expressions into circuits of logic gates, as you will see in the Logic Gates lesson
- Games and smart homes: a door opens or a light switches on when an expression of several sensors equals 1
Real World Applications
Rules in a Program
Programmers write rules as Boolean expressions and test every combination of inputs before the program goes live.
Example:
A theme park ride lets you in if : = you have a ticket, = you are tall enough, = a parent rides with you.
The ride rule is . A child has a ticket (), is not tall enough () and rides with a parent ().
How many test cases does the rule have, and may the child ride?
Step 1: Write the mathematical expression
Write the number of test cases as a power of 2:
Spam Filters
An email program decides with a Boolean expression whether a message goes to the spam folder.
Example:
A filter marks an email as spam if : = sender is on a block list, = suspicious words, = sender is in your contacts.
The rule is . An email from a friend in your contacts () contains a suspicious word (), and the sender is not on the block list (). With 0 and 1, AND works like multiplication and NOT like .
Does the email go to spam?
Step 1: Write the mathematical expression
Write as a calculation:
Smart Home Rules
Two different expressions can control a device in exactly the same way. A truth table shows when a long rule can be replaced by a short one.
Example:
A garden light uses the rule : = motion detected, = it is night.
An engineer wants to replace the rule with the shorter rule .
Do the two rules always switch the light the same way?
Step 1: Write the mathematical expression
Write the number of rows as a power of 2:
Key Takeaways
- 1A Boolean expression combines variables, the values 1 (true) and 0 (false) and the operators , ,
- 2The value of a Boolean expression is always 1 or 0, never 2 or more
- 3Order of operations: parentheses first, then NOT, then AND, then OR
- 4NOT applies only to what comes directly after it: is not
- 5An expression with variables has a truth table with rows, starting with the row where all variables are 0
- 6Two expressions are equivalent when their final columns are the same in every row
Frequently Asked Questions
Glossary
- Boolean variable
- A letter such as , or that can only take the values 1 (true) or 0 (false)
- Boolean expression
- A formula made of Boolean variables, the values 1 and 0 and the operators , ,
- Order of operations
- The rule for which operator is done first: parentheses, then NOT, then AND, then OR
- Truth table
- A table that lists the value of an expression for all combinations of its variables
- Equivalent
- Two expressions are equivalent when they have the same value in every row of the truth table
Formula Card
Order of operations
Parentheses first, then NOT, then AND, then OR
NOT
Flips the value of what comes directly after it
AND and OR
AND is 1 only if both are 1; OR is 0 only if both are 0
Number of rows
$n$ is the number of variables: $2^2 = 4$, $2^3 = 8$