Predicate Logic, Quantifiers, and Foundations of Logic Programming

Mathematical Sets and Domain Foundations

Predicate logic relies heavily on specifying the collections of objects over which variables range. Standard notations for fundamental numerical sets include:

  • Natural numbers: N\mathbb{N}
  • Integer numbers: Z\mathbb{Z}
  • Rational numbers: Q\mathbb{Q}
  • Real numbers: R\mathbb{R}
  • Complex numbers: C\mathbb{C}

Fundamentals of Predicate Logic

Statements such as x>3x > 3, x=y+3x = y + 3, and x+y=zx + y = z contain symbols such as >>, ++, and == that denote relations between variables and values:

  • In x>3x > 3, the relation >> holds between xx and 33.
  • In x=y+3x = y + 3, the relations == and ++ hold between xx, yy, and 33.
  • In x+y=zx + y = z, the relations hold between xx, yy, and zz.

These relations may either hold or fail to hold depending on the specific values assigned to the variables xx, yy, and zz.

A predicate is a property that is affirmed or denied about the subject of a statement. In formal logic, the subject is referred to as the variable or argument:

  • In the statement "xx is greater than 3", the component xx is the subject.
  • The phrase "is greater than 3" is the predicate.

A statement containing one or more variables is a predicate. A predicate is not a proposition on its own because it lacks a definitive truth value. However, if values are assigned to all variables within a predicate, the resulting statement becomes a proposition:

  • The statement "x<5x < 5" is a predicate where xx denotes any real number (x∈Rx \in \mathbb{R}).
  • Substituting the value 33 for xx yields the proposition "3<53 < 5", which has a truth value of True (TT).
  • Substituting the value 66 for xx yields the proposition "6<56 < 5", which has a truth value of False (FF).

Propositional Functions and Arity

A propositional function is a sentence expressed in a manner that would assume a truth value of either true or false, except that it contains one or more variables that are not defined or specified, leaving the statement undetermined.

To symbolize a statement like "xx is greater than 3" in predicate logic:

  1. Introduce a functional symbol for the predicate, such as PP.
  2. Place the subject as an argument to the functional symbol, written as P(x)P(x).

The statement P(x)P(x) represents the value of the propositional function PP at xx. In this notation:

  • P(x)P(x) is a statement.
  • PP is the predicate or propositional function.
  • xx is the argument.

Predicates are classified by their arity, which is the number of arguments they accept:

  • Unary predicate (arity 1): Accepts one argument, such as Father(x)\text{Father}(x).
  • Binary predicate (arity 2): Accepts two arguments, such as Brother(x,y)\text{Brother}(x, y).
  • Ternary predicate (arity 3): Accepts three arguments, such as Sum(x,y,z)\text{Sum}(x, y, z).
  • nn-ary predicate (arity nn): Accepts nn arguments, denoted P(x1,x2,…,xn)P(x_1, x_2, \dots, x_n) or P(x,y,z,t)P(x, y, z, t).

A statement of the form P(x1,x2,…,xn)P(x_1, x_2, \dots, x_n) is the value of the propositional symbol PP evaluated at the nn-tuple (x1,x2,…,xn)(x_1, x_2, \dots, x_n). Conceptually, a propositional function:

  • Takes one or more arguments.
  • Expresses a predicate involving those arguments.
  • Evaluates to true or false once values are assigned to all its arguments, thereby becoming a proposition.

Consider the ternary propositional function Q(x,y,z)Q(x, y, z) denoting x2+y2=z2x^2 + y^2 = z^2:

  • For (x,y,z)=(3,4,5)(x, y, z) = (3, 4, 5), Q(3,4,5)Q(3, 4, 5) asserts 32+42=523^2 + 4^2 = 5^2 (9+16=259 + 16 = 25), which is True.
  • For (x,y,z)=(2,2,3)(x, y, z) = (2, 2, 3), Q(2,2,3)Q(2, 2, 3) asserts 22+22=322^2 + 2^2 = 3^2 (4+4=8≠94 + 4 = 8 \neq 9), which is False.
  • Similarly, Q(2,3,3)Q(2, 3, 3) asserts 22+32=322^2 + 3^2 = 3^2 (4+9=13≠94 + 9 = 13 \neq 9), which is False.
  • There are infinitely many triples (x,y,z)(x, y, z) that make Q(x,y,z)Q(x, y, z) true, corresponding to the infinite number of right triangles.

Universe of Discourse

When evaluating a statement such as x>3x > 3, assigning an entity like "blue" to xx is meaningless. The universe of discourse (also known as the domain of discourse, or simply the domain) is the set of all objects that can sensibly be assigned to a variable in a propositional function.

For example, given the propositional function:

\text{EnrolledCSE235}(x) = \text{`x is enrolled in CSE235'}

The universe of discourse for xx comprises all students (specifically university students eligible for enrollment).

In multivariate functions, each argument in an nn-tuple may draw from a distinct universe of discourse. Consider the 4-ary predicate:

P(r, g, b, c) = \text{`The RGB values of the color c is $(r, g, b)'}

  • The universes of discourse for rr, gg, and bb are the set of valid color channel intensity integers, {0,1,2,…,255}\{0, 1, 2, \dots, 255\}.
  • The universe of discourse for cc is the set of color names.
  • Evaluating P(255,0,0,red)P(255, 0, 0, \text{red}) yields True, as pure red is represented by RGB coordinates (255,0,0)(255, 0, 0).
  • Evaluating P(0,0,255,green)P(0, 0, 255, \text{green}) yields False, as (0,0,255)(0, 0, 255) corresponds to blue, not green.

Quantifiers in Predicate Calculus

A predicate statement containing variables can be transformed into a proposition with a definitive truth value through two primary methods:

  1. Assigning concrete values from the universe of discourse to every variable.
  2. Quantification.

Quantification expresses the extent to which a predicate is true over a range of elements. The formal branch of logic dealing with predicates and quantifiers is termed the predicate calculus (or First-Order Logic).

While natural languages express quantification using words like all, some, many, none, and few, predicate calculus centers on two fundamental types:

  • Universal Quantification: Asserts that a predicate is true for every element in the domain.
  • Existential Quantification: Asserts that a predicate is true for at least one element in the domain.

The Universal Quantifier

The universal quantification of a predicate P(x)P(x) is the proposition:

"P(x)P(x) is true for all values of xx in the universe of discourse."

This is denoted by the universal quantifier symbol ∀\forall:

∀xP(x)\forall x P(x)

This expression is read as "for all xx, P(x)P(x)" or "for every xx, P(x)P(x)".

If the universe of discourse is finite and consists of elements {n1,n2,…,nk}\{n_1, n_2, \dots, n_k\}, the universal quantification is equivalent to the conjunction of the propositions evaluated at every element:

∀xP(x)  ⟺  P(n1)∧P(n2)∧⋯∧P(nk)\forall x P(x) \iff P(n_1) \land P(n_2) \land \dots \land P(n_k)

A counterexample is any element xx in the universe of discourse for which P(x)P(x) is false. A single counterexample is sufficient to disprove a universally quantified statement.

Application Examples of Universal Quantification

Let P(x)P(x) be "xx must take a discrete mathematics course" and Q(x)Q(x) be "xx is a CS student", where the universe of discourse consists of all computer science students:

  • "Every CS student must take a discrete mathematics course":
    ∀x(Q(x)→P(x))\forall x (Q(x) \to P(x))
  • "Everybody must take a discrete mathematics course or be a CS student":
    ∀x(P(x)∨Q(x))\forall x (P(x) \lor Q(x))
  • "Everybody must take a discrete mathematics course and be a CS student":
    ∀x(P(x)∧Q(x))\forall x (P(x) \land Q(x))

Expressing the statement "for every xx and every yy, x+y>10x + y > 10" over the universe of discourse of integers Z\mathbb{Z}:

∀x∀yP(x,y)or in shorthand∀x,yP(x,y)\forall x \forall y P(x, y) \quad \text{or in shorthand} \quad \forall x, y P(x, y)

where P(x,y)P(x, y) denotes x+y>10x + y > 10.

Evaluating Universal Quantifications
  • Let Q(x)Q(x) be "x<2x < 2" with the domain of all real numbers R\mathbb{R}. The statement ∀xQ(x)\forall x Q(x) is false because x=3x = 3 provides a counterexample where Q(3)Q(3) ("3<23 < 2") is false.
  • Let P(x)P(x) be "x2>0x^2 > 0" over the universe of discourse of all integers Z\mathbb{Z}. The statement ∀xP(x)\forall x P(x) is false because x=0x = 0 is a counterexample: 02=00^2 = 0, which is not strictly greater than 00.
  • Let P(x)P(x) be "x2<10x^2 < 10" over the domain of positive integers not exceeding 4 (i.e., {1,2,3,4}\{1, 2, 3, 4\}). The universal quantification ∀xP(x)\forall x P(x) corresponds to the conjunction:   P(1)∧P(2)∧P(3)∧P(4)P(1) \land P(2) \land P(3) \land P(4)   Evaluating each:
    • P(1)≡12<10≡1<10P(1) \equiv 1^2 < 10 \equiv 1 < 10 (True)
    • P(2)≡22<10≡4<10P(2) \equiv 2^2 < 10 \equiv 4 < 10 (True)
    • P(3)≡32<10≡9<10P(3) \equiv 3^2 < 10 \equiv 9 < 10 (True)
    • P(4)≡42<10≡16<10P(4) \equiv 4^2 < 10 \equiv 16 < 10 (False)   Because P(4)P(4) is false, ∀xP(x)\forall x P(x) is False.

The Existential Quantifier

The existential quantification of a predicate P(x)P(x) is the proposition:

"There exists a value xx in the universe of discourse such that P(x)P(x) is true."

This is denoted by the existential quantifier symbol ∃\exists:

∃xP(x)\exists x P(x)

This expression is read as "there exists xx such that P(x)P(x)" or "there is at least one xx such that P(x)P(x)".

If the universe of discourse is finite and consists of elements {n1,n2,…,nk}\{n_1, n_2, \dots, n_k\}, the existential quantification is equivalent to the disjunction of the propositions evaluated at every element:

∃xP(x)  ⟺  P(n1)∨P(n2)∨⋯∨P(nk)\exists x P(x) \iff P(n_1) \lor P(n_2) \lor \dots \lor P(n_k)

The statement ∃xP(x)\exists x P(x) is false if and only if there is no element in the domain for which P(x)P(x) is true—that is, P(x)P(x) is false for every element in the domain.

Application Examples of Existential Quantification
  • Let P(x,y)P(x, y) denote "x+y=5x + y = 5". The expression ∃x∃yP(x,y)\exists x \exists y P(x, y) asserts that there exists some pair xx and yy whose sum equals 5. This is true over the integers Z\mathbb{Z}, rationals Q\mathbb{Q}, or reals R\mathbb{R}.
  • Expressing "there exists a real solution to ax2+bx+c=0a x^2 + b x + c = 0" where a,b,ca, b, c are fixed constants:   The roots of the equation are given by the quadratic formula:   x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}   Let P(x)P(x) be the predicate defining the solution. Over the domain of real numbers R\mathbb{R}, ∃xP(x)\exists x P(x) is false whenever the discriminant is negative (b2<4acb^2 < 4ac). To ensure ∃xP(x)\exists x P(x) is unconditionally true for any quadratic with non-zero aa, the universe of discourse must be extended to the complex numbers C\mathbb{C}.
  • Expressing "There exists an xx such that x<4x < 4": Setting P(x)P(x) as "x<4x < 4", this is transcribed as:   ∃xP(x)\exists x P(x)
  • Let P(x)P(x) denote "x>3x > 3" over the domain of real numbers R\mathbb{R}. The quantification ∃xP(x)\exists x P(x) is True because there exists at least one value (for example, x=4x = 4) for which the condition holds.
  • Let Q(x)Q(x) denote "x=x+1x = x + 1" over the domain of real numbers R\mathbb{R}. The quantification ∃xQ(x)\exists x Q(x) is False because no real number satisfies the equation, making Q(x)Q(x) false for every element in the domain.

Truth Values of Quantified Statements

StatementTrue When…False When…
∀xP(x)\forall x P(x)P(x)P(x) is true for every xxThere is an xx for which P(x)P(x) is false
∃xP(x)\exists x P(x)There is an xx for which P(x)P(x) is trueP(x)P(x) is false for every xx

Nested and Mixed Quantifiers

Existential and universal quantifiers can be combined to quantify multi-variable predicates. For instance, ∀x∃yP(x,y)\forall x \exists y P(x, y) is a valid quantified expression.

When evaluating mixed quantifiers:

  1. Expressions must be parsed strictly from left to right.
  2. The order of different quantifiers is critical and generally non-commutative:    ∀x∃yP(x,y)≢∃y∀xP(x,y)\forall x \exists y P(x, y) \not\equiv \exists y \forall x P(x, y)

Consider the predicate Loves(x,y)\text{Loves}(x, y), signifying "xx loves yy":

  • ∀x∃yLoves(x,y)\forall x \exists y \text{Loves}(x, y): "Everybody loves somebody."
  • ∃y∀xLoves(x,y)\exists y \forall x \text{Loves}(x, y): "There is someone loved by everyone."

These statements carry entirely different meanings. The presence of an individual loved by everyone logically implies that everyone loves someone, but the converse is not true:

(∃y∀xLoves(x,y))→(∀x∃yLoves(x,y))(\exists y \forall x \text{Loves}(x, y)) \to (\forall x \exists y \text{Loves}(x, y))

However, consecutive quantifiers of the same type commute freely without altering the logical meaning:

  • ∀x∀yP(x,y)≡∀y∀xP(x,y)≡∀x,yP(x,y)\forall x \forall y P(x, y) \equiv \forall y \forall x P(x, y) \equiv \forall x, y P(x, y)
  • ∃x∃yP(x,y)≡∃y∃xP(x,y)≡∃x,yP(x,y)\exists x \exists y P(x, y) \equiv \exists y \exists x P(x, y) \equiv \exists x, y P(x, y)
Truth Values of Mixed Quantifiers
StatementTrue When…False When…
∀x∀yP(x,y)\forall x \forall y P(x, y)P(x,y)P(x, y) is true for every pair x,yx, yThere is at least one pair x,yx, y for which P(x,y)P(x, y) is false
∀x∃yP(x,y)\forall x \exists y P(x, y)For every xx, there is a yy for which P(x,y)P(x, y) is trueThere is an xx for which P(x,y)P(x, y) is false for every yy
∃x∀yP(x,y)\exists x \forall y P(x, y)There is an xx for which P(x,y)P(x, y) is true for every yyFor every xx, there is a yy for which P(x,y)P(x, y) is false
∃x∃yP(x,y)\exists x \exists y P(x, y)There is at least one pair x,yx, y for which P(x,y)P(x, y) is trueP(x,y)P(x, y) is false for every pair x,yx, y
Mathematical Examples of Nested Quantifiers
  • Infinitude of integers: Over the universe of discourse of integers Z\mathbb{Z}, stating that there is an infinite number of integers is formulated using the predicate P(x,y)P(x, y) as "x<yx < y":   ∀x∃yP(x,y)\forall x \exists y P(x, y)
  • Commutative law of addition for R\mathbb{R}: For every pair of real numbers x,yx, y, the identity x+y=y+xx + y = y + x holds. Letting P(x,y)P(x, y) denote x+yx + y:   ∀x∀y(P(x,y)  ⟺  P(y,x))or∀x∀y(x+y=y+x)\forall x \forall y (P(x, y) \iff P(y, x)) \quad \text{or} \quad \forall x \forall y (x + y = y + x)
  • Multiplicative inverse for non-zero reals (R∖{0}\mathbb{R} \setminus \{0\}): For every non-zero real number xx, there exists a real number yy such that xy=1x y = 1:   ∀x∃y(xy=1)\forall x \exists y (x y = 1)
  • Non-commutativity of subtraction over R\mathbb{R}: The proposition asserting commutativity of subtraction is:   ∀x∀y(x−y=y−x)\forall x \forall y (x - y = y - x)   This is a false mathematical statement over R\mathbb{R}.
  • Additive and multiplicative identity elements: The statement "There is a number xx such that when it is added to any number, the result is that number, and if it is multiplied by any number, the result is xx" is formalized over domains N\mathbb{N}, Z\mathbb{Z}, Q\mathbb{Q}, or R\mathbb{R}. Letting P(x,y)P(x, y) be x+y=yx + y = y and Q(x,y)Q(x, y) be xy=xx y = x:   ∃x∀y(P(x,y)∧Q(x,y))or∃x∀y((x+y=y)∧(xy=x))\exists x \forall y (P(x, y) \land Q(x, y)) \quad \text{or} \quad \exists x \forall y ((x + y = y) \land (x y = x))   (This holds true for x=0x = 0).

Variable Binding and Scope

A variable in predicate logic can be categorized depending on its association with a quantifier:

  • Bound Variable: A variable on which a quantifier is applied.
  • Free Variable: A variable occurring in a predicate expression that is not governed by any quantifier.

In the expression ∃x∀yP(x,y)\exists x \forall y P(x, y), both xx and yy are bound variables. In the expression ∀xP(x,y)\forall x P(x, y), the variable xx is bound, but the variable yy is free.

A statement is termed a well-formed formula (WFF) when all of its variables are properly quantified. A propositional function cannot represent a proposition with a truth value until every variable appearing within it is bound.

Scope of Quantifiers

The scope of a quantifier is the set of all variables bound by that specific quantifier. In the expression:

∃x,y∀zP(x,y,z,c)\exists x, y \forall z P(x, y, z, c)

  • The scope of the existential quantifier contains xx and yy.
  • The scope of the universal quantifier contains zz.
  • The bound variables are xx, yy, and zz.
  • The free variable is cc.
  • The formula is not a well-formed formula because the variable cc is free.
Non-Equivalence of Quantifier Distribution

A common misconception is that universal quantification distributes across individual variables:

∀x,yP(x,y)≢(∀xP(x,y))∧(∀yP(x,y))\forall x, y P(x, y) \not\equiv (\forall x P(x, y)) \land (\forall y P(x, y))

  • On the left-hand side, both xx and yy are bound variables, rendering it a fully bound proposition.
  • On the right-hand side, yy is free in the first conjunct (∀xP(x,y))(\forall x P(x, y)), while xx is free in the second conjunct (∀yP(x,y))(\forall y P(x, y)).
  • Because the right-hand side contains free variables, it is not a proposition and cannot be logically equivalent to the left-hand side.

Negation of Quantified Expressions

Negating a quantified expression transforms the quantifier type and shifts the negation inward to the underlying predicate. This represents the quantified extension of De Morgan's Laws.

Consider the proposition: "Every student in your class has taken a course in calculus." Letting P(x)P(x) denote "xx has taken a course in calculus" over the domain of students in the class, the statement is:

∀xP(x)\forall x P(x)

The negation of this statement is: "It is not the case that every student in your class has taken a course in calculus." This is logically equivalent to "There is a student in your class who has not taken a course in calculus", written as:

∃x¬P(x)\exists x \neg P(x)

De Morgan's Laws for Quantifiers

For any predicate P(x)P(x):

¬(∀xP(x))≡∃x¬P(x)\neg (\forall x P(x)) \equiv \exists x \neg P(x)

¬(∃xP(x))≡∀x¬P(x)\neg (\exists x P(x)) \equiv \forall x \neg P(x)

When the universe of discourse is finite ({n1,n2,…,nk}\{n_1, n_2, \dots, n_k\}), these equivalences reduce directly to standard propositional De Morgan's Laws:

¬(⋀i=1kP(ni))≡⋁i=1k¬P(ni)\neg \left(\bigwedge_{i=1}^{k} P(n_i)\right) \equiv \bigvee_{i=1}^{k} \neg P(n_i)

¬(⋁i=1kP(ni))≡⋀i=1k¬P(ni)\neg \left(\bigvee_{i=1}^{k} P(n_i)\right) \equiv \bigwedge_{i=1}^{k} \neg P(n_i)

Truth Values of Negated Quantifiers
StatementTrue When…False When…
¬∃xP(x)≡∀x¬P(x)\neg \exists x P(x) \equiv \forall x \neg P(x)P(x)P(x) is false for every xxThere is an xx for which P(x)P(x) is true
¬∀xP(x)≡∃x¬P(x)\neg \forall x P(x) \equiv \exists x \neg P(x)There is an xx for which P(x)P(x) is falseP(x)P(x) is true for every xx
Negation Translation Examples
  • Negating "There is an honest politician":
      Let H(x)H(x) denote "xx is honest" over the domain of all politicians.
      The statement is ∃xH(x)\exists x H(x).
      Its negation is:   ¬∃xH(x)≡∀x¬H(x)\neg \exists x H(x) \equiv \forall x \neg H(x)   In English: "Every politician is dishonest."
  • Negating "All Americans eat cheeseburgers":
      Let C(x)C(x) denote "xx eats cheeseburgers" over the domain of all Americans.
      The statement is ∀xC(x)\forall x C(x).
      Its negation is:   ¬∀xC(x)≡∃x¬C(x)\neg \forall x C(x) \equiv \exists x \neg C(x)   In English: "Some American does not eat cheeseburgers" or "There is an American who does not eat cheeseburgers."
Pushing Negations Inward

To negate a nested quantified formula, push the negation operator inward step by step, toggling quantifiers and applying De Morgan's laws to logical connectives:

¬∀x(∃y∀zP(x,y,z)∧∃z∀yP(x,y,z))\neg \forall x (\exists y \forall z P(x, y, z) \land \exists z \forall y P(x, y, z))

  1. Move the negation past the universal quantifier ∀x\forall x:    ∃x¬(∃y∀zP(x,y,z)∧∃z∀yP(x,y,z))\exists x \neg (\exists y \forall z P(x, y, z) \land \exists z \forall y P(x, y, z))
  2. Apply De Morgan's Law for conjunction (¬(A∧B)≡¬A∨¬B\neg (A \land B) \equiv \neg A \lor \neg B):    ∃x(¬(∃y∀zP(x,y,z))∨¬(∃z∀yP(x,y,z)))\exists x (\neg (\exists y \forall z P(x, y, z)) \lor \neg (\exists z \forall y P(x, y, z)))
  3. Distribute negation through the inner quantifiers:    ¬(∃y∀zP(x,y,z))≡∀y∃z¬P(x,y,z)\neg (\exists y \forall z P(x, y, z)) \equiv \forall y \exists z \neg P(x, y, z)¬(∃z∀yP(x,y,z))≡∀z∃y¬P(x,y,z)\neg (\exists z \forall y P(x, y, z)) \equiv \forall z \exists y \neg P(x, y, z)
  4. Combine the result:    ∃x(∀y∃z¬P(x,y,z)∨∀z∃y¬P(x,y,z))\exists x (\forall y \exists z \neg P(x, y, z) \lor \forall z \exists y \neg P(x, y, z))

Translating English to Predicate Logic

Translating natural language into logical expressions is essential in mathematics, artificial intelligence, software engineering, and logic programming. Natural language statements should be transcribed using a structured sequence:

  1. Rephrase the statement to reveal the underlying quantifiers:
    "Every student in this class has studied calculus" becomes "For every student in this class, that student has studied calculus."
  2. Introduce explicit variables:
    "For every student xx in this class, xx has studied calculus."
  3. Define propositional functions:
       Let C(x)C(x) denote "xx has studied calculus."
  4. Define the domain of discourse:
       Domain of xx = students in this class.
  5. Synthesize the symbolic formula:
    ∀xC(x)\forall x C(x)
Pairing Quantifiers with Connectives

Translating natural language requires matching quantifiers with their appropriate connectives:

  • Universal quantifiers (∀\forall) typically pair with implication (→\to):
    • ∀x(Lion(x)→Fierce(x))\forall x (\text{Lion}(x) \to \text{Fierce}(x)): "Every lion is fierce." (True even if the universe contains non-lions, provided all lions are fierce).
    • If conjunction is erroneously used, ∀x(Lion(x)∧Fierce(x))\forall x (\text{Lion}(x) \land \text{Fierce}(x)), the statement asserts: "Everyone is a lion and everyone is fierce."
  • Existential quantifiers (∃\exists) typically pair with conjunction (∧\land):
    • ∃x(Lion(x)∧Vegan(x))\exists x (\text{Lion}(x) \land \text{Vegan}(x)): "There is at least one vegan lion."
    • If implication is erroneously used, ∃x(Lion(x)→Vegan(x))\exists x (\text{Lion}(x) \to \text{Vegan}(x)), the expression evaluates to True simply by finding any entity that is not a lion (since False →\to Anything is True), failing to represent the original statement.

Logic Programming with Prolog

Prolog (Programming in Logic) is a declarative programming language grounded in a restricted form of Predicate Logic (predicate calculus / first-order logic). Developed by logicians in the Artificial Intelligence community, it is designed for automated theorem proving and symbolic reasoning.

Structure of a Prolog Program
  • Facts: Concrete assertions represented as propositional functions:
    • student(mia)
    • enrolled(mia, cse235)
    • instructor(patel, cse235)
  • Rules: Universal implications with conjunctions defining new relations:
    • teaches(X, Y) :- instructor(X, Z), enrolled(Y, Z)
    • In Prolog syntax, the :- symbol represents reverse implication (←\leftarrow), a comma , represents logical conjunction (∧\land), and a semicolon ; represents logical disjunction (∨\lor).
    • The rule above defines that professor X teaches student Y if there exists a course Z such that X is the instructor of Z and Y is enrolled in Z.
  • Queries: Questions evaluated against the defined database of facts and rules. Prolog answers queries by binding variables and applying inference rules to prove theorems:
    • ?enrolled(mia, cse235)
    • ?enrolled(X, cse476)
    • ?teaches(X, mia)
Prolog Execution Example

Consider the following database of facts:

instructor(chan, math273).
instructor(patel, ee222).
instructor(grossman, cs301).
enrolled(kevin, math273).
enrolled(juana, ee222).
enrolled(juana, cs301).
enrolled(kiko, math273).
enrolled(kiko, cs301).

With the rule:

teaches(P, S) :- instructor(P, C), enrolled(S, C).

Evaluating sample queries:

  1. ?enrolled(kevin, math273):
       Prolog evaluates this against the fact base and returns Yes because enrolled(kevin, math273) is explicitly defined.
  2. ?enrolled(X, math273):
       Prolog determines all bindings for variable X that satisfy the goal. It outputs:
    • kevin
    • kiko
  3. ?teaches(X, juana):
       To find all professors X who instruct classes taken by Juana, Prolog evaluates instructor(X, C), enrolled(juana, C). Juana is enrolled in ee222 and cs301. The instructors for these classes are patel and grossman. The query outputs:
    • patel
    • grossman

Advanced Formalization Exercises

Disjunction and Negation Equivalences

Expressing "For all xx, x<5x < 5 or x≥5x \ge 5":
Let P(x)P(x) be "x<5x < 5" and Q(x)Q(x) be "x≥5x \ge 5". The proposition is written as:

∀x[P(x)∨Q(x)]\forall x [P(x) \lor Q(x)]

Because Q(x)Q(x) is equivalent to ¬P(x)\neg P(x), the statement can also be expressed as:

∀x[P(x)∨¬P(x)]\forall x [P(x) \lor \neg P(x)]

Quantifier Order Distinctions

Let P(x,y)P(x, y) denote the predicate "y=x+1y = x + 1". Comparing two distinct statements:

  1. "For every number xx there is a number yy such that y=x+1y = x + 1":
    ∀x∃yP(x,y)\forall x \exists y P(x, y)
  2. "There is a number yy such that, for every number xx, y=x+1y = x + 1":
    ∃y∀xP(x,y)\exists y \forall x P(x, y)

Over the real numbers R\mathbb{R}, statement (1) is true (for any xx, choosing y=x+1y = x + 1 satisfies the condition), while statement (2) is false (no single yy can simultaneously equal x+1x + 1 for all xx).

Theatre Seat Booking Formalization

In a theatre seat reservation specification, let B(p,s)B(p, s) denote the predicate "person pp has booked seat ss":

  • (a) Seat ss has been booked:
    ∃pB(p,s)\exists p B(p, s)
  • (b) Person pp has booked a (at least one) seat:
    ∃sB(p,s)\exists s B(p, s)
  • (c) All the seats are booked:
    ∀s∃pB(p,s)\forall s \exists p B(p, s)
  • (d) No seat is booked by more than one person:
      If no seat is booked by multiple individuals, then B(p,s)B(p, s) and B(q,s)B(q, s) cannot both be true unless pp and qq denote the identical person:
    ∀s∀p∀q{[B(p,s)∧B(q,s)]→(p=q)}\forall s \forall p \forall q \{[B(p, s) \land B(q, s)] \to (p = q)\}
Arithmetic Property Characterization

Let P(x,y)P(x, y) denote "xx is a factor of yy", where x∈{1,2,3,… }x \in \{1, 2, 3, \dots\} and y∈{2,3,4,… }y \in \{2, 3, 4, \dots\}. Consider the quantified predicate:

Q(x,y)≡∀x,y[P(x,y)→(x=y)∨(x=1)]Q(x, y) \equiv \forall x, y [P(x, y) \to (x = y) \lor (x = 1)]

When evaluated for a specific integer yy, the property ∀x[P(x,y)→(x=y)∨(x=1)]\forall x [P(x, y) \to (x = y) \lor (x = 1)] states that the only positive factors of yy are 11 and yy itself. This formula formalizes the mathematical definition of a prime number.