🧠 Beginner β€’ Mathematics

Logic Basics for AI

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.

⏱ 10-12 minutes

🎯 What You'll Learn

  • What propositions and truth values are
  • The three fundamental operations: AND, OR, NOT
  • How to reason with if-then statements
  • Reading and building truth tables
  • How logic underlies AI decision-making

1 Propositions & Truth Values

A proposition is a statement that is either true or falseβ€”never both, never neither. This binary nature is fundamental to how computers think.

βœ“ Valid Propositions

"The sky is blue" β†’ True "5 > 10" β†’ False "Paris is in France" β†’ True "2 + 2 = 5" β†’ False "This model is trained" β†’ True/False

βœ— Not Propositions

"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

Truth Values

Every proposition has exactly one of two truth values:

  • True (T) β€” often represented as 1
  • False (F) β€” often represented as 0

πŸ’‘ Binary Thinking

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.

πŸ€– In AI

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.

2 AND / OR / NOT

These three operations let you combine and modify propositions to build complex conditions from simple ones.

NOT (Negation) β€” Β¬ or !

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
                    

πŸ“ NOT in Code

Python: not True β†’ False not False β†’ True not (5 > 3) β†’ False Math: Β¬T = F Β¬F = T

AND (Conjunction) β€” ∧ or &&

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!
                    

πŸ“ AND in Code

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 (Disjunction) β€” ∨ or ||

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!
                    

πŸ“ OR in Code

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()

πŸ’‘ Remember the Pattern

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

3 If-Then Reasoning

If-then statements (implications) are the backbone of logical reasoning and programming. "If A is true, then B follows."

Structure

        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)
                    

When is If-Then True?

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

πŸ“ Real Example

"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)

πŸ€– If-Then in AI

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."

4 Truth Tables

A truth table systematically shows all possible input combinations and their outputs. It's the complete specification of a logical operation.

Building a Truth Table

  1. List all variables (P, Q, etc.)
  2. Write all possible combinations of T/F
  3. Compute the result for each combination
        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
                    

Complete Reference Tables

NOT (Β¬P)

P¬P
TF
FT

AND (P ∧ Q)

PQP ∧ Q
TTT
TFF
FTF
FFF

OR (P ∨ Q)

PQP ∨ Q
TTT
TFT
FTT
FFF

XOR (P βŠ• Q) β€” Exclusive OR

PQP βŠ• Q
TTF
TFT
FTT
FFF

XOR = "one or the other, but not both"

Real-world XOR: "Soup or salad?" at a restaurant means you get one, not both!

Complex Expression Example

πŸ“ Evaluate: (P AND Q) OR (NOT P)

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

πŸ€– Logic Gates in Neural Networks

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.

🎯 Key Takeaways

  • Propositions are statements that are either True or False
  • NOT flips truth values; AND requires all true; OR requires at least one
  • If-then is only false when the condition is true but the result is false
  • Truth tables exhaustively show all input/output combinations
  • Logic is the foundation of programming conditions and AI decision-making

What's Next?

You've completed the beginner math foundations! Now you're ready for the core topics: