Lesson 2 of 15
Predicate Logic & Quantifiers
From Propositions to Predicates
Predicate logic (first-order logic) extends propositional logic with predicates — statements about objects — and quantifiers that range over domains.
A predicate is a statement about that becomes a proposition when is given a value. The two quantifiers are:
Negation of quantifiers (De Morgan for quantifiers):
def for_all(domain, predicate):
return all(predicate(x) for x in domain)
def exists(domain, predicate):
return any(predicate(x) for x in domain)
# Every number in {1..5} is positive
print(for_all(range(1, 6), lambda x: x > 0)) # True
# Some number in {1..5} equals 3
print(exists(range(1, 6), lambda x: x == 3)) # True
Nested Quantifiers
Order matters: differs from .
Your Task
Implement for_all(domain, predicate) and exists(domain, predicate) using Python's built-in all and any.
Pyodide loading...
Loading...
Click "Run" to execute your code.