CODEBHAVYA • MATHEMATICAL THINKING

🔀 Logic and Truth Tables

Learn how statements become true or false, combine them using logical operators and evaluate conditions used in mathematics, algorithms and computer programs.

🎯 What You Will Learn

01 Identify propositions and determine their truth values.
02 Use NOT, AND, OR, XOR, implication and biconditional.
03 Construct and interpret complete truth tables.
04 Translate logical expressions into programming conditions.

💬 1. Statements and Propositions

A proposition is a declarative statement that has exactly one truth value: either true or false.

TRUE PROPOSITION

“8 is an even number.”

This statement is true.

FALSE PROPOSITION

“15 is divisible by 4.”

This statement is false.

NOT A PROPOSITION

“Close the window.”

A command does not have a truth value.

NOT A PROPOSITION

“What is your age?”

A question is neither true nor false.

Quick check: If you can meaningfully label a sentence as true or false, it is usually a proposition.

🔁 2. Truth Values and Negation

We write T for true and F for false. The NOT operator reverses a truth value.

NOT P = ¬P
P ¬P
T F
F T
Example P: “A student submitted the form.”
¬P: “A student did not submit the form.”

🔗 3. AND, OR and XOR Operators

AND • P ∧ Q

Both must be true

The result is true only when P and Q are both true.

OR • P ∨ Q

At least one is true

The result is false only when both statements are false.

XOR • P ⊕ Q

Exactly one is true

The result is true when P and Q have different values.

P Q P ∧ Q P ∨ Q P ⊕ Q
TTTTF
TFFTT
FTFTT
FFFFF
In logic, OR normally means inclusive OR: one or both statements may be true. XOR is used when exactly one must be true.

➡️ 4. Implication and Biconditional

IMPLICATION • P → Q

If P, then Q

It is false only when P is true but Q is false.

BICONDITIONAL • P ↔ Q

P if and only if Q

It is true when P and Q have the same truth value.

P Q P → Q P ↔ Q
TTTT
TFFF
FTTF
FFTT
Memory rule: A promise “If P, then Q” is broken only when P happens but Q does not happen.

🧱 5. How to Build a Truth Table

A truth table checks an expression under every possible combination of truth values.

  1. Count the variables. For example, P and Q means two variables.
  2. Calculate the rows. Use 2n, where n is the number of variables.
  3. List all combinations. For two variables: TT, TF, FT and FF.
  4. Create intermediate columns. Evaluate NOT operations before larger expressions.
  5. Evaluate the final column. Apply operators according to precedence.
1 variable2¹ = 2 rows
2 variables2² = 4 rows
3 variables2³ = 8 rows
4 variables2⁴ = 16 rows

🧮 6. Compound Expressions and Precedence

A compound expression contains more than one operator. Use parentheses whenever they make the intended order clearer.

Parentheses → NOT → AND → OR → Implication → Biconditional

Worked Example

Evaluate (P ∨ Q) ∧ ¬P when P = F and Q = T.

Solution

First, P ∨ Q = F ∨ T = T.

Next, ¬P = ¬F = T.

Finally, T ∧ T = T.

Final truth value: T

⚖️ 7. Equivalence and De Morgan’s Laws

Two expressions are logically equivalent when their final truth-table columns match for every row.

IMPLICATION P → Q ≡ ¬P ∨ Q

“If P then Q” can be rewritten using NOT and OR.

DE MORGAN 1 ¬(P ∧ Q) ≡ ¬P ∨ ¬Q

NOT of AND becomes OR of the negated statements.

DE MORGAN 2 ¬(P ∨ Q) ≡ ¬P ∧ ¬Q

NOT of OR becomes AND of the negated statements.

ALWAYS TRUE

Tautology

P ∨ ¬P

ALWAYS FALSE

Contradiction

P ∧ ¬P

SOMETIMES TRUE

Contingency

P ∧ Q

🧪 Truth Table Builder

Select a logical expression. The builder evaluates it for all four combinations of P and Q and explains its meaning.

💻 8. Logic in Programming

Programming conditions use the same reasoning as mathematical logic. The symbols may change, but the truth rules remain the same.

Logic C / Java-style symbol Example meaning
NOT ! !isEmpty: the collection is not empty
AND && age >= 18 && hasId: both requirements hold
OR || isAdmin || isOwner: either permission is enough
XOR idea != for Boolean values Exactly one of two Boolean choices is true
CodeBhavya Example A student may enter the lab when the booking is valid AND the identity card is active: validBooking && activeId.

🧩 9. Solved Problems

Problem 1

Evaluate P ∧ ¬Q when P = T and Q = F.

Solution

¬Q = ¬F = T.

P ∧ ¬Q = T ∧ T = T.

Answer: T

Problem 2

Classify P ∨ ¬P.

Solution

If P is true, P ∨ ¬P is T ∨ F = T.

If P is false, P ∨ ¬P is F ∨ T = T.

Answer: It is a tautology.

Problem 3

A portal permits access when a user is an administrator OR has both a valid account and an active subscription. Write the logical expression.

Solution

Let A = administrator, V = valid account and S = active subscription.

The two valid paths are A, or V together with S.

Answer: A ∨ (V ∧ S)

✍️ 10. Practice Problems

Decide each answer before opening the solution. Use a small truth table whenever the result is not immediately clear.

1. Is “x + 4 = 10” a proposition when x has not been specified?

2. Evaluate P ∨ Q when P = F and Q = T.

3. When is P → Q false?

4. Apply De Morgan’s law to ¬(P ∨ Q).

5. Evaluate (P ⊕ Q) ∧ R for P = T, Q = F and R = T.

📝 Quick Revision

  • A proposition has exactly one truth value: true or false.
  • NOT reverses a truth value.
  • AND needs both inputs to be true.
  • OR needs at least one input to be true.
  • XOR needs exactly one input to be true.
  • P → Q is false only for P = T and Q = F.
  • P ↔ Q is true when P and Q match.
  • n variables require 2n truth-table rows.
  • Equivalent expressions have identical final columns.
  • Programming conditions use the same Boolean truth rules.

🔀 Logic and Truth Tables Practice

You have learned, visualized, solved and revised the topic. Now answer all 20 questions and submit once. Your score, correct answers and explanations appear only after submission.

Start 20-Question Test →