CSCI 2824: Lecture 4

In this lecture, we will cover the following topic:

  • Predicates and Quantifiers (Section 1.4 of the book).


In the previous lecture, we looked at propositions. Propositions are statements for which we can give true or false valuation. We will now generalize propositions to predicates.

Predicates should be familiar from english grammar.

 underset{mathit{Subject}}{underbrace{mbox{Tom}}};; underset{mathit{Predicate}}{underbrace{mbox{is going to school}}} ,.

Thus, the predicate can be informally expressed as: x is going to school, where x is a variable that can stand for a person.

In logic, we represent the predicate as:


isGoingToSchool is the predicate and x is a variable.

If we fill in values for x, such as Tom, Susan, My Fish and so on, we obtain propositions that can be given true or false valuations:

  • Proposition p_1: isGoingToSchool(Tom)

  • Proposition p_2: isGoingToSchool(Susan)

  • Proposition p_3: isGoingToSchool(My Fish)

A one argument predicate P(x) has a single variable x.

Whenever x is substituted by an object, then it results in a proposition that can be given true or false valuaton.

A common example of a single argument predicate over numbers is the isPrime(x) predicate stands for a proposition of the form number x is prime.

  • isPrime(10) denotes that the number 10 is prime. This is a false statement for natural numbers.

  • isPrime(5) denotes that the number 5 is prime. This is true in the theory of natural numbers.

Multiple Argument Predicates

There can be multiple argument predicates. Let us imagine a predicate with two arguments:

John is the son of Catherine.

Let us imagine a two argument predicate Son(x,y) that denotes that whatever object is substituted for x is the son of the object that is substituted for y.

Therefore, we can write:

Son(John, Catherine)


Let M(x) stand for the statement: __<x>__ is mortal .

Q: What is M(+Socrates+)?

A: The proposition Socrates is mortal.

We can use predicates with the variables substituted by objects inside propositional formulas.

Socrates is mortal AND he NOT is the son of Zeus.

 mbox{Mortal}(mbox{Socrates}) mbox{AND} (mbox{NOT} mbox{Son}(mbox{Socrates}, mbox{Zeus}))


Predicates can be arithmetic in nature. Here are some predicates over numbers:

  • x < y: Number x is less than number y. < is a two argument predicate written as an infix operator. In logic, we will sometimes write it as LessThan(x,y) to remind the reader that it is a predicate.

  • mbox{isPrime}(x): Number x is prime.

  • S(n): (n < 10) mbox{OR}  (n > 20). Here the predicate S(n) is defined as a formula involving the LessThan predicate. It is considered true for a natural number n, if number n is less than 10 or greater than 20.

Note that we can plug in various numbers and find out if the resulting statement is true of false.

  • Try all statements above with n=100. Which ones are true?

  • What about with n= -5?


Let Father(x,y) stand for the statement: __<x>__ is the father of __<y>__ .

Q: Using the predicate above, how do we express Darth is the father of Luke?

A: Father(Darth, Anakin).

And the same applies to predicates over numbers:

  •  A(x,y): x < 10  mbox{OR} y - x > 10 .

  •  B(x,y): x^2 - sin( y) = 2.4

  •  C(x,y): mbox{NOT}(y = x + 100) mbox{OR}  mbox{NOT}( y < x - 3).


We can now bring in all the propositional connectives and combine them with predicates.

Q: How do we say that

( DarthV is the father of Luke OR Anakin is the father of Luke) AND (Luke is NOT the father of Darth)

using the Father predicate from the previous example?

A:  (Father(Darth, Luke)  mbox{OR} Father(Anakin,Luke)) mbox{AND} mbox{NOT} Father(Luke,Darth).


Let P(n) be a predicate over numbers n that stands for n is prime.

Which of the following formulae are true over numbers?

  • P(100)

  • P(17)

  • (mbox{NOT} P(13))  mbox{OR} P(18).


  • P(100) is false.

  • P(17) is true.

  • (mbox{NOT} P(13))  mbox{OR}  P(18) is false.

Redo the example with the following interpretation of P: P(x):  x  mbox{is even}.

Predicates in Programs

In general, predicates appear all over the place in programs. A predicate is a function that returns a Boolean. Here is an example predicate over strings in Python.

Example Predicate

import re

def stringPredicate(x):

    # Predicate is true only if string has the pattern
    # a followed by a string of bs and then an a, somewhere in it.

    m ='ab+a',x)
    # A Predicate returns a Boolean
    if (m == None):
       return False
       return True

#Take a list of words
lst=['abba','maama mia','abbby', 'abbbbba','abbacadabra','dancing queen']

#Filter the list through a predicate
newList = filter(stringPredicate,lst)

Some common reasons to define predicates include:

  • Search for an object in a data structure that makes a predicate true.

  • Filter through a data structure choosing elements that match the list

  • Use a two place predicate to define an order between objects and then sort a collection of objects using this predicate.

Rather than write special routine for every operation, you will learn to use in-built filtering, search or sorting routines that can use any predicate.

Languages like C (STL) and Java support these operations for a wide variety of data structures based on predicates that users can define.

A function that defines a predicate must be free of side effects, or in other words, a pure function.

You will learn more about side effects in your future programming languages or software engineering classes.

Predicates and Sets

We can use predicates to select elements from a set. Let us fix a set U={1,2,3,ldots,100}. We will present this in detail when we discuss sets.

  • Select elements from U that are even:

    • Define E(x) to be the predicate: x is even. We can instead write E(x) out as x  mbox{mod} 2 = 0.

    • We then write the set as: { x in U | E(x) }.

    • Alternative notation: { x in U | x mbox{mod} 2 = 0 }.

  • Select elements from U that are greater than 4 and are divisible by 13:

    • { x in U | (x geq 4)   mbox{AND}  (x mbox{mod} 13 = 0 ) }.

  • Select the empty set.

    • { x in U | (x not= x) }.

  • Select the entire set U:

    • { x in U | x = x }.

Application Mention SQL in databases. Here is what a query looks like (syntax may be a little off).

SQL Query

select (name, age)
from db
where ( name[1]=="z" && age < 20)

Negation of Predicates and Formulas

The negation of predicate P(x) is written as mbox{NOT} P(x). However, this can be simplified further by applying DeMorgan's Laws.

Eg., Consider the predicate x < y. It is cumbersome to write mbox{NOT} (x < y) everywhere. Instead, we write x geq y.

In other words, we say that the predicate geq represents the negation of <.

Starting from predicates, we can extend negations to formulae.

What is the negation of:

 (x < y)   mbox{OR}  (x > y^2 + 3) ,?


 ( x geq y)  mbox{AND}  (x leq y^2 + 3)

Note how the  mbox{OR} changes to a  mbox{AND} while negation.

Rules for negation:

Formula Type Negation
mbox{NOT} P P
P  mbox{OR}  Q mbox{NOT} P  mbox{AND}  mbox{NOT} Q
P  mbox{AND}  Q  mbox{NOT} P  mbox{OR}  mbox{NOT} Q


Write down the negation of the following formulae:

Q1: x^2 geq y  mbox{AND}  ( x < 5   mbox{OR}  x > 8).

A:  x^2 < y  mbox{OR}  ( x geq 5  mbox{AND}  x  leq 8 ).

Q2: Father(A,B)  mbox{OR}  (Father(A,C)  mbox{AND}  Father(C,D)).

A:  mbox{NOT} Father(A,B)  mbox{AND}  (mbox{NOT} Father(A,C)  mbox{OR}  mbox{NOT} Father(C,D)).


The power of predicates arise from our ability to quantify. Let us illustrate quantification with an example.

How do we express the statement:

For all natural numbers x, x is divisible by 2 OR x-1 is divisible by 2 ?

If we forget the for all in the first place, we can write

 x mbox{mod} 2 = 0   mbox{OR}  (x-1) mbox{mod}  = 0

This is a formula involving a predicate that allows us to plug-in values for x. But the original statement was meant to hold for all possible values of x.

We use the universal or forall quantifier to say:

 (forall x in mathbb{N}) x mbox{mod} 2 = 0   mbox{OR}  (x-1) mbox{mod}  = 0  ,.

  • The forall symbol is an inverted A and stands for for all or for each.

  • The notation in mathbb{N} stands for belongs to the set mathbb{N}.

  • The set mathbb{N} is commonly used to denote the set of natural numbers. Other commonly used notations include mathbb{R} for reals, mathbb{Z} for integers and mathbb{Q} for rational numbers.

The other quantifier used is the existential or the exists quantifier. As an example, we wish to say:

There is a number n that is even and prime.

 (exists n in mathbb{N}) ( mbox{Prime}(n)  mbox{AND}  (n mbox{mod} 2 = 0))

The symbol exists stands for exists. Notice that it is an inverted E.

Quantified Formula

Whenever there is a quantifier in front of a formula, it is called a quantified formula.

As an example consider the formula:

 psi[y]:  (forall x in mathbb{R}) (x leq 5  Rightarrow  x - y leq 5 )

In this formula the variable x is called a bound or a quantified variable. The variable y is called a free variable.

We usually write formulas as psi[y] to denote that y is a free variable in the formula.

For example, which of the following are true for the formula above:

  • psi(20)?

  • psi(-1)?

Formulas can have multiple quantifiers in front of them:

 (forall x in mathbb{N}) (exists y in  mathbb{N}) (y > x  mbox{AND}  mbox{Prime}(y))

Q Paraphrase this formula in plain english.

A For every number x there exists a number y such that y > x and y is prime.

Q Express this sentence in Logic: “ Forall persons x,y,z, If (x is the parent of y) and ( y is the parent of z) then (x is the grandparent of z) ”. Use predicates “P(x,y)” for parent and “GP(x,y)”, grand parent.

 (forall x,y,z in mathsf{Persons})  ( (P(x,y)  mbox{AND}  P(y,z)) Rightarrow GP(x,z)) ,.

Q Define the formula Sib(x,y) to express that x is a sibling of y using the parent relation, where two persons are siblings if they have a parent in common.

A:  (exists z in mathsf{Persons}) (P(z,x)  mbox{AND}  P(z,y))