Predicate Logic

Emina Torlak and Kevin Zatloukal

- Key notions in predicate logic
- A brief review of Lecture 05.
- Using quantifiers
- From predicate logic to English and back.
- Negating quantified formulas
- DeMorgan’s laws for quantifiers.
- Quantifier scopes
- Bound and free variables.
- Nested quantifiers
- The quantifier order matters.

A brief review of Lecture 05.

- Syntax
- Predicate logic extends propositional logic with two key constructs:
*predicates*and*quantifiers*($\exists,\forall$). - Semantics
- We define the meaning of formulas in predicate logic with respect to a
*domain of discourse*.

- Predicate is a function that returns a truth value.
- Cat(x) $::=$ “x is a cat”
- Prime(x) $::=$ “x is prime”
- HasTaken(x, y) $::=$ “student x has taken course y”
- LessThan(x, y) $::=$ “x < y”
- Sum(x, y, z) $::=$ “x + y = z”
- GreaterThan5(x) $::=$ “x > 5”
- HasNChars(s, n) $::=$ “string s has length n”
- Predicates can have varying arity (numbers of arguments).
- But a given predicate accepts a fixed number of arguments.
- Predicates can have any names.
- The name does
*not*determine the meaning of the predicate. - So we can define Cat(x) $::=$ “x is an even number”.

To give meaning to predicates in a formula, we define a set of objects that those predicates can take as input.

This set of objects is called the *domain of discourse* for a formula.

- For each of the following, what might the domain be?
- “x is a cat”, “x barks”, “x ruined my couch”
- “mammals” or “sentient beings” or “cats and dogs” or …
- “x is prime”, “x = 0”, “x < 0”, “x is a power of two”
- “numbers” or “integers” or “integers greater than 5” or …
- “student x has taken course y” “x is a pre-req for z”
- “students and courses” or “university entities” or …

- Quantifiers let us talk about
*all*or*some*objects in the domain. - $\forall x. P(x)$
- $P(x)$ is true
**for every**$x$ in the domain. - Read as “for all $x$, $P(x)$”.
- Called the
**universal quantifier**. - $\exists x. P(x)$
**There is**an $x$ in the domain for which $P(x)$ is true.- Read as “there exists $x$, $P(x)$”.
- Called the
**existential quantifier**.

The truth value of a quantified formula depends on the domain.

$\{-3, 3\}$ | Integers | Odd Integers | |
---|---|---|---|

$\forall x. \text{Odd}(x)$ | True | False | True |

$\forall x. \text{LessThan5}(x)$ | True | False | False |

$\{-3, 3\}$ | Integers | Positive Multiples of 5 | |
---|---|---|---|

$\exists x. \text{Odd}(x)$ | True | True | True |

$\exists x. \text{LessThan5}(x)$ | True | True | False |

**You can think of $\forall x. P(x)$ as conjunction over all objects in the domain,
and $\exists x. P(x)$ as disjunction over all objects in the domain.**

- $\forall x. \text{Odd}(x)$
- over $\{-3, 3\}$ is the conjunction $\text{Odd}(-3)\wedge\text{Odd}(3)$
- over integers is the infinite conjunction $\ldots\wedge\text{Odd}(-1)\wedge\text{Odd}(0)\wedge\text{Odd}(1)\wedge\ldots$

- $\exists x. \text{Odd}(x)$
- over $\{-3, 3\}$ is the disjunction $\text{Odd}(-3)\vee\text{Odd}(3)$
- over integers is the infinite disjunction $\ldots\vee\text{Odd}(-1)\vee\text{Odd}(0)\vee\text{Odd}(1)\vee\ldots$

From predicate logic to English and back.

Just like with propositional logic, we need to define variables (this time predicates). And we must also now define a domain of discourse.

**What is the truth value of these statements?**

$\exists x. \text{Even}(x)$ | T |

$\forall x. \text{Odd}(x)$ | F |

$\forall x. \text{Even}(x)\vee\text{Odd}(x)$ | T |

$\exists x. \text{Even}(x)\wedge\text{Odd}(x)$ | F |

$\forall x. \text{Greater}(x+1,x)$ | T |

$\exists x. \text{Even}(x)\wedge\text{Prime}(x)$ | T |

- Domain of discourse
- Positive integers

- Predicate definitions
- Even(x) $:=$ “x is even”
- Odd(x) $:=$ “x is odd”
- Prime(x) $:=$ “x is prime”
- Greater(x, y) $:=$ “x > y”
- Equal(x, y) $:=$ “x = y”
- Sum(x, y, z) $:=$ “z = x + y”

- Translate the following statements to English
- $\forall x. \exists y. \text{Greater}(y, x)\wedge\text{Prime}(y)$
- For every positive integer $x$, there is a positive integer $y$, such that $y > x$ and $y$ is prime.
- $\forall x. \text{Prime}(x)\rightarrow(\text{Equal}(x,2)\vee\text{Odd}(x))$
- For every positive integer $x$, if $x$ is prime then $x=2$ or $x$ is odd.
- $\exists x. \exists y. \text{Sum}(x,2,y)\wedge\text{Prime}(x)\wedge\text{Prime}(y)$
- There exist positive integers $x$ and $y$ such that $x+2=y$ and $x$ and $y$ are prime.

- Domain of discourse
- Positive integers

- Predicate definitions
- Even(x) $:=$ “x is even”
- Odd(x) $:=$ “x is odd”
- Prime(x) $:=$ “x is prime”
- Greater(x, y) $:=$ “x > y”
- Equal(x, y) $:=$ “x = y”
- Sum(x, y, z) $:=$ “z = x + y”

- Translate the following statements to English
- $\forall x. \exists y. \text{Greater}(y, x)\wedge\text{Prime}(y)$
- For every positive integer there is a larger number that is prime.
- $\forall x. \text{Prime}(x)\rightarrow(\text{Equal}(x,2)\vee\text{Odd}(x))$
- Every prime number is 2 or odd.
- $\exists x. \exists y. \text{Sum}(x,2,y)\wedge\text{Prime}(x)\wedge\text{Prime}(y)$
- There exist prime numbers that differ by two.

- Domain of discourse
- Positive integers

- Predicate definitions
- Even(x) $:=$ “x is even”
- Odd(x) $:=$ “x is odd”
- Prime(x) $:=$ “x is prime”
- Greater(x, y) $:=$ “x > y”
- Equal(x, y) $:=$ “x = y”
- Sum(x, y, z) $:=$ “z = x + y”

- “Orange cats like lasagna.”
- $\forall x. ((\text{Orange}(x) \wedge \text{Cat}(x)) \rightarrow \text{LikesLasagna}(x))$
- “Some orange cats don’t like lasagna.”
- $\exists x. ((\text{Orange}(x) \wedge \text{Cat}(x)) \wedge \neg \text{LikesLasagna}(x))$

- Domain of discourse
- Mammals

- Predicate definitions
- Cat(x) $:=$ “x is a cat”
- Orange(x) $:=$ “x is orange”
- LikesLasagna(x) $:=$ “x likes lasagna”

- “Orange cats like lasagna.”
- $\forall x. ((\text{Orange}(x) \wedge \text{Cat}(x)) \rightarrow \text{LikesLasagna}(x))$
- When there’s no leading quantification, it means “for all”.
- When restricting to a smaller domain in a “for all”, use implication.
- “Some orange cats don’t like lasagna.”
- $\exists x. ((\text{Orange}(x) \wedge \text{Cat}(x)) \wedge \neg \text{LikesLasagna}(x))$
- “Some” means “there exists”.
- When restricting to a smaller domain in an “exists”, use conjunction.
- When putting predicates together, like orange cats, use conjunction.

- Domain of discourse
- Mammals

- Predicate definitions
- Cat(x) $:=$ “x is a cat”
- Orange(x) $:=$ “x is orange”
- LikesLasagna(x) $:=$ “x likes lasagna”

DeMorgan’s laws for quantifiers.

- Domain of discourse
- {plum, apple, …}

- Predicate definitions
- PurpleFruit(x) $:=$ “x is a purple fruit”

Let $P$ be the formula $\forall x. \text{PurpleFruit}(x)$, “all fruits are purple.”

What is the negation of $P$?

- a. “There exists a purple fruit” ($\exists x. \text{PurpleFruit}(x)$)
- b. “There exists a non-purple fruit” ($\exists x. \neg \text{PurpleFruit}(x)$)
- c. “All fruits are not purple” ($\forall x. \neg \text{PurpleFruit}(x)$)

**Key idea**: think of $p$ as a conjunction over all objects in the domain, negate
that conjunction, and convert back to a quantified formula.

$p$ | $\equiv \text{PurpleFruit}(\text{plum})\wedge\text{PurpleFruit}(\text{apple})\wedge\ldots$ | $\forall$ to conjunction |

$\neg p$ | $\equiv \neg(\text{PurpleFruit}(\text{plum})\wedge\text{PurpleFruit}(\text{apple})\wedge\ldots)$ | Negate both sides |

$\equiv \neg\text{PurpleFruit}(\text{plum})\vee\neg\text{PurpleFruit}(\text{apple})\vee\ldots$ | DeMorgan | |

$\equiv \exists x.\neg\text{PurpleFruit}(x)$ | Disjunction to $\exists$ |

**“There is no largest integer.”**

$\neg \exists x. \forall y. (x≥y)$ | $\equiv$ | $\forall x. \neg \forall y. (x \geq y) $ | DeMorgan |

$\equiv$ | $\forall x. \exists y. \neg (x \geq y) $ | DeMorgan | |

$\equiv$ | $\forall x. \exists y. (x < y) $ | Semantics of $>$ |

**“For every integer there is a larger integer.”**

Bound and free variables.

$\exists $$x$$. (P($$x$$)\wedge Q($$x$$))$

There is an object in the domain for which both $P$ and $Q$ are true.

**vs**

$\exists $$x$$. P($$x$$)\wedge \exists $$x$$. Q($$x$$)$

There is an object for which $P$ is true and an object for which $Q$ is true, and they may be different objects.

The formula inside of a quantifier is called its *scope*.

A variable is *bound* if it is in the scope of some quantifier.

A variable is *free* if it isn’t in the scope of any quantifier.

- Example: $\forall $$y$$. ((\exists $$x$$. P($$x$$)) \rightarrow Q($$x$$, $$y$$))$
- Is $y$ in $Q(x, y)$ bound or free? Bound.
- Is $x$ in $P(x)$ bound or free? Bound.
- Is $x$ in $Q(x, y)$ bound or free? Free.

$\forall \color{deeppink}x. (\exists \color{seagreen}y. (P(\color{deeppink}x,\color{seagreen}y)\rightarrow\forall\color{slateblue}x\, Q(\color{seagreen}y,\color{slateblue}x)))$

This isn’t wrong, but it’s confusing. Help your reader by using unique names for quantified variables. Names are cheap :)

The quantifier order matters.

- Bound variable names don’t matter.
- $\forall x. \exists y. P(x, y) \equiv \forall a. \exists b. P(a, b)$
- Quantifiers can sometimes move within the enclosing formula.
- $\forall x. (Q(x) \wedge \color{deeppink}{\exists y}. P(x, y)) ≡ \forall x. \color{deeppink}{\exists y}. (Q(x) \wedge P(x, y))$
- But the
*order*of quantifiers is important.

- Example: are these formulas true or false?
- $ \exists x. \forall y. \text{GreaterEq}(x, y)$ $\mathsf{F}$
- $ \forall y. \exists x. \text{GreaterEq}(x, y)$ $\mathsf{T}$

- Domain of discourse
- Integers
- Predicate definitions
- GreaterEq(x, y) $:=$ “x $\geq$ y”

Formula | When true |
When false |
---|---|---|

$\forall x. \forall y. P(x, y)$ | Every pair is true. | At least one pair is false. |

$\exists x. \exists y. P(x, y)$ | At least one pair is true. | All pairs are false. |

$\forall x. \exists y. P(x, y)$ | Every $x$ has a corresponding $y$. | Some $x$ doesn’t have a $y$. |

$\exists y. \forall x. P(x, y)$ | A particular $y$ works for every $x$. | Every $y$ has an $x$ that makes $P(x,y)$ false. |

- This is the form of the program synthesis query!
- $\exists P. \forall x. S(x, P(x))$
- “There is a program $P$ that satisfies the spec $S$ on every input $x$.”

- Predicate logic adds predicates and quantifiers to propositional logic.
- Predicate is a function that returns a truth value.
- Quantifiers let us talk about
*all*($\forall$) or*some*($\exists$) objects in the domain. - The domain of discourse is the set of objects over which the predicates and quantifiers in a formula are evaluated.
- When using quantifiers, keep in mind
- the DeMorgan’s laws for negating quantified formulas,
- which variables are free and bound, and
- the order of quantifiers.