Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 2: Predicate Logic, Quantifiers & Rules of Inference

Lesson 6 of 17 in the free Mathematical Foundation of CS notes on Siksha Sarovar, written by Rohit Jangra.

5.1 Predicates and Quantifiers

Propositional logic cannot express "every prime greater than 2 is odd" — it has no way to talk about all or some objects. A predicate P(x) is a statement containing variables that becomes a proposition once values are substituted or the variables are quantified over a domain (universe of discourse).

QuantifierNotationReadingTrue whenFalse when
Universal∀x P(x)"for all x, P(x)"P holds for every domain elementat least one counterexample exists
Existential∃x P(x)"there exists x with P(x)"at least one witness existsP fails for every element

Over a finite domain {a1, ..., an}: ∀x P(x) ≡ P(a1) ∧ ... ∧ P(an) and ∃x P(x) ≡ P(a1) ∨ ... ∨ P(an) — quantifiers are giant conjunctions/disjunctions.

The domain matters. ∀x (x^2 ≥ x) is true over Z but false over R (take x = 0.5: 0.25 < 0.5).

5.2 Translation Patterns (and the Classic Trap)

EnglishCorrect LogicWrong Version
"All lions are fierce"∀x (Lion(x) → Fierce(x))∀x (Lion(x) ∧ Fierce(x)) — claims everything is a lion
"Some students are smart"∃x (Student(x) ∧ Smart(x))∃x (Student(x) → Smart(x)) — true even with no students
"No CS student fails"∀x (CS(x) → ¬Fails(x))equivalently ¬∃x (CS(x) ∧ Fails(x))

Rule of thumb: ∀ pairs with →, ∃ pairs with ∧.

5.3 Negating Quantifiers (Generalized De Morgan)

  • ¬∀x P(x) ≡ ∃x ¬P(x) — "not everyone" means "someone fails".
  • ¬∃x P(x) ≡ ∀x ¬P(x) — "no one" means "everyone fails".

To negate nested quantifiers, push ¬ inward flipping every quantifier it passes: ¬∀x∃y P(x, y) ≡ ∃x∀y ¬P(x, y).

5.4 Worked Example 1 — Nested Quantifiers and Order

Let the domain be Z and consider P(x, y): x + y = 0.

  1. ∀x∃y (x + y = 0): for each x choose the witness y = −x ∈ Z. True.
  2. ∃y∀x (x + y = 0): demands one fixed y that works for every x simultaneously. If y worked for x = 0 then y = 0, but then 1 + 0 ≠ 0. False.
  3. Conclusion: ∀∃ and ∃∀ are not interchangeable. (Over the domain N, even statement 1 fails: for x = 1 the required y = −1 ∉ N.)
  4. Negation practice: ¬∀x∃y (x + y = 0) ≡ ∃x∀y (x + y ≠ 0) — "some x has no additive inverse", exactly the sentence that is true over N.

5.5 Rules of Inference

RuleSchema
Modus Ponensp → q, p ⊢ q
Modus Tollensp → q, ¬q ⊢ ¬p
Hypothetical Syllogismp → q, q → r ⊢ p → r
Disjunctive Syllogismp ∨ q, ¬p ⊢ q
Addition / Simplificationp ⊢ p ∨ q; p ∧ q ⊢ p
Universal Instantiation (UI)∀x P(x) ⊢ P(c) for any c in the domain
Universal Generalization (UG)P(c) for arbitrary c ⊢ ∀x P(x)
Existential Instantiation (EI)∃x P(x) ⊢ P(c) for some fresh name c
Existential Generalization (EG)P(c) ⊢ ∃x P(x)

5.6 Worked Example 2 — A Formal Deduction

Argument: "Every CS student knows logic. Everyone who knows logic can debug. Priya is a CS student. Therefore Priya can debug."

Let C(x): x is a CS student, L(x): x knows logic, D(x): x can debug.

  1. ∀x (C(x) → L(x)) — premise
  2. ∀x (L(x) → D(x)) — premise
  3. C(Priya) — premise
  4. C(Priya) → L(Priya) — UI on (1)
  5. L(Priya) — Modus Ponens (3), (4)
  6. L(Priya) → D(Priya) — UI on (2)
  7. D(Priya) — Modus Ponens (5), (6) ∎

This mechanical style is exactly how Prolog resolves queries and how proof assistants (Coq, Lean) check software correctness.

5.7 Common Mistakes & CS Applications

  • Using EI with a name already in use — the witness must be fresh.
  • Applying UG to a constant that was not arbitrary (e.g., one obtained from EI).
  • Swapping quantifier order as if it were harmless (Example 1 shows it is not).
  • Applications: SQL's EXISTS/NOT EXISTS are ∃/¬∃ over rows; ∀ is expressed via double negation (NOT EXISTS ... NOT ...); loop invariants are ∀-statements over iterations; array-bounds verification is ∀i (0 ≤ i < n → safe(a[i])).

🎯 Exam Focus

  1. Let P(x): "x > 3", with domain R. Determine the truth values of ∀x P(x), ∃x P(x), ∃x ¬P(x).
  2. Translate into predicate logic: "Every student in this class has visited Delhi or Mumbai."
  3. Negate and simplify: ∀x∃y (x < y). What does the negation assert about the domain?
  4. Determine, with justification, the truth of ∀x∃y (x·y = 1) over R and over R − {0}.
  5. Show using rules of inference: premises p → q, ¬q, p ∨ r entail r. Name every rule.
  6. Explain with an example why ∃x (P(x) ∧ Q(x)) is not implied by ∃x P(x) ∧ ∃x Q(x).