CSCI 2824: Lecture 4

In this lecture, we will cover the following topic:

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

Predicates

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.

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(x)

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 : isGoingToSchool(Tom)

• Proposition : isGoingToSchool(Susan)

• Proposition : isGoingToSchool(My Fish)

A one argument predicate has a single variable .

Whenever 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(,) that denotes that whatever object is substituted for is the son of the object that is substituted for .

Therefore, we can write:

Son(John, Catherine)

Example-1:

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

Q: What is ?

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.

Example-2:

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

• : 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.

• : Number x is prime.

• . Here the predicate is defined as a formula involving the LessThan predicate. It is considered true for a natural number , if number is less than or greater than .

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

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

Example-3:

Let 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: .

And the same applies to predicates over numbers:

• .

• .

Example-4:

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: .

Example-5:

Let be a predicate over numbers that stands for is prime.

Which of the following formulae are true over numbers?

• .

• is false.

• is true.

• is false.

Redo the example with the following interpretation of : .

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 = re.search('ab+a',x)
# A Predicate returns a Boolean
if (m == None):
return False
else:
return True

#Take a list of words

#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.

Predicates and Sets

We can use predicates to select elements from a set. Let us fix a set . We will present this in detail when we discuss sets.

• Select elements from that are even:

• Define to be the predicate: is even. We can instead write out as .

• We then write the set as: .

• Alternative notation: .

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

• .

• Select the empty set.

• .

• Select the entire set :

• .

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 is written as . However, this can be simplified further by applying DeMorgan's Laws.

Eg., Consider the predicate . It is cumbersome to write everywhere. Instead, we write .

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

Starting from predicates, we can extend negations to formulae.

What is the negation of:

Note how the changes to a while negation.

Rules for negation:

 Formula Type Negation

Example

Write down the negation of the following formulae:

Q1: .

A: .

Q2: .

A: .

Quantifiers

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 , is divisible by OR is divisible by ?

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

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

We use the universal or forall quantifier to say:

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

• The notation stands for belongs to the set .

• The set is commonly used to denote the set of natural numbers. Other commonly used notations include for reals, for integers and 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 that is even and prime.

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

Quantified Formula

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

As an example consider the formula:

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

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

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

• ?

• ?

Formulas can have multiple quantifiers in front of them:

Q Paraphrase this formula in plain english.

A For every number there exists a number such that and 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.

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

A: