Logic is the language of reasoningβboth for humans and machines. Learn how to express and combine true/false statements, the foundation of every if-statement, every decision boundary, and every neural network gate.
A proposition is a statement that is either true or falseβnever both, never neither. This binary nature is fundamental to how computers think.
"The sky is blue" β True
"5 > 10" β False
"Paris is in France" β True
"2 + 2 = 5" β False
"This model is trained" β True/False
"Hello!" β Greeting, not T/F
"What time is it?" β Question, not T/F
"x + 5" β Expression, not T/F
"Maybe" β Not definite T/F
"Do your homework" β Command, not T/F
Every proposition has exactly one of two truth values:
Computers are built on binary: everything is 0 or 1, off or on, false or true. This isn't a limitationβit's incredibly powerful. Complex decisions are built by combining many simple true/false questions.
Classification models answer propositions: "Is this email spam?" (T/F), "Is this a cat?" (T/F). Even when models output probabilities (0.73), we often threshold them to get a final true/false decision.
These three operations let you combine and modify propositions to build complex conditions from simple ones.
NOT flips the truth value. If something is true, NOT makes it false, and vice versa.
NOT reverses the truth value:
NOT True = False
NOT False = True
Example:
"The light is on" is True
"The light is NOT on" is False
Python: not True β False
not False β True
not (5 > 3) β False
Math: Β¬T = F
Β¬F = T
AND is true only when both parts are true. Think of it as requiring two conditions to pass.
AND requires BOTH to be true:
True AND True = True β (both pass)
True AND False = False β (one fails)
False AND True = False β (one fails)
False AND False = False β (both fail)
Example:
"I have money" AND "Store is open" β Can I shop?
Both must be true to shop!
Python: True and True β True
True and False β False
(5 > 3) and (2 < 4) β True
Real example:
if age >= 18 and has_id:
allow_entry()
OR is true when at least one part is true. Think of it as needing only one condition to pass.
OR requires AT LEAST ONE to be true:
True OR True = True β (at least one)
True OR False = True β (at least one)
False OR True = True β (at least one)
False OR False = False β (neither passes)
Example:
"It's weekend" OR "It's holiday" β Can I sleep in?
Either one being true is enough!
Python: True or False β True
False or False β False
(5 > 10) or (2 < 4) β True
Real example:
if is_admin or is_moderator:
show_controls()
AND is strict: all must be true β "Both/All"
OR is lenient: any can be true β "At least one"
NOT is a flip: opposite truth value
If-then statements (implications) are the backbone of logical reasoning and programming. "If A is true, then B follows."
IF [condition] THEN [result]
"If it rains, then the ground gets wet"
Condition (antecedent): "it rains"
Result (consequent): "the ground gets wet"
Written as: P β Q (P implies Q)
An implication P β Q is only false when the condition (P) is true but the result (Q) is false. This is a broken promise.
| P (If) | Q (Then) | P β Q | Interpretation |
|---|---|---|---|
| T | T | T | Promise kept β |
| T | F | F | Promise broken β |
| F | T | T | No promise made |
| F | F | T | No promise made |
"If you pass the test, you get a certificate"
Pass? Certificate? Promise kept?
Yes Yes β True (got what was promised)
Yes No β False (promise broken!)
No Yes β True (bonus! no promise broken)
No No β True (no promise was made)
Decision trees are chains of if-then rules. "If pixel brightness > 128, then go right, else go left." Neural network activation: "If weighted sum > threshold, then fire." Even attention mechanisms use if-then logic: "If these tokens are related, then attend more."
A truth table systematically shows all possible input combinations and their outputs. It's the complete specification of a logical operation.
For n variables, you need 2βΏ rows:
1 variable (P): 2ΒΉ = 2 rows (T, F)
2 variables (P, Q): 2Β² = 4 rows (TT, TF, FT, FF)
3 variables: 2Β³ = 8 rows
4 variables: 2β΄ = 16 rows
NOT (Β¬P)
| P | Β¬P |
|---|---|
| T | F |
| F | T |
AND (P β§ Q)
| P | Q | P β§ Q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
OR (P β¨ Q)
| P | Q | P β¨ Q |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
XOR (P β Q) β Exclusive OR
| P | Q | P β Q |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
XOR = "one or the other, but not both"
Real-world XOR: "Soup or salad?" at a restaurant means you get one, not both!
Step by step for each row:
P Q β P AND Q β NOT P β (P AND Q) OR (NOT P)
βββββββββΌββββββββββΌββββββββΌβββββββββββββββββββββ
T T β T β F β T
T F β F β F β F
F T β F β T β T
F F β F β T β T
A single perceptron can learn AND and OR, but NOT XOR! This was the famous limitation discovered in 1969. It's why we need multiple layers (deep learning)βto combine simple logic gates into complex decision boundaries.
You've completed the beginner math foundations! Now you're ready for the core topics: