Predicate Logic: Syntax

Alice Gao

Lecture 12

CS 245 Logic and Computation Fall 2019 1 / 30 Outline

Learning goals

Symbols

Terms

Formulas

Parse Trees

Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 2 / 30 Learning goals

By the end of this lecture, you should be able to ▶ Define the set of terms inductively. ▶ Define the set of formulas inductively. ▶ Determine whether a variable in a formula is free or bound. ▶ Prove properties of terms and formulas by structural induction. ▶ Draw the parse tree of a formula.

CS 245 Logic and Computation Fall 2019 3 / 30 The Language of Predicate Logic

▶ Domain: a non-empty set of objects. ▶ Individuals: concrete objects in the domain. ▶ Variables: placeholders for concrete objects in the domain. ▶ Functions: takes objects in the domain as arguments and returns an object of the domain. ▶ Relations: 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 isthe statement true?

CS 245 Logic and Computation Fall 2019 4 / 30 Outline

Learning goals

Symbols

Terms

Formulas

Parse Trees

Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 5 / 30 Predicate Language 퐿

Eight classes of symbols: ▶ Individual symbols: 푎, 푏, 푐. ▶ Relation symbols: 퐹 , 퐺, 퐻. A special equality symbol ≈ ▶ Function symbols: 푓, 푔, ℎ. ▶ Free variable symbols: 푢, 푣, 푤. ▶ Bound variable symbols: 푥, 푦, 푧. ▶ Connective symbols: ¬, ∧, ∨, →, ↔. ▶ Quantifier symbol: ∀, ∃. ▶ Punctuation symbols: ‘(’, ‘)’, and ‘,’

CS 245 Logic and Computation Fall 2019 6 / 30 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. ▶ is free, otherwise.

CS 245 Logic and Computation Fall 2019 7 / 30 Outline

Learning goals

Symbols

Terms

Formulas

Parse Trees

Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 8 / 30 Two Kinds of Expressions

Two kinds of expressions: ▶ A term refers to an object in the domain. ▶ A formula evaluates to 1 or 0.

CS 245 Logic and Computation Fall 2019 9 / 30 Terms

The set of terms Term(퐿) is defined below: 1. An individual symbol 푎 standing alone is a term. 2. A free variable symbol 푢 standing alone is a term.

3. If 푡1, … , 푡푛 are terms and 푓 is an 푛-ary function symbol, then 푓(푡1, … , 푡푛) is a term. 4. Nothing else is a term.

CS 245 Logic and Computation Fall 2019 10 / 30 Examples of Terms

Terms: ▶ 푎, 푏, 푐, 푢, 푣, 푤 ▶ 푓(푏), 푔(푎, 푓(푏)), 푔(푢, 푏), 푓(푔(푓(푢), 푏))

A term with no free variable symbols is called a closed term. Which one(s) of the above are closed terms?

CS 245 Logic and Computation Fall 2019 11 / 30 CQ: Which expressions are terms?

Which of the following expressions is a term? If there are multiple correct answers, choose your favourite one. (A) 푤 (B) 푔(푎, 푢) (C) 퐹 (푓(푢, 푣), 푎) (D) 푓(푢, 푔(푣, 푤), 푎) (E) 푔(푢, 푓(푣, 푤), 푎) Individual symbols: 푎 Relation symbols: 퐹 is a binary relation symbol. Function symbols: 푓 is a binary function symbol and 푔 is a 3-ary function symbol. Free variable symbols: 푢, 푣, 푤.

CS 245 Logic and Computation Fall 2019 12 / 30 Defining the set of terms inductively

The set of terms can be inductively defined as follows: ▶ The domain set 푋: The set of finite sequences of symbols of 퐿 ▶ The core set 퐶: The set of all individual symbols and free variable symbols ▶ The set of operations 푃 : The set of all function symbols

CS 245 Logic and Computation Fall 2019 13 / 30 Structural induction on terms

Theorem: Every term has a property 푃 . Proof by structural induction: ▶ Base cases: The term is an individual symbol. The term is a free variable symbol. ▶ Inductive cases:

The term is 푓(푡1, … , 푡푛) where 푓 is an n-ary function and 푡1, ..., 푡푛 are terms. Induction hypotheses: Assume that 푡1, … , 푡푛 all have the property 푃 .

We need to show that 푓(푡1, … , 푡푛) has the property 푃 .

CS 245 Logic and Computation Fall 2019 14 / 30 Outline

Learning goals

Symbols

Terms

Formulas

Parse Trees

Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 15 / 30 Atomic Formulas

The set of atomic formulas Atom(퐿) is defined below: ▶ If 퐹 is an n-ary relation symbol and 푡1, … , 푡푛 (푛 ≥ 1) are terms, then 퐹 (푡1, … , 푡푛) is an atomic formula. ▶ If 푡1, 푡2 are terms, then ≈ (푡1, 푡2) is an atomic formula. ▶ Nothing else is an atomic formula.

CS 245 Logic and Computation Fall 2019 16 / 30 Examples of Atomic Formulas

Terms: ▶ 푎, 푏, 푐, 푢, 푣, 푤 ▶ 푓(푏), 푔(푎, 푓(푏)), 푔(푢, 푏), 푓(푔(푓(푢), 푏))

Atomic formulas: ▶ 퐹 (푎, 푢, 푓(푏), 푓(푤), 푔(푣, 푓(푎))) ▶ ≈ (푏, 푤)

CS 245 Logic and Computation Fall 2019 17 / 30 Well-Formed Formulas

The set of well-formed formulas Form(퐿) is defined below: 1. An atomic formula is a well-formed formula. 2. If 퐴 is a well-formed formula, then (¬퐴) is a well-formed formula. 3. If 퐴 and 퐵 are well-formed formulas and ⋆ is one of ∧, ∨, →, and ↔, then (퐴 ⋆ 퐵) is a well-formed formula. 4. If 퐴(푢) is a well-formed formula and 푥 does not occur in 퐴(푢), then ∀푥 퐴(푥) and ∃푥 퐴(푥) are well-formed formulas. 5. Nothing else is a well-formed formula.

CS 245 Logic and Computation Fall 2019 18 / 30 Explaining Case 4 of Formulas

If 퐴(푢) is a well-formed formula and 푥 does not occur in 퐴(푢), then ∀푥 퐴(푥) and ∃푥 퐴(푥) are well-formed formulas. ▶ 퐴(푢) is a well-formed formula where 푢 is a free variable in the formula. We want to quantify 푢. ▶ In order to do so, we need to choose a symbol for a bound variable, e.g. 푥. We need to make sure that our choice of the bound variable symbol does not already occur in 퐴(푢).

CS 245 Logic and Computation Fall 2019 19 / 30 Examples for Case 4

▶ We are allowed to generate the formula ∀푦퐹 (푦, 푦). Start with 퐹 (푢, 푢). If we quantify 푢 by replacing it with 푦, we get ∀푦퐹 (푦, 푦).

▶ We are not allowed to generate the formula ∃푦∀푦퐹 (푦, 푦). Start with ∀푦퐹 (푦, 푦). If we want to add the ∃ quantifier, we will need to choose a bound variable symbol that is not 푦 because 푦 already appears in ∀푦 퐹 (푦, 푦). So, there is no way for us to generate ∃푦∀푦퐹 (푦, 푦).

▶ We are allowed to generate the formula ∃푥퐺(푥) ∨ ∀푥퐻(푥). Start with 퐺(푢) and 퐻(푣) separately. We can quantify 푢 by replacing it with 푥 since 푥 does not appear in 퐺(푢)). We get ∃푥퐺(푥). We can quantify 푣 by replacing it with 푥 since 푥 does not appear in 퐻(푣). We get ∀푥퐻(푥). Connecting the two formulas using ∨, we get ∃푥퐺(푥) ∨ ∀푥퐻(푥).

CS 245 Logic and Computation Fall 2019 20 / 30 Examples of Formulas

Well-Formed Formulas: ▶ 퐹 (푎, 푏), ∀푦 퐹 (푎, 푦), ∃푥∀푦 퐹 (푥, 푦) ▶ 퐹 (푢, 푣), ∃푦 퐹 (푢, 푦)

A formula with no free variable symbols is called a closed formula or a sentence. Which formulas above are closed formulas?

CS 245 Logic and Computation Fall 2019 21 / 30 Determine whether a formula is well-formed

Which of the following is a well-formed formula? (A) 푓(푢) → 퐹 (푢, 푣) (B) ∀푥 퐹 (푚, 푓(푥)) (C) 퐹 (푢, 푣) → 퐺(퐺(푢)) (D) 퐺(푚, 푓(푚)) (E) 퐹 (푚, 푓(퐺(푢, 푣))) Individual symbols: 푚. Free Variable Symbols: 푢, 푣. Bound Variable symbols: 푥. Relation symbols: 퐹 and 퐺 are binary relation symbols. Function symbols: 푓 is a unary function.

CS 245 Logic and Computation Fall 2019 22 / 30 Defining the set of formulas inductively

The set of formulas can be inductively defined as follows: ▶ The domain set 푋: The set of finite sequences of symbols of 퐿 ▶ The core set 퐶: The set of all atomic formulas. ▶ The set of operations 푃 :

푓1(푥) = (¬푥) 푓2(푥, 푦) = (푥 ∗ 푦) where ∗ is one of ∧, ∨, →, and ↔. 푓3(퐴(푢)) = ∀푥 퐴(푥), 푓4(퐴(푢)) = ∃푥 퐴(푥) where 푥 does not occur in 퐴(푢).

CS 245 Logic and Computation Fall 2019 23 / 30 Structural induction on formulas

Theorem: Every formula has a property 푃 . Proof by structural induction: ▶ Base cases: The formula is an atomic formula. ▶ Inductive cases: The formula is (¬퐴) where 퐴 is a formula. The formula is (퐴 ∗ 퐵) where 퐴 and 퐵 are formulas and ∗ is a binary connective. The formula is ∀푥 퐴(푥) and ∃푥 퐴(푥) where 퐴(푢) is a formula and 푥 does not occur in 퐴(푢).

CS 245 Logic and Computation Fall 2019 24 / 30 Comparing the Definitions of Well-Formed Formulas

Let’s compare the set of predicate formulas to the set of propositional formulas. Questions to think about: ▶ Which parts of the two definitions are the same? The cases for negation and binary connectives are the same. ▶ Which parts of the two definitions are different? Atomic formulas are different.

▶ Atomic propositional formulas are propositional variables. ▶ Atomic predicate formulas are relations applied to terms. Predicate formulas have one additional case for quantifiers.

CS 245 Logic and Computation Fall 2019 25 / 30 Outline

Learning goals

Symbols

Terms

Formulas

Parse Trees

Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 26 / 30 Parse Trees of Predicate Formulas

▶ The leaves are atomic formulas. ▶ Every quantifier has exactly one child (namely the formula which is its scope). Example: ∀푥(퐹 (푏) → ∃푦(∀푧 퐺(푦, 푧) ∨ 퐻(푓(푢), 푥, 푦)))

CS 245 Logic and Computation Fall 2019 27 / 30 Parse tree

Example: ∀푥(퐹 (푏) → ∃푦(∀푧 퐺(푦, 푧) ∨ 퐻(푓(푢), 푥, 푦))) Parse tree:

∀푥(퐹 (푏) → ∃푦(∀푧 퐺(푦, 푧) ∨ 퐻(푓(푢), 푥, 푦)))

퐹 (푏) → ∃푦(∀푧 퐺(푦, 푧) ∨ 퐻(푓(푢), 푣, 푦))

퐹 (푏) ∃푦(∀푧 퐺(푦, 푧) ∨ 퐻(푓(푢), 푣, 푦))

∀푧 퐺(푤, 푧) ∨ 퐻(푓(푢), 푣, 푤)

∀푧 퐺(푤, 푧) 퐻(푓(푢), 푣, 푤)

퐺(푤, 푢1)

CS 245 Logic and Computation Fall 2019 28 / 30 A few notes on parse trees

1. While constructing the parse tree, when removing a quantifier, we change the bound variable symbol to one of the free variable symbols that hasn’t appeared in the parse tree. For example, When removing ∀푥, we changed 푥 to 푣. When removing ∃푦, we changed 푦 to 푤. 2. Th quantifiers have higher precedence than any other connective. Each quantifier modifies the formula that is immediately after it. For example, ∀푧 modifies 퐺(푤, 푧) instead of 퐺(푤, 푧) ∨ 퐻(푓(푢), 푣, 푤).

CS 245 Logic and Computation Fall 2019 29 / 30 Revisiting the learning goals

By the end of this lecture, you should be able to ▶ Define the set of terms inductively. ▶ Define the set of formulas inductively. ▶ Determine whether a variable in a formula is free or bound. ▶ Prove properties of terms and formulas by structural induction. ▶ Draw the parse tree of a formula.

CS 245 Logic and Computation Fall 2019 30 / 30