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 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.
Interactive Lab
# A Predicate function in Python
def is_even(n):
return n % 2 == 0
# Test the predicate with different values
numbers = [1, 2, 3, 4, 5]
for n in numbers:
print(f"Is {n} even? {is_even(n)}")
python
1# A Predicate function in Python
2def is_even(n):
3return n %2==0
4
5# Test the predicate with different values
6numbers =[1, 2, 3, 4, 5]
7for n in numbers:
8print(f"Is {n} even? {is_even(n)}")
9
The expression ” is even” is written as . It is not true or false until you provide an .
2. Quantifiers: For All and There Exists
Quantifiers describe the scope of a predicate over a Domain (a set of objects).
Universal (): Reads “For all x…“. The statement is true only if the predicate holds for every element in the domain.
Existential (): 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.
Interactive Lab
# Domain of integers
domain = [2, 4, 6, 8, 10]
# Universal Quantifier: Are ALL numbers even?
forall_even = all(n % 2 == 0 for n in domain)
# Existential Quantifier: Does there exist a number > 5?
exists_greater_5 = any(n > 5 for n in domain)
print(f"Domain: {domain}")
print(f"For all n, n is even: {forall_even}")
print(f"Exists n such that n > 5: {exists_greater_5}")
python
1# Domain of integers
2domain =[2, 4, 6, 8, 10]
3
4# Universal Quantifier: Are ALL numbers even?
5forall_even =all(n %2==0for n in domain)
6
7# Existential Quantifier: Does there exist a number > 5?
8exists_greater_5 =any(n >5for 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.
”It’s not true that everyone is rich” “There exists someone who is not rich."
"There is no one who is immortal” “Everyone is mortal.”
4. The Order of Quantifiers
When you nest quantifiers, the order matters immensely for the meaning of the statement.
such that : “Everyone has a father.” (True for humans)
such that : “There is one man who is the father of everyone.” (False for humans)
Exercises
Knowledge Check
If the domain is all positive integers, which statement is true?
Answer: ∃n, n is prime
The existential quantifier only requires one example to be true. Since 2 is a prime integer, the statement 'Exists n such that n is prime' is true.
If the domain is all positive integers, which statement is true?
Knowledge Check
Negate the statement: 'Every bird can fly'.
Answer: Exists a bird that cannot fly.
Negating 'For all' (Every) yields 'Exists at least one' (Some) that does not satisfy the property.