Computer Science and IT›⌂ 0:00 studied

Module 1 · 17 min read · Free chapter

Propositional and first-order logic

In short

A proposition is true or false. The implication p → q is false only when p is true and q is false, and it equals its contrapositive ¬q → ¬p. Quantifiers flip under negation: ¬∀x P(x) ≡ ∃x ¬P(x). When translating, ∀ goes with → and ∃ goes with ∧.

What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: rules that are either kept or broken

At a railway station the TTE follows a simple rule: "If your ticket is confirmed, then you may board the AC coach." Think of four travellers. One has a confirmed ticket and boards, one has a confirmed ticket and is stopped, one is on the waiting list and boards anyway because a berth fell free, and one is on the waiting list and stays out.

Which traveller shows that the rule was broken? Only the second one, who had a confirmed ticket and was still stopped. The rule says nothing about waiting-list travellers, so whatever happens to them, the rule stands.

This is logic in its plainest form. Each statement here, such as "the ticket is confirmed" or "the traveller boards", is either true or false. Logic gives exact rules for combining such statements and for deciding when a conclusion really follows.

Why it matters. Every if-condition in a program, every database query and every circuit is a logical formula. GATE asks you to check equivalences, decide validity and turn English sentences into formulas, so these rules must be second nature.

Propositions, connectives and truth tables

A proposition is a declarative sentence that is either true (T)(T) or false (F)(F), but not both. "Delhi is the capital of India" is a proposition, and so is "7 is even", which is simply false. "Close the door" and "x+2=5x + 2 = 5" are not propositions, because the first is a command and the second depends on xx.

We name propositions with letters pp, qq, rr and join them with five connectives. Negation ¬p\neg p flips the value. Conjunction p∧qp \land q is true only when both are true, and disjunction p∨qp \lor q is false only when both are false. Implication p→qp \to q is false only when pp is true and qq is false, and the biconditional p↔qp \leftrightarrow q is true when both sides have the same value.

p q p∧qp \land q p∨qp \lor q p→qp \to q p↔qp \leftrightarrow q
T T TT T T T
T F FF T F F
F T FF T T F
F F FF F T T

A truth table lists every combination of input values. With nn variables there are 2n2^n rows, because each variable doubles the count. Each row can then be marked TT or FF in the output column, so the number of different truth functions of nn variables is 22n2^{2^n}. For two variables that is 24=162^4 = 16, and for three variables it is 28=2562^8 = 256.

Worked example. Is (p∧q)→p(p \land q) \to p always true? The only way to make an implication false is a true left side with a false right side. If p∧qp \land q is true, then pp is true, so the right side cannot be false. Hence the formula is true in all four rows.

Why it matters. The truth table is the final judge for any propositional question. When a shortcut fails or you are unsure, eight rows for three variables settle the matter in under a minute.

Implication and its relatives

The implication p→qp \to q causes more mistakes than any other connective. It is false in exactly one case: pp true and qq false. When pp is false, the implication is true whatever qq is, which is called being vacuously true. This matches the TTE rule: a waiting-list traveller can never break a rule about confirmed tickets.

Because the only false case is "pp and not qq", we get the key equivalence p→q≡¬p∨qp \to q \equiv \neg p \lor q. English has many ways to say p→qp \to q: "if pp then qq", "qq if pp", "pp only if qq", "pp is sufficient for qq" and "qq is necessary for pp". Note especially that "pp only if qq" means p→qp \to q, not q→pq \to p.

From p→qp \to q we can build three related statements. The converse is q→pq \to p, the inverse is ¬p→¬q\neg p \to \neg q, and the contrapositive is ¬q→¬p\neg q \to \neg p. The contrapositive always has the same truth table as the original, and the converse always matches the inverse.

Worked example. Take "If a number is divisible by 4, then it is even." The contrapositive "If a number is not even, then it is not divisible by 4" is also true. The converse "If a number is even, then it is divisible by 4" is false, since 6 is even but not divisible by 4.

Why it matters. Proof by contrapositive is one of the main proof methods in mathematics. In exams, confusing the converse with the original is the single most common logic error.

Tautologies, equivalences and complete sets

A formula that is true in every row is a tautology, such as p∨¬pp \lor \neg p. A formula false in every row is a contradiction, such as p∧¬pp \land \neg p, and anything in between is a contingency. A formula is satisfiable if at least one row makes it true, so every tautology and every contingency is satisfiable.

There is a neat link between these ideas. A formula FF is valid (a tautology) exactly when ¬F\neg F is unsatisfiable. Two formulas A and BB are logically equivalent, written A≡BA \equiv B, when A↔BA \leftrightarrow B is a tautology, that is when their truth tables match row for row.

A small set of laws lets you simplify formulas without tables:

  • De Morgan's laws say that ¬(p∧q)≡¬p∨¬q\neg (p \land q) \equiv \neg p \lor \neg q and ¬(p∨q)≡¬p∧¬q\neg (p \lor q) \equiv \neg p \land \neg q.
  • The distributive laws say that p∧(q∨r)≡(p∧q)∨(p∧r)p \land (q \lor r) \equiv (p \land q) \lor (p \land r) and p∨(q∧r)≡(p∨q)∧(p∨r)p \lor (q \land r) \equiv (p \lor q) \land (p \lor r).
  • The absorption laws say that p∨(p∧q)≡pp \lor (p \land q) \equiv p and p∧(p∨q)≡pp \land (p \lor q) \equiv p.
  • The biconditional splits as p↔q≡(p→q)∧(q→p)p \leftrightarrow q \equiv (p \to q) \land (q \to p).
  • Exportation says that p→(q→r)≡(p∧q)→rp \to (q \to r) \equiv (p \land q) \to r, and proof by cases says that (p→r)∧(q→r)≡(p∨q)→r(p \to r) \land (q \to r) \equiv (p \lor q) \to r.

Worked example. Show that ((p→q)∧(q→r))→(p→r)((p \to q) \land (q \to r)) \to (p \to r) is a tautology. Suppose it is false; then p→rp \to r is false, so p=Tp = T and r=Fr = F. Then p→qp \to q forces q=Tq = T, and q→rq \to r with r=Fr = F forces q=Fq = F, which is impossible, so no false row exists.

A set of connectives is functionally complete if every truth function can be written with it alone. The sets {¬,∧}\{\neg, \land \}, {¬,∨}\{\neg, \lor \} and {¬,→}\{\neg, \to \} are complete, and so are the single gates NAND and NOR. The set {∧,∨}\{\land, \lor \} is not complete, because any formula built only from ∧\land and ∨\lor is true when all inputs are true, so it can never express ¬p\neg p.

Why it matters. Equivalences are how compilers simplify conditions and how circuit designers reduce gates. Knowing that NAND alone is complete explains why chips can be built from a single kind of gate, which links straight to Boolean algebra and minimisation.

Normal forms: CNF and DNF

A literal is a variable or its negation, such as pp or ¬q\neg q. A formula is in disjunctive normal form (DNF) when it is an OR of terms and each term is an AND of literals, like (p∧¬q)∨(¬p∧r)(p \land \neg q) \lor (\neg p \land r). It is in conjunctive normal form (CNF) when it is an AND of clauses and each clause is an OR of literals, like (p∨q)∧(¬p∨r)(p \lor q) \land (\neg p \lor r).

Every formula can be converted into both forms, and the safe recipe has three steps. First, remove ↔\leftrightarrow and →\to using p→q≡¬p∨qp \to q \equiv \neg p \lor q. Second, push every ¬\neg inward with De Morgan's laws until it sits on a variable. Third, distribute ∨\lor over ∧\land for CNF, or ∧\land over ∨\lor for DNF.

Worked example. Convert ¬(p→q)∨r\neg (p \to q) \lor r into CNF. First ¬(p→q)≡¬(¬p∨q)≡p∧¬q\neg (p \to q) \equiv \neg (\neg p \lor q) \equiv p \land \neg q, so the formula is (p∧¬q)∨r(p \land \neg q) \lor r, which is already a DNF. Distributing rr gives (p∨r)∧(¬q∨r)(p \lor r) \land (\neg q \lor r), which is the CNF.

There is also a direct way from the truth table. Each row where the formula is true gives a minterm, an AND of all variables with ¬\neg on those that are FF, and the OR of these minterms is the full DNF. Each false row gives a maxterm, an OR of all variables with ¬\neg on those that are TT, and the AND of these is the full CNF. So a formula of three variables that is true in 3 rows has 3 minterms and 5 maxterms.

Why it matters. SAT solvers, which check huge circuits and schedules, take input in CNF. The resolution rule of the next section works only on clauses, so CNF is the working format of automated reasoning.

Rules of inference and valid arguments

An argument is a list of premises followed by a conclusion. It is valid when the conclusion must be true whenever all premises are true. In symbols, premises P1P_1, …, PnP_n and conclusion CC form a valid argument exactly when (P1∧⋯∧Pn)→C(P_1 \land \dots \land P_n) \to C is a tautology.

Instead of building a large table, we chain small valid steps called rules of inference:

Rule From Conclude
Modus ponens pp, p→qp \to q q
Modus tollens ¬q\neg q, p→qp \to q ¬p\neg p
Hypothetical syllogism p→qp \to q, q→rq \to r p→rp \to r
Disjunctive syllogism p∨qp \lor q, ¬p\neg p q
Resolution p∨qp \lor q, ¬p∨r\neg p \lor r q∨rq \lor r
Simplification and addition p∧qp \land q, and pp pp, and p∨qp \lor q

Two patterns look like valid rules but are fallacies. Affirming the consequent goes from qq and p→qp \to q to pp, and denying the antecedent goes from ¬p\neg p and p→qp \to q to ¬q\neg q. Both fail in the row where pp is false and qq is true.

Worked example. Premises: "If it rains, the match is cancelled" (r→c)(r \to c), "If the match is cancelled, we go to the cinema" (c→m)(c \to m), and "We did not go to the cinema" (¬m)(\neg m). Hypothetical syllogism gives r→mr \to m, and modus tollens with ¬m\neg m gives ¬r\neg r. So the valid conclusion is "It did not rain".

Why it matters. Program verification tools and expert systems chain exactly these rules. In GATE you will be given three or four premises and asked which conclusion follows, and naming the rule for each step is the fastest route.

Predicates and quantifiers

Propositional logic cannot express "every student passed" in a useful way, because it has no way to talk about many objects at once. First-order logic adds predicates and quantifiers. A predicate P(x)P(x) such as "xx passed" is neither true nor false until we fix xx from a domain, here the students of a class.

The universal quantifier ∀xP(x)\forall x P(x) says "P(x)P(x) holds for every xx in the domain". The existential quantifier ∃xP(x)\exists x P(x) says "P(x)P(x) holds for at least one xx". On a finite domain {a1,…,an}\{a_1, \dots, a_n\}, ∀\forall is a long AND and ∃\exists is a long OR, which is the best way to understand both.

That picture gives the negation rules at once. By De Morgan, ¬∀xP(x)≡∃x¬P(x)\neg \forall x P(x) \equiv \exists x \neg P(x) and ¬∃xP(x)≡∀x¬P(x)\neg \exists x P(x) \equiv \forall x \neg P(x). To negate a formula with several quantifiers, move ¬\neg to the right one step at a time and flip each quantifier it crosses: ¬∀x∃yP(x,y)≡∃x∀y¬P(x,y)\neg \forall x \exists y P(x, y) \equiv \exists x \forall y \neg P(x, y).

Some quantifier laws are full equivalences and some go one way only:

  • ∀x(P(x)∧Q(x))≡∀xP(x)∧∀xQ(x)\forall x (P(x) \land Q(x)) \equiv \forall x P(x) \land \forall x Q(x), and ∃x(P(x)∨Q(x))≡∃xP(x)∨∃xQ(x)\exists x (P(x) \lor Q(x)) \equiv \exists x P(x) \lor \exists x Q(x).
  • ∀xP(x)∨∀xQ(x)→∀x(P(x)∨Q(x))\forall x P(x) \lor \forall x Q(x) \to \forall x (P(x) \lor Q(x)) is valid, but the reverse is not.
  • ∃x(P(x)∧Q(x))→∃xP(x)∧∃xQ(x)\exists x (P(x) \land Q(x)) \to \exists x P(x) \land \exists x Q(x) is valid, but the reverse is not.
  • ∃y∀xP(x,y)→∀x∃yP(x,y)\exists y \forall x P(x, y) \to \forall x \exists y P(x, y) is valid, but the reverse is not.

Worked example. Let the domain be integers and P(x,y)P(x, y) be "x+y=0x + y = 0". ∀x∃yP(x,y)\forall x \exists y P(x, y) is true, since each xx has y=−xy = -x. ∃y∀xP(x,y)\exists y \forall x P(x, y) is false, since no single yy works for every xx. So swapping ∀\forall and ∃\exists changes the meaning.

Why it matters. Database queries in SQL and relational calculus are first-order formulas over tables. A formula is valid in first-order logic when it is true in every domain and every interpretation, and GATE often asks which of four such formulas is valid.

Translating English into logic

GATE regularly gives an English sentence and four formulas, and asks which formula matches. Four patterns cover almost every case, and the key is which connective goes with which quantifier.

English Formula
All A are BB ∀x(A(x)→B(x))\forall x (A(x) \to B(x))
Some A are BB ∃x(A(x)∧B(x))\exists x (A(x) \land B(x))
No A is BB ∀x(A(x)→¬B(x))\forall x (A(x) \to \neg B(x)), same as ¬∃x(A(x)∧B(x))\neg \exists x (A(x) \land B(x))
Not all A are BB ∃x(A(x)∧¬B(x))\exists x (A(x) \land \neg B(x))
Only A are BB ∀x(B(x)→A(x))\forall x (B(x) \to A(x))

The rule of thumb is simple: ∀\forall goes with →\to, and ∃\exists goes with ∧\land. Writing ∀x(A(x)∧B(x))\forall x (A(x) \land B(x)) would claim that everything in the domain is an A, which is far too strong. Writing ∃x(A(x)→B(x))\exists x (A(x) \to B(x)) is far too weak, because it becomes true as soon as one object is not an A.

Worked example. Translate "Not every graduate gets a job" with G(x)G(x) for "xx is a graduate" and J(x)J(x) for "xx gets a job". Start with ¬∀x(G(x)→J(x))\neg \forall x (G(x) \to J(x)). Push the negation in: ∃x¬(G(x)→J(x))≡∃x¬(¬G(x)∨J(x))≡∃x(G(x)∧¬J(x))\exists x \neg (G(x) \to J(x)) \equiv \exists x \neg (\neg G(x) \lor J(x)) \equiv \exists x (G(x) \land \neg J(x)), which reads "some graduate does not get a job".

Sentences with two quantifiers need care about order. "Every student has a friend" is ∀x∃yF(x,y)\forall x \exists y F(x, y), while "Someone is a friend of every student" is ∃y∀xF(x,y)\exists y \forall x F(x, y). The second is much stronger, since one person must be a friend of all.

Why it matters. Writing a correct database query or a correct specification is exactly this translation. A wrong connective under a quantifier produces a query that returns the wrong rows without any error message.

Descriptive lens: how written papers ask this

Written papers for scientist posts and university-level tests ask about logic in four ways:

  1. Prove that a formula is a tautology, either by truth table or by a chain of equivalences.
  2. Convert a formula into CNF and DNF and state the minterms or maxterms.
  3. Test an argument for validity using named rules of inference, or show it is a fallacy with a counter-example row.
  4. Translate English statements into quantified formulas and negate them in simplest form.

Practice questions (our own, not previous-year questions).

  1. Show without a truth table that (p→q)∧(p→r)≡p→(q∧r)(p \to q) \land (p \to r) \equiv p \to (q \land r). (8 marks)
  2. Test the validity of this argument: "If the server is up, the site loads. The site does not load. Hence the server is down." Name each rule used. (8 marks)
  3. Write "Every program that compiles is not necessarily correct" in first-order logic, then negate it and simplify. (10 marks)

Answer plan for question 2.

  • Let ss stand for "the server is up" and ll for "the site loads", so the premises are s→ls \to l and ¬l\neg l.
  • State that the conclusion "the server is down" is ¬s\neg s.
  • Apply modus tollens to s→ls \to l and ¬l\neg l, which gives ¬s\neg s directly.
  • Conclude that the argument is valid, because the conclusion follows by a valid rule.
  • Add a check that (s→l)∧¬l→¬s(s \to l) \land \neg l \to \neg s is true in all four rows of its truth table.

Quick revision

  • A proposition is either true or false, and nn variables give 2n2^n rows and 22n2^{2^n} truth functions.
  • p→qp \to q is false only for p=Tp = T and q=Fq = F, and it equals ¬p∨q\neg p \lor q.
  • An implication equals its contrapositive, and the converse equals the inverse.
  • A tautology is always true, a contradiction is always false, and FF is valid exactly when ¬F\neg F is unsatisfiable.
  • NAND alone and NOR alone are functionally complete, but {∧,∨}\{\land, \lor \} is not.
  • Full DNF takes one minterm per true row, and full CNF takes one maxterm per false row.
  • Modus ponens, modus tollens, hypothetical syllogism, disjunctive syllogism and resolution are valid rules.
  • ¬∀xP(x)≡∃x¬P(x)\neg \forall x P(x) \equiv \exists x \neg P(x), and ¬∃xP(x)≡∀x¬P(x)\neg \exists x P(x) \equiv \forall x \neg P(x).
  • ∀\forall goes with →\to and ∃\exists goes with ∧\land when translating English.
  • ∃y∀xP(x,y)\exists y \forall x P(x, y) implies ∀x∃yP(x,y)\forall x \exists y P(x, y), but not the other way round.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 15 answered

  1. Which of these is a proposition?

  2. How many different truth functions (Boolean functions) of 3 variables exist?

  3. p→qp \to q is false when:

  4. Which statement is logically equivalent to p→qp \to q?

  5. The formula (p∧q)→p(p \land q) \to p is:

  6. Which set of connectives is NOT functionally complete?

  7. (p→r)∧(q→r)(p \to r) \land (q \to r) is equivalent to:

  8. A formula of 3 variables is true in exactly 3 rows of its truth table. Its full CNF has how many maxterms?

  9. From p→qp \to q and ¬q\neg q we may validly conclude:

  10. Which inference is a fallacy?

  11. Over the domain {1,2,3}\{1, 2, 3\}, ∃xP(x)\exists x P(x) is the same as:

  12. ¬∀x∃yP(x,y)\neg \forall x \exists y P(x, y) is equivalent to:

  13. Which formula is valid?

  14. 'Not all rainy days are cold' (R(d):dR(d): d is rainy, C(d)C(d): dd is cold) is:

  15. In GATE CS, propositional and first-order logic is listed under:

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

When is p → q false?

Only when p is true and q is false. In every other row, including when p is false, the implication is true.

Which statement is equivalent to an implication?

The contrapositive ¬q → ¬p is equivalent to p → q. The converse q → p is not.

How do you negate a quantified statement?

Move ¬ inward and flip each quantifier it crosses, so ¬∀x P(x) becomes ∃x ¬P(x).

How is 'All A are B' written in logic?

It is ∀x (A(x) → B(x)). 'Some A are B' is ∃x (A(x) ∧ B(x)).

More in this module: Discrete mathematics

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Discrete Mathematics (IIT Ropar, 106106183): propositional logic, predicates and quantifiers