Boolean Logic
itComputer fundamentals
Boolean Logic
Boolean logic gives you a small language for decisions. A Boolean value has two possible states: true or false. You combine those values with operators to describe when a larger condition is true.
The model appears throughout computing. A program branches when a condition is true. A search keeps or rejects a record. A digital circuit combines high and low signals through logic gates. The notation changes across these settings, but the underlying truth relationships stay recognizable.
The three core operators
Start with three operators:
- NOT reverses one truth value.
- AND is true only when both inputs are true.
- OR is true when at least one input is true.
In Boolean logic, OR is inclusive. It is true when either input is true and also when both are true. XOR, or exclusive OR, handles the different rule: exactly one input must be true.
Suppose has_badge means a worker has a valid badge, and door_unlocked means the door is already unlocked.
has_badge AND NOT door_unlocked
This expression is true only when the worker has a badge and the door is locked. Each name is a proposition: a statement that can be assigned a truth value. The complete line is a Boolean expression.
Truth tables remove ambiguity
A truth table lists every possible input combination and the corresponding output. Two inputs produce four rows.
| A | B | A AND B | A OR B | A XOR B |
|---|---|---|---|---|
| true | true | true | true | false |
| true | false | false | true | true |
| false | true | false | true | true |
| false | false | false | false | false |
NOT needs only one input:
| A | NOT A |
|---|---|
| true | false |
| false | true |
Use truth tables when prose feels uncertain. A table forces you to check every case instead of reasoning from one convenient example.
Build expressions in layers
Treat a compound expression as a tree of smaller expressions. Evaluate the innermost or highest-priority part first.
(is_admin OR is_owner) AND NOT is_suspended
This rule grants access when the person is an administrator or owner, provided the account is not suspended. Parentheses make the grouping visible. Without them, operator precedence decides the grouping, and precedence rules vary by notation or programming language.
Names also carry part of the meaning. Positive names such as is_suspended are easier to negate than names containing a hidden negative. NOT is_not_suspended makes the reader untangle two negations before checking the rule.
Equivalence lets you rewrite safely
Two Boolean expressions are logically equivalent when they produce the same output for every input combination. You can prove equivalence by comparing their truth-table columns.
De Morgan's laws are two useful equivalences:
NOT (A AND B) = (NOT A) OR (NOT B)
NOT (A OR B) = (NOT A) AND (NOT B)
The operator changes when the negation moves inward. This detail matters. NOT (valid AND current) does not mean NOT valid AND NOT current. The original condition is false when either part is false, not only when both are false.
Other common laws include double negation, NOT (NOT A) = A, and idempotence, A AND A = A. These laws help you compare rules, simplify expressions, and move a negation to a clearer location.
Boolean logic in software
Comparisons often produce Boolean values. A condition such as temperature < limit can then be combined with other conditions.
Many programming languages short-circuit AND and OR. Once the left operand determines the result, the right operand is not evaluated. For A AND B, a false A determines that the whole expression cannot be true. For A OR B, a true A determines that the whole expression is true.
Short-circuiting can prevent unnecessary work or guard an operation:
record_exists AND record_is_valid
The exact syntax and returned value depend on the language. Python's and and or, for example, return one of their operands rather than always returning a bool. Read the language specification before relying on coercion, precedence, or evaluation order.
Logical operators also differ from bitwise operators. Logical operators combine truth conditions. Bitwise operators combine corresponding bits inside integer values. Some languages reuse related symbols, so check the types and operator definition instead of judging by appearance.
Where the model stops
Classical Boolean logic has exactly two truth values. Real systems sometimes add another state. SQL search conditions can be true, false, or unknown because of null values. Hardware descriptions may model unknown or high-impedance signals. These systems use logic, but their truth tables are not the two-value tables in this course.
Boolean expressions also cannot decide whether their input facts are accurate. A perfectly written access rule still fails its purpose if is_owner is populated incorrectly. Separate the logical structure from data quality, policy quality, and side effects.
Your working method is straightforward: name each proposition, make grouping explicit, enumerate the input combinations, and compare the output with the intended rule. That method scales from a two-condition branch to a larger policy.
