Skip to main content

Predicates and Quantifiers

Propositional logic cannot express statements such as "every prime greater than 22 is odd" without flattening the whole sentence into one atomic symbol. Predicate logic opens the sentence and exposes its variables. A predicate such as P(x)P(x) becomes a proposition only after xx is assigned a value or after a quantifier says how broadly PP is being asserted.

This is the language used for definitions, theorems, loop invariants, database queries, and specifications. Universal quantifiers support claims about all objects in a domain. Existential quantifiers support claims that at least one object exists. Much of proof writing is the disciplined process of introducing, transforming, and eliminating these quantifiers.

Definitions

A predicate or propositional function is a statement containing variables. For example, P(x)P(x): "x20x^2\ge 0" is not a proposition until the domain of xx is known and xx is given a value or quantified. Over the real numbers, P(3)P(3) is true. Over the same domain, Q(x)Q(x): "x2=2x^2=2" is true for some values but not all.

The domain of discourse is the set of objects a variable is allowed to represent. Changing the domain can change the truth value. The statement x(x2x)\forall x(x^2\ge x) is false over the real numbers, false over the integers, but true over the nonnegative integers only for x=0x=0 or x1x\ge1; if the domain is {0,1,2,}\{0,1,2,\dots\}, it is true.

The two basic quantifiers are:

  • Universal quantifier: xP(x)\forall x\,P(x) means "P(x)P(x) is true for every xx in the domain."
  • Existential quantifier: xP(x)\exists x\,P(x) means "there is at least one xx in the domain for which P(x)P(x) is true."

A unique existence statement, written !xP(x)\exists!x\,P(x), means there is exactly one object satisfying PP. It abbreviates

x(P(x)y(P(y)y=x)).\exists x\bigl(P(x)\land \forall y(P(y)\to y=x)\bigr).

Variables inside a quantifier's scope are bound. Variables not bound by a quantifier are free. A formula with free variables is not a complete proposition until those variables are assigned or quantified.

Key results

Negating quantified statements reverses the quantifier and negates the predicate:

¬xP(x)x¬P(x),¬xP(x)x¬P(x).\begin{aligned} \neg\forall x\,P(x) &\equiv \exists x\,\neg P(x),\\ \neg\exists x\,P(x) &\equiv \forall x\,\neg P(x). \end{aligned}

These are De Morgan laws for quantifiers. The first says that to refute "everyone has property PP," it is enough to find one counterexample. The second says that to refute "someone has property PP," one must show that no object has it.

Quantifier order matters. In general,

xyR(x,y)\forall x\exists y\,R(x,y)

is not equivalent to

yxR(x,y).\exists y\forall x\,R(x,y).

The first allows yy to depend on xx. The second requires one single yy that works for every xx. For example, over the integers, xy(y>x)\forall x\exists y(y\gt x) is true, because each integer has a larger integer. But yx(y>x)\exists y\forall x(y\gt x) is false, because no fixed integer is larger than every integer.

Universal statements are usually proved by choosing an arbitrary element of the domain and proving the predicate for it. Existential statements are usually proved by constructing a witness. To disprove a universal statement, produce a counterexample. To disprove an existential statement, prove a universal negation.

Nested quantifiers also interact with implication. The statement

x(P(x)Q(x))\forall x(P(x)\to Q(x))

does not assert that any object satisfies P(x)P(x). It asserts that every object that satisfies PP also satisfies QQ. This is why mathematical definitions often have the form "for all xx, if xx has the hypotheses, then xx has the conclusion."

Visual

Claim formMeaningHow to proveHow to disprove
xP(x)\forall x\,P(x)every object workstake arbitrary xx and prove P(x)P(x)find one xx with ¬P(x)\neg P(x)
xP(x)\exists x\,P(x)at least one object worksgive a witness aa and prove P(a)P(a)prove x¬P(x)\forall x\,\neg P(x)
xyR(x,y)\forall x\exists y\,R(x,y)each xx has a possibly different yygive a rule for yy in terms of xxfind one xx with no possible yy
yxR(x,y)\exists y\forall x\,R(x,y)one yy works for all xxgive a single universal witnessshow every candidate yy fails for some xx

Worked example 1: Negate a nested statement

Problem. Let the domain be the integers. Negate the statement

xy(y>xy is even).\forall x\exists y\,(y>x \land y \text{ is even}).

Then decide whether the original statement is true.

Method.

  1. Start with the negation:
¬xy(y>xy is even).\neg\forall x\exists y\,(y>x \land y \text{ is even}).
  1. Move the negation through the universal quantifier:
x¬y(y>xy is even).\exists x\,\neg\exists y\,(y>x \land y \text{ is even}).
  1. Move the negation through the existential quantifier:
xy¬(y>xy is even).\exists x\forall y\,\neg(y>x \land y \text{ is even}).
  1. Apply De Morgan's law inside:
xy(yxy is not even).\exists x\forall y\,(y\le x \lor y \text{ is not even}).

Checked answer. The negation says: "There is an integer xx such that every integer yy is either not greater than xx or is not even." The original statement is true. Given any integer xx, choose y=2x+2y=2x+2 if x0x\ge0 and choose y=0y=0 if x<0x\lt 0. In both cases yy is even and y>xy\gt x. The chosen yy is allowed to depend on xx, which is exactly what xy\forall x\exists y permits.

Worked example 2: Compare quantifier orders

Problem. Over the real numbers, compare the truth values of:

xy(x+y=0)\forall x\exists y\,(x+y=0)

and

yx(x+y=0).\exists y\forall x\,(x+y=0).

Method.

  1. For xy(x+y=0)\forall x\exists y(x+y=0), choose an arbitrary real number xx.
  2. We need a real number yy satisfying x+y=0x+y=0.
  3. The equation gives y=xy=-x, which is a real number.
  4. Therefore each xx has a witness, so the first statement is true.
  5. For yx(x+y=0)\exists y\forall x(x+y=0), suppose a single real number yy worked for every xx.
  6. Taking x=0x=0 gives y=0y=0.
  7. Taking x=1x=1 gives 1+y=01+y=0, so y=1y=-1.
  8. No single yy can be both 00 and 1-1.

Checked answer. The first statement is true and the second is false. The only difference is quantifier order. In the first, yy may depend on xx; in the second, one fixed yy must work for all xx.

Code

def forall(domain, predicate):
return all(predicate(x) for x in domain)

def exists(domain, predicate):
return any(predicate(x) for x in domain)

domain = range(-5, 6)

statement1 = forall(
domain,
lambda x: exists(domain, lambda y: x + y == 0),
)

statement2 = exists(
domain,
lambda y: forall(domain, lambda x: x + y == 0),
)

print(statement1)
print(statement2)

On the finite sample domain {5,,5}\{-5,\dots,5\}, the output is True and False. Finite testing is not a proof over all real numbers, but it reflects the same quantifier-order difference that the proof establishes.

Common pitfalls

  • Forgetting to state the domain. A quantified formula can change truth value when the domain changes.
  • Reversing quantifier order. xy\forall x\exists y usually means "a custom response for each input"; yx\exists y\forall x means "one response fits all inputs."
  • Negating only the predicate and forgetting to flip the quantifier.
  • Treating x\exists x as "many." It means at least one unless uniqueness is explicitly stated.
  • Proving a universal statement by testing several examples. Examples can suggest a proof, but they do not prove "for all."
  • Using a special element when proving a universal statement. The chosen element must be arbitrary.

When translating English, identify the domain before choosing quantifiers. "Every student has taken a math course" might mean every student in a class, every student at a university, or every student in some database table. The predicate and the truth value both depend on this domain. A good translation states the domain in words or in the formula.

Restricted quantifiers can be written with implications or conjunctions. "Every prime greater than 22 is odd" becomes n((P(n)n>2)O(n))\forall n((P(n)\land n\gt 2)\to O(n)). "There exists a prime greater than 100100" becomes n(P(n)n>100)\exists n(P(n)\land n\gt 100). Universal restrictions usually use implication; existential restrictions usually use conjunction. Reversing these patterns changes the meaning.

For nested quantifiers, read from left to right while tracking dependency. In xyR(x,y)\forall x\exists y\,R(x,y), the witness yy may be chosen after seeing xx. In yxR(x,y)\exists y\forall x\,R(x,y), the witness yy is chosen before any xx and must work for all of them. This dependency is often the whole point of the statement.

A useful translation check is to negate the formula and see whether the result matches the ordinary-language failure case. The negation of "every server has a backup" should be "some server has no backup." If the symbolic negation says something different, the original quantifier or connective was probably mistranslated.

When a statement contains several variables, specify whether they share a domain. In xy(x<y)\forall x\exists y(x\lt y) over integers, both variables are integers. In applied settings, xx might range over users while yy ranges over permissions or files. Mixed-domain predicates should make each variable's type explicit.

Connections