<<

Syntax of Predicate

Syntax of Predicate Logic 1/25 The Language of Predicate Logic

• Domain: a non-empty of objects • Constants: concrete objects in the domain • Variables: placeholders for concrete objects in the domain • Functions: takes objects in the domain as and returns an object of the domain. • Predicates: takes objects in the domain as arguments and returns true or false. They describe properties of objects or relationships between objects. • Quantifiers: for how many objects in the domain is the statement true?

Syntax of Predicate Logic 2/25 A question on functions

Consider two translations of the sentence “every child is younger than its mother.”

1. (∀푥 (∀푦 ((퐶ℎ푖푙푑(푥) ∧ 푀표푡ℎ푒푟(푦, 푥)) → 푌 표푢푛푔푒푟(푥, 푦)))) 2. (∀푥 (퐶ℎ푖푙푑(푥) → 푌 표푢푛푔푒푟(푥, 푚표푡ℎ푒푟(푥))))

Which of the following is the best answer? a. Both are wrong. b. 1 is correct and 2 is wrong. c. 2 is correct and 1 is wrong. d. Both are correct. 1 is better. e. Both are correct. 2 is better.

The domain is the set of people. 퐶ℎ푖푙푑(푥) means 푥 is a child. 푀표푡ℎ푒푟(푥, 푦) means 푥 is 푦’s mother. 푌 표푢푛푔푒푟(푥, 푦) means 푥 is younger than 푦. 푚표푡ℎ푒푟(푥) returns 푥’s mother. Syntax of Predicate Logic 3/25 Functions

Using functions allows us to avoid ugly/inelegant predicate logic formulas. Try translating the following sentence with and without functions. “Andy and Paul have the same maternal grandmother.”

Syntax of Predicate Logic 4/25 The Language of Predicate Logic

The seven kinds of symbols:

1. Constant symbols. Usually 푐, 푑, 푐1, 푐2, … , 푑1, 푑2 … 2. Variables. Usually 푥, 푦, 푧, … 푥1, 푥2, … , 푦1, 푦2 … 3. symbols. Usually 푓, 푔, ℎ, … 푓1, 푓2, … , 푔1, 푔2,… 4. Predicate symbols. 푃 , 푄,…푃1, 푃2, …, 푄1, 푄2,… 5. Connectives: ¬, ∧, ∨, →, and ↔ 6. Quantifiers: ∀ and ∃ 7. Punctuation: ‘(’, ‘)’, and ‘,’ Function symbols and predicate symbols have an assigned arity—the number of arguments required. For example,

• 푓(1): 푓 is a unary function. • 푃 (2): 푃 is a binary predicate.

Syntax of Predicate Logic Symbols 5/25 Two kinds of expressions

In predicate logic, we need to consider two kinds of expressions:

• those that refer to an object of the domain, called terms, and • those that can have a value, called formulas.

Syntax of Predicate Logic Terms and Formulas 6/25 Terms

Each term refers to an object of the domain. We define the set of terms inductively as follows.

1. Each constant symbol is an atomic term. 2. Each variable is an atomic term.

3. 푓(푡1, … , 푡푛) is a term if 푡1, … , 푡푛 are terms and 푓 is an 푛-ary function symbol. (If 푓 is a binary function symbol, then we may write (푡1 푓 푡2) instead of 푓(푡1, 푡2).) 4. Nothing else is a term.

Syntax of Predicate Logic Terms and Formulas 7/25 Which expressions are terms?

A term refers to an object of the domain. Which of the following expressions is a term? a. 푔(푑, 푑) b. 푃 (푓(푥, 푦), 푑) c. 푓(푥, 푔(푦, 푧), 푑) d. 푔(푥, 푓(푦, 푧), 푑)

Let 푑 be a constant symbol. Let 푃 be a predicate symbol with 2 arguments. Let 푓 be a function symbol with 2 arguments and 푔 be a function symbol with 3 arguments. Let 푥, 푦, and 푧 be variable symbols.

Syntax of Predicate Logic Terms and Formulas 8/25 Is this a term?

True or False: The expression (2 − 푓(푥)) + (푦 ∗ 푥) is a term. a. True b. False c. Not enough information to tell

The domain is the set of integers. +, − and ∗ are binary functions. 푓 is a unary function. 푥 and 푦 are variables and 2 is a constant.

Syntax of Predicate Logic Terms and Formulas 9/25 Well-Formed Predicate Logic Formulas

We define the set of well-formed formulas of predicate logic inductively as follows.

1. 푃 (푡1, … , 푡푛) is an atomic formula if 푃 is an 푛-ary predicate symbol and each 푡푖 is a term (1 ≤ 푖 ≤ 푛). 2. (¬훼) is a formula if 훼 is a formula. 3. (훼 ⋆ 훽) is a formula if 훼 and 훽 are formulas and ⋆ is a binary connective symbol. 4. Each of (∀푥 훼) and (∃푥 훼) is a formula if 훼 is a formula and 푥 is a variable. 5. Nothing else is a formula.

Syntax of Predicate Logic Terms and Formulas 10/25 Determine whether a formula is well-formed

푚 is a constant and 푥 and 푦 are variables. 푃 (2) and 푄(2) are binary predicates. 푓(1) is a unary function. Which of the following is a well-formed predicate logic formula? a. (푓(푥) → 푃 (푥, 푦)) b. ∀푦 푃 (푚, 푓(푦)) c. 푃 (푥, 푦) → 푄(푄(푥)) d. 푄(푚, 푓(푚)) e. 푃 (푚, 푓(푄(푥, 푦)))

Syntax of Predicate Logic Terms and Formulas 11/25 Determine whether a formula is well-formed

Things to consider:

• Are there enough brackets? Are the brackets in the right places? • Is each unary/binary connective applied to the right number of predicates? • Does every function have the right number and type of arguments? • Does every predicate have the right number and type of arguments?

Syntax of Predicate Logic Terms and Formulas 12/25 Comparing the Definitions of WFFs

Let’s compare and contrast the definitions of WFFs for propositional and predicate logic.

• Which parts of the two definitions are the same? • The definition of WFF for propositional logic says that a propositional variable is an atomic WFF. Is this still the case for predicate logic? • What is new in the definition of WFF for predicate logic compared to the definition of WFF for propositional logic? • If we were to prove that every WFF for predicate logic has a property P by structural induction, what does the proof look like? What are the base case(s) and what are the cases in the induction step?

Syntax of Predicate Logic Terms and Formulas 13/25 Parse Trees of Predicate Logic Formulas

New elements in the parse tree:

• Quantifiers ∀푥 and ∃푦 has one subtree, similar to the unary connective negation.

• A predicate 푃 (푡1, 푡2, … , 푡푛) has a node labelled 푃 with a sub-tree for each of the terms 푡1, 푡2, … , 푡푛.

• A function 푓(푡1, 푡2, … , 푡푛) has a node labelled 푓 with a sub-tree for each of the terms 푡1, 푡2, … , 푡푛. Example 1: (∀푥 (푃 (푥) ∧ 푄(푥))) → (¬(푃 (푓(푥, 푦)) ∨ 푄(푦))) Example 2: (∀푥 ((푃 (푥) ∧ 푄(푥)) → (¬(푃 (푓(푥, 푦)) ∨ 푄(푦)))))

Syntax of Predicate Logic Terms and Formulas 14/25 Evaluating a Formula

To evaluate the of a formula, we need to replace the variables by concrete objects in the domain. However, we don’t necessarily have to perform this substitution for every variable. There are two types of variables in a formula:

• A variable may be free. To evaluate the formula, we need to replace a free variable by an object in the domain. • A variable may be bound by a . The quantifier tells us how to evaluate the formula.

We need to understand how to determine whether a variable is free/bound and how to replace a free variable with an object in the domain.

Syntax of Predicate Logic Free and Bound Variables 15/25 Free and Bound Variables

In a formula (∀푥 훼) or (∃푥 훼), the scope of a quantifier is the formula 훼. A quantifier binds its variable within its scope. An occurrence of a variable in a formula is bound if it lies in the scope of some quantifier of the same variable. Otherwise the occurrence ofthis variable is free.

• If a variable occurs multiple times, we need to consider each occurrence of the variable separately. • The variable symbol immediately after ∃ or ∀ is neither free nor bound.

A formula with no free variables is called a closed formula or sentence.

Syntax of Predicate Logic Free and Bound Variables 16/25 Determine whether a variable is free or bound

Determine whether a variable is free or bound using a parse tree.

1. Draw the parse tree for the formula. 2. Choose the leaf node for an occurrence of a variable. 3. Walk up the tree. Stop as soon as we encounter a quantifier for this variable or we reach the root of the tree. 4. If we encountered a quantifier for the variable, this occurrence of the variable is bound. 5. If we reached the root of the tree which is not a quantifier for the variable, this occurrence of the variable is free.

Example 1: (∀푥 (푃 (푥) ∧ 푄(푥))) → (¬(푃 (푓(푥, 푦)) ∨ 푄(푦))) Example 2: (∀푥 ((푃 (푥) ∧ 푄(푥)) → (¬(푃 (푓(푥, 푦)) ∨ 푄(푦)))))

Syntax of Predicate Logic Free and Bound Variables 17/25 Substitution

When writing proofs in predicate logic, it is often useful to replace a variable in a formula with a term. Suppose that the following sentences are true:

(∀푥 (Fish(푥) → Swim(푥))) (1)

Fish(Nemo) (2) To conclude that Nemo can swim, we need to replace every occurence of the variable x in the implication Fish(푥) → Swim(푥) by the term Nemo. This gives us (Fish(Nemo) → Swim(Nemo)) (3) By modus ponens on (2) and (3), we conclude that Swim(Nemo). Formally, we use substitution to refer to the process of replacing 푥 by Nemo in the formula ∀푥 Fish(푥) → Swim(푥).

Syntax of Predicate Logic Substitution 18/25 Substitution

Intuitively, 훼[푡/푥] answers the question,

“What happens to 훼 if 푥 has the value specified by term 푡?”

For a variable 푥, a term 푡, and a formula 훼, 훼[푡/푥] denotes the resulting formula by replacing each free occurrence of 푥 in 훼 with 푡. In other words, substitution does NOT affect bound occurrences of the variable.

Syntax of Predicate Logic Substitution 19/25 Examles of Substitution

Examples.

• If 훼 is the formula 퐸(푓(푥)), then 훼[(푦 + 푦)/푥] is 퐸(푓(푦 + 푦)). • 훼[푓(푥)/푥] is 퐸(푓(푓(푥))). • 퐸(푓(푥 + 푦))[푦/푥] is 퐸(푓(푦 + 푦)).

• If 훽 is (∀푥 (퐸(푓(푥)) ∧ 푆(푥, 푦))), then 훽[푔(푥, 푦)/푥] is 훽, because 훽 has no free occurrence of 푥.

Syntax of Predicate Logic Substitution 20/25 Examples: Substitution

Example. Let 훽 be (푃 (푥) ∧ (∃푥 푄(푥))). What is 훽[푦/푥]? 훽[푦/푥] is (푃 (푦) ∧ (∃푥 푄(푥))). Only the free 푥 gets substituted.

Example. What about 훽[(푦 − 1)/푧], where 훽 is (∀푥 (∃푦 ((푥 + 푦) = 푧))))?

At first thought, we might say (∀푥 (∃푦 ((푥 + 푦) = (푦 − 1)))). But there’s a problem—the free variable 푦 in the term (푦 − 1) got “captured” by the quantifier ∃푦.

We want to avoid this capture.

Syntax of Predicate Logic Substitution 21/25 Preventing Capture

Example. Formula 훼 = 푆(푥) ∧ ∀푦 (푃 (푥) → 푄(푦)); term 푡 = 푓(푦, 푦). The leftmost 푥 can be substituted by 푡 since it is not in the scope of any quantifier, but substituting in 푃 (푥) puts the variable 푦 into the scope of ∀푦.

We can prevent capture of variables by a different choice of variable. (Above, we might be able to substitute 푓(푧, 푧) instead of 푓(푦, 푦). Or alter 훼 to quantify some other variable.)

Syntax of Predicate Logic Substitution 22/25 Substitution—Formal Definition

Let 푥 be a variable and 푡 a term. For a term 푢, the term 푢[푡/푥] is 푢 with each occurrence of the variable 푥 replaced by the term 푡. For a formula 훼,

1. If 훼 is 푃 (푡1, … , 푡푘), then 훼[푡/푥] is 푃 (푡1[푡/푥], … , 푡푘[푡/푥]). 2. If 훼 is (¬훽), then 훼[푡/푥] is (¬훽[푡/푥]). 3. If 훼 is (훽 ⋆ 훾), then 훼[푡/푥] is (훽[푡/푥] ⋆ 훾[푡/푥]). 4. …

(Continued next page…)

Syntax of Predicate Logic Substitution 23/25 Substitution—Formal Definition (2)

For variable 푥, term 푡 and formula 훼:

⋮ 4. If 훼 is (푄푥 훽), then 훼[푡/푥] is 훼. 5. If 훼 is (푄푦 훽) for some other variable 푦, then (a) If 푦 does not occur in 푡, then 훼[푡/푥] is (푄푦 훽[푡/푥]). (b) Otherwise, select a variable 푧 that occurs in neither 훼 nor 푡; then 훼[푡/푥] is (푄푧 (훽[푧/푦])[푡/푥]).

The last case prevents capture by renaming the quantified variable to something harmless.

Syntax of Predicate Logic Substitution 24/25 Example, Revisited

Example. If 훼 is (∀푥 (∃푦 (푥 + 푦 = 푧))), what is 훼[(푦 − 1)/푧]? This falls under case 5(b): the term to be substituted, namely 푦 − 1, contains a variable 푦 quantified in formula 훼. Let 훽 be (푥 + 푦 = 푧); thus 훼 is (∀푥 (∃푦 훽)). Select a new variable, say 푤. Then

훽[푤/푦] is 푥 + 푤 = 푧, and 훽[푤/푦][(푦 − 1)/푧] is (푥 + 푤) = (푦 − 1) .

Thus the required formula 훼[(푦 − 1)/푧] is

(∀푥 ∃푤((푥 + 푤) = (푦 − 1))) .

Syntax of Predicate Logic Substitution 25/25