Search Knowledge

© 2026 LIBREUNI PROJECT

Predicate Logic

Predicate Logic (First-Order Logic)

Propositional logic is great for simple true/false statements, but it can’t handle variables. We cannot say “x is even” in propositional logic because xx is unknown. Predicate Logic solves this by introducing variables and Quantifiers.

1. Predicates as Functions

A Predicate is a statement whose truth depends on one or more variables. In programming, a predicate is simply a function that returns a Boolean.

python
1# A Predicate function in Python
2def is_even(n):
3 return n % 2 == 0
4 
5# Test the predicate with different values
6numbers = [1, 2, 3, 4, 5]
7for n in numbers:
8 print(f"Is {n} even? {is_even(n)}")
9 

The expression ”xx is even” is written as P(x)P(x). It is not true or false until you provide an xx.

2. Quantifiers: For All and There Exists

Quantifiers describe the scope of a predicate over a Domain (a set of objects).

  1. Universal (x\forall x): Reads “For all x…“. The statement is true only if the predicate holds for every element in the domain.
  2. Existential (x\exists x): Reads “There exists an x…“. The statement is true if there is at least one element that satisfies the predicate.

In Python, we use the all() and any() functions to represent these quantifiers.

python
1# Domain of integers
2domain = [2, 4, 6, 8, 10]
3 
4# Universal Quantifier: Are ALL numbers even?
5forall_even = all(n % 2 == 0 for n in domain)
6 
7# Existential Quantifier: Does there exist a number > 5?
8exists_greater_5 = any(n > 5 for n in domain)
9 
10print(f"Domain: {domain}")
11print(f"For all n, n is even: {forall_even}")
12print(f"Exists n such that n > 5: {exists_greater_5}")
13 

3. Negating Quantifiers

Negating a quantifier flips its type. This is a common point of confusion in both math and natural language.

  • ¬(x,P(x))x,¬P(x)\neg (\forall x, P(x)) \equiv \exists x, \neg P(x)
    • ”It’s not true that everyone is rich”     \iff “There exists someone who is not rich."
  • ¬(x,P(x))x,¬P(x)\neg (\exists x, P(x)) \equiv \forall x, \neg P(x)
    • "There is no one who is immortal”     \iff “Everyone is mortal.”

4. The Order of Quantifiers

When you nest quantifiers, the order matters immensely for the meaning of the statement.

  • x,y\forall x, \exists y such that Father(y,x)Father(y, x): “Everyone has a father.” (True for humans)
  • y,x\exists y, \forall x such that Father(y,x)Father(y, x): “There is one man who is the father of everyone.” (False for humans)

Exercises

If the domain is all positive integers, which statement is true?

Negate the statement: 'Every bird can fly'.

Previous Module Numerical Root Finding