# CSE 311 Lecture 08: Inference Rules and Proofs for Predicate Logic

## Topics

Propositional logic proofs
A brief review of Lecture 07.
A quick look at predicate logic proofs
Inference rules for quantifiers and a “hello” world example.
An in-depth look at predicate logic proofs
Understanding rules for quantifiers through more advanced examples.

$\newcommand{rule}[2]{\begin{array}{c}#1\\ \hline \therefore #2\end{array}}$ $\newcommand{ruletemplate}[2]{\begin{array}{c}#1\\ \hline #2\end{array}}$ $\newcommand{hilite}[2]{\color{#1}{#2}}$ $\newcommand{arbitrary}[1]{\color{SteelBlue}{#1}}$ $\newcommand{specific}[1]{\color{MediumSeaGreen}{#1}}$ $\newcommand{qed}{\square}$

## Propositional logic proofs

A brief review of Lecture 07.

### Inference rules for propositional logic

Two rules per binary connective: to eliminate and introduce it.

Intro $\wedge$ $\rule{A; B}{A \wedge B}$
Elim $\wedge$ $\rule{A\wedge B}{A,B}$

Intro $\vee$ $\rule{A}{A\vee B, B\vee A}$
Elim $\vee$ $\rule{A\vee B; \neg A}{B}$

Direct Proof Rule $\rule{A\implies B}{A\rightarrow B}$
Modus Ponens $\rule{A ; A\rightarrow B}{B}$

Direct Proof Rule is special: not like the other rules.

### Proving implications with the direct proof rule

Direct Proof Rule $\rule{A\implies B}{A\rightarrow B}$

The premise $A\implies B$ means “Given $A$, we can prove $B$.”

So the direct proof rule says that if we have such a proof, then we can conclude that $A\rightarrow B$ is true.

Example: prove $(p\wedge q) \rightarrow (p \vee q)$.

 1.1. $p\wedge q$ Assumption 1.2. $p$ Elim $\wedge$: 1.1 1.3. $p\vee q$ Intro $\vee$: 1.2
 2 $(p\wedge q) \rightarrow (p \vee q)$ Direct Proof Rule
• Indent the proof subroutine.
• Write the assumption and the goal.
• Fill in the steps.

### Why does the direct proof rule work?

Inference rules let us derive facts that are implied by the existing facts.

So, for every rule $\rule{P}{Q}$, $P \rightarrow Q$ is a tautology ($P \rightarrow Q \equiv \mathsf{T}$).

The proof $P\implies Q$ shows that $P \rightarrow Q$ is a tautology ($P \rightarrow Q\equiv \mathsf{T}$), since it just a series of implications that we know are tautologies.

So the Direct Proof Rule $\small{\rule{A\implies B}{A\rightarrow B}}$ says that we can add $A\rightarrow B$ to our set of facts, if we can show that $A\rightarrow B$ is a tautology.

One way to show that $A \rightarrow B\equiv \mathsf{T}$ is by writing a subproof, using all the facts we have inferred up to that point.

### An example proof

Prove $((p\rightarrow q)\wedge(q\rightarrow r))\rightarrow(p\rightarrow r)$.

 1.1. $(p\rightarrow q)\wedge(q\rightarrow r)$ Assumption 1.2. $p\rightarrow q$ Elim $\wedge$: 1.1 1.3. $q\rightarrow r$ Elim $\wedge$: 1.1
 1.4.1. $p$ Assumption 1.4.2. $q$ MP: 1.2, 1.4.1 1.4.3. $r$ MP: 1.3, 1.4.2
 1.5. $p\rightarrow r$ Direct Proof Rule
 2 $((p\rightarrow q)\wedge(q\rightarrow r))\rightarrow(p\rightarrow r)$ Direct Proof Rule
• Write the premise and the conclusion.
• Work forwards and backwards.
• We’ll need parts of 1.1 so Elim $\wedge$ to get 1.2, 1.3.
• We can use DPR to get 1.5.
• Using MP on 1.2, 1.4.1 gives us 1.4.2.
• Using MP on 1.3, 1.4.2 gives us 1.4.3.

### Which facts can be used in a subproof?

 1.1. $(p\rightarrow q)\wedge(q\rightarrow r)$ Assumption 1.2. $p\rightarrow q$ Elim $\wedge$: 1.1 1.3. $q\rightarrow r$ Elim $\wedge$: 1.1
 1.4.1. $p$ Assumption 1.4.2. $q$ MP: 1.2, 1.4.1 1.4.3. $r$ MP: 1.3, 1.4.2
 1.5. $p\rightarrow r$ Direct Proof Rule
 2 $((p\rightarrow q)\wedge(q\rightarrow r))\rightarrow(p\rightarrow r)$ Direct Proof Rule
• A line $k$ in a (sub)proof can use a fact at line $i$ if the set of assumptions and givens that $k$ is derived from contains all the assumptions and givens that $i$ is derived from.
• So, 1.4.2 can use 1.2 because they are derived from the assumptions {1.1, 1.4.1} and {1.1}, respectively.
• Can 1.5 use 1.4.3?
• No. Because 1.5 is derived from {1.1} and 1.4.3 from {1.1, 1.4.1}.
• Can 2 use 1.2?
• No. Because 2 is derived from {} and 1.2 from {1.1}.

### Which facts can be used in a subproof? A mnemonic

{

{

 1.1. $(p\rightarrow q)\wedge(q\rightarrow r)$ Assumption 1.2. $p\rightarrow q$ Elim $\wedge$: 1.1 1.3. $q\rightarrow r$ Elim $\wedge$: 1.1

{

 1.4.1. $p$ Assumption 1.4.2. $q$ MP: 1.2, 1.4.1 1.4.3. $r$ MP: 1.3, 1.4.2

}

 1.5. $p\rightarrow r$ Direct Proof Rule

}

 2 $((p\rightarrow q)\wedge(q\rightarrow r))\rightarrow(p\rightarrow r)$ Direct Proof Rule

}

This is just like Java’s scoping rules.

### A general proof strategy

1. Look at the rules for introducing connectives to see how you would build up the formula you want to prove from pieces of what is given.

2. Use the rules for eliminating connectives to break down the given formulas so that you get the pieces need for 1

3. Write the proof beginning with what you figured out for 2 followed by 1.

Intro $\wedge$ $\rule{A; B}{A \wedge B}$
Elim $\wedge$ $\rule{A\wedge B}{A,B}$

Intro $\vee$ $\rule{A}{A\vee B, B\vee A}$
Elim $\vee$ $\rule{A\vee B; \neg A}{B}$

Direct Proof Rule $\rule{A\implies B}{A\rightarrow B}$
Modus Ponens $\rule{A ; A\rightarrow B}{B}$

## A quick look at predicate logic proofs

Inference rules for quantifiers and a “hello” world example.

### Inference rules for quantifiers

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

The name $a$ stands for an arbitrary value in the domain. No other name in $P$ depends on $a$.

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

The name $c$ is fresh and stands for a value in the domain where $P(c)$ is true. List all dependencies for $c$.

### Predicate logic proofs can use …

Predicate logic inference rules
Applied to whole formulas only.
Predicate logic equivalences
Even on subformulas.
Propositional logic inference rules
Applied to whole formulas only.
Propositional logic equivalences
Even on subformulas.

### A “hello world” proof

Prove $(\forall x. P(x)) \rightarrow (\exists x. P(x))$.

 1.1. $\forall x. P(x)$ Assumption 1.2. $P(c)$ Elim $\forall$: 1.1 1.3. $\exists x. P(x)$ Intro $\exists$: 1.2
 2 $(\forall x. P(x)) \rightarrow (\exists x. P(x))$ Direct Proof Rule
• Given $\rightarrow$, so use Direct Proof Rule.
• We can use Intro $\exists$ to get 1.3, but need $P(c)$ for some $c$.
• We have $P(c)$ from Elim $\forall$ on 1.1.

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

Working forwards and backwards:
In applying Intro $\exists$ rule, we didn’t know what expression we might be able to prove $P(c)$ for, so we worked forwards to figure out what might work.

## An in-depth look at predicate logic proofs

Understanding rules for quantifiers through more advanced examples.

### Advanced proofs: considering domain semantics

So far, we have treated the predicate definitions as black boxes, and the domain of discourse as a set of objects with no additional properties.

In practice, we want to prove theorems for specific domains, and use the properties of those domains in our proofs.

For example, the set of integers is equipped with the operators $+,\cdot,=$.

We can use these operators in our predicates (below) and proofs (next):

Domain of discourse
Integers
Predicate definitions
$\text{Even}(x) ::= \exists y. x = 2\cdot y$

### A not so odd example

Prove that there is an even number: $\exists x. \text{Even}(x)$.

 1 $\specific{2} = \specific{2}\cdot \hilite{SteelBlue}{1}$ Arithmetic 2 $\exists \hilite{SteelBlue}{y}. \specific{2} = \specific{2}\cdot \hilite{SteelBlue}{y}$ Intro $\exists$: 1 3 $\text{Even}(\specific{2})$ Definition of Even: 2 4 $\exists \specific{x}. \text{Even}(\specific{x})$ Intro $\exists$: 3
Domain of discourse
Integers
Predicate definitions
$\text{Even}(x) ::= \exists y. x = 2\cdot y$

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

### A prime example

Prove that there is an even prime number: $\exists x. \text{Even}(x) \wedge \text{Prime}(x)$.

 1 $\specific{2} = \specific{2}\cdot \hilite{SteelBlue}{1}$ Arithmetic 2 $\exists \hilite{SteelBlue}{y}. \specific{2} = \specific{2}\cdot \hilite{SteelBlue}{y}$ Intro $\exists$: 1 3 $\text{Even}(\specific{2})$ Definition of Even: 2 4 $\text{Prime}(\specific{2})$ Property of integer 2 5 $\text{Even}(\specific{2}) \wedge \text{Prime}(\specific{2})$ Intro $\wedge$: 3, 4 6 $\exists \specific{x}. \text{Even}(\specific{x}) \wedge \text{Prime}(\specific{x})$ Intro $\exists$: 5
Domain of discourse
Integers
Predicate definitions
$\text{Even}(x) ::= \exists y. x = 2\cdot y$
$\text{Prime}(x) ::=$ “$x$ is prime”

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

We use a black-box definition of Prime because the proof won’t need to break it down further.

### An equal example

Prove that $\forall y. \exists z. y = z$ follows from $\forall x. x = x$.

 1 $\forall x. x = x$ Given 2 $\arbitrary{a}=\arbitrary{a}$ Elim $\forall$: 1, $\arbitrary{a}$ is arbitrary 3 $\exists z. \arbitrary{a}=z$ Intro $\exists$: 2 4 $\forall y. \exists z. y=z$ Intro $\forall$: 3
Domain of discourse
Integers

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

### A square example

Prove that the square of every even number is even: $\forall x. \text{Even}(x) \rightarrow \text{Even}(x^2)$.

 1 Let $\arbitrary{a}$ be an arbitrary integer.
 2.1. $\text{Even}(\arbitrary{a})$ Assumption 2.2. $\exists \specific{y}. \arbitrary{a} = 2\specific{y}$ Definition of Even: 2.1 2.3. $\arbitrary{a} = 2\specific{b}$ Elim $\exists$: 2.2, $\specific{b}$ depends on $\arbitrary{a}$ 2.4. $\arbitrary{a}^2 = 4\specific{b}^2 = 2(2\specific{b}^2)$ Algebra 2.5. $\exists y. \arbitrary{a}^2 = 2y$ Intro $\exists$: 2.4 2.6. $\text{Even}(\arbitrary{a}^2)$ Definition of Even: 2.5
 3 $\text{Even}(\arbitrary{a}) \rightarrow \text{Even}(\arbitrary{a}^2)$ Direct Proof Rule 4 $\forall x. \text{Even}(x) \rightarrow \text{Even}(x^2)$ Intro $\forall$: 1, 3
• Use Intro $\forall$ on 1 and 2.
• $\rightarrow$ so use DRP to get 3.
• Use definition of Even to break down 2.1 and 2.6.
• Use Elim $\exists$ on 2.2.
• Use algebra on 2.3 to match the body of 2.5.
• Use Intro $\exists$ on 2.4 to get 2.5.
Domain of discourse
Integers
Predicate definitions
$\text{Even}(x) ::= \exists y. x = 2\cdot y$

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

### Why list dependencies? To avoid incorrect proofs.

Over the integer domain: $\forall x. \exists y. y\geq x$ is True but $\exists y. \forall x. y\geq x$ is False.

 1 $\forall x. \exists y. y\geq x$ Given 2 Let $\arbitrary{a}$ be an arbitrary integer. 3 $\exists \specific{y}. \specific{y}\geq \arbitrary{a}$ Elim $\forall$: 1 4 $\specific{b}\geq \arbitrary{a}$ Elim $\exists$: 3, $\specific{b}$ depends on $\arbitrary{a}$ 5 $\forall x. \specific{b}\geq x$ Intro $\forall$: 2, 4 6 $\exists y. \forall x. y\geq x$ Intro $\exists$: 5

Example: an incorrect proof.

Can’t get rid of $\arbitrary{a}$ since another name, $\specific{b}$, in the same formula depends on it!

Elim $\forall$ $\rule{\forall x. P(x)}{P(a) \text{ for any } a}$

Intro $\forall$ $\rule{P(a); a \text{ is } \color{MediumVioletRed}{\text{arbitrary}}}{\forall x. P(x)}$

The name $a$ stands for an arbitrary value in the domain. No other name in $P$ depends on $a$.

Intro $\exists$ $\rule{P(c) \text{ for some } c}{\exists x. P(x)}$

Elim $\exists$ $\rule{\exists x. P(x)}{P(c) \text{ for a } \color{MediumVioletRed}{\text{specific }} c }$

The name $c$ is fresh and stands for a value in the domain where $P(c)$ is true. List all dependencies for $c$.

## Summary

Predicate logic proofs extend propositional logic proofs.
Can use all rules and equivalences for propositional logic.
Plus inference rules for quantifiers and equivalences for predicate logic.
When applying Intro $\forall$ to $P(a)$, make sure that
$a$ is arbitrary, and
no other name depends on $a$.
When applying Elim $\exists$ to $\exists x. P(x)$, make sure that
$c$ in $P(c)$ is fresh, and
all the dependencies for $c$ are listed.