Predicate Logic: Introduction and Translations Alice Gao Lecture - - PowerPoint PPT Presentation

predicate logic introduction and translations
SMART_READER_LITE
LIVE PREVIEW

Predicate Logic: Introduction and Translations Alice Gao Lecture - - PowerPoint PPT Presentation

Predicate Logic: Introduction and Translations Alice Gao Lecture 11 CS 245 Logic and Computation Fall 2019 1 / 37 Outline Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate


slide-1
SLIDE 1

Predicate Logic: Introduction and Translations

Alice Gao

Lecture 11

CS 245 Logic and Computation Fall 2019 1 / 37

slide-2
SLIDE 2

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Interpreting the Quantifjers Why do we need functions? A Summary of Translation Idioms At least, at most, and exactly Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 2 / 37

slide-3
SLIDE 3

Learning goals

By the end of this lecture, you should be able to (Introduction to Predicate Logic)

▶ Give examples of English sentences that can be modeled using

predicate logic but cannot be modeled using propositional logic. (Translations)

▶ Translate an English sentence into a predicate formula. ▶ Translate a predicate formula into an English sentence.

CS 245 Logic and Computation Fall 2019 3 / 37

slide-4
SLIDE 4

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 4 / 37

slide-5
SLIDE 5

Translate the following argument into propositional logic

Consider the argument below.

  • 1. Every human is mortal.
  • 2. Socrates is a human.

From these two sentences, one should be able to conclude that

  • 3. Socrates is mortal.

In propositional logic, how would you express this argument?

CS 245 Logic and Computation Fall 2019 5 / 37

slide-6
SLIDE 6

What can we NOT express in propositional logic?

A few things that are diffjcult to express using propositional logic:

▶ Relationships among individuals:

“Alice is a friend of Bob and Alice is not a friend of Cate.“

▶ Generalizing patterns:

“Every bear likes honey.“

▶ Infjnite domains:

“Defjne what it means for a natural number to be prime.“ We can use predicate logic (fjrst-order logic) to express all of these.

CS 245 Logic and Computation Fall 2019 6 / 37

slide-7
SLIDE 7

Would you really use predicate logic?

Examples of predicate logic in CS245 so far:

  • 1. Every well-formed formula has an equal number of left and

right brackets.

  • 2. If there does not exist a formal deduction proof from the

premises to the conclusion, then the premises do not logically imply the conclusion.

  • 3. There exists a truth valuation 𝑢 such that

for every 𝐵 ∈ Σ, 𝐵𝑢 = 1.

CS 245 Logic and Computation Fall 2019 7 / 37

slide-8
SLIDE 8

Would you really use predicate logic?

Examples of predicate logic in Computer Science:

  • 1. Data structure: Every key stored in the left subtree of a node

𝑂 is smaller than the key stored at 𝑂.

  • 2. Algorithms: In the worst case, every comparison sort requires

at least 𝑑𝑜 log 𝑜 comparisons to sort 𝑜 values, for some constant 𝑑 > 0.

  • 3. Java example: There is no path via references from any

variable in scope to any memory location available for garbage collection...

  • 4. Database query: Select a person whose age is greater than or

equal to the age of every other person in the table.

CS 245 Logic and Computation Fall 2019 8 / 37

slide-9
SLIDE 9

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 9 / 37

slide-10
SLIDE 10

Elements of predicate logic

Predicate logic generalizes propositional logic. New things in predicate logic:

▶ Domains ▶ Relations ▶ Quantifjers

CS 245 Logic and Computation Fall 2019 10 / 37

slide-11
SLIDE 11

Domains

A domain is

▶ a non-empty set of objects/individuals. ▶ a world that our statement is situated within.

Examples: natural numbers, people, animals, etc. Why is it important to specify a domain?

▶ A statement can have difgerent truth values in difgerent

domains.

▶ There exists a number whose square is 2.

Is this sentence true when the domain is ℕ? ℝ?

CS 245 Logic and Computation Fall 2019 11 / 37

slide-12
SLIDE 12

Objects in a domain

Individuals: concrete objects in the domain

▶ Natural numbers: 0, 6, 100, ... ▶ Alice, Bob, Eve, ... ▶ Animals: Winnie the Pooh, Micky Mouse, Simba, ...

Variables: placeholders for concrete objects.

▶ e.g. 𝑣, 𝑤, 𝑥, 𝑦, 𝑧, 𝑨. ▶ refers to an object without specifying a particular object.

CS 245 Logic and Computation Fall 2019 12 / 37

slide-13
SLIDE 13

Relations

A relation represents

▶ a property of an individual, or ▶ a relationship among multiple individuals. ▶ a n-ary function which takes constants and/or variables as

inputs and outputs 1/0 Examples:

▶ Defjne 𝑇(𝑦) to mean “𝑦 is a student”. (unary predicate)

▶ Bob is a student: 𝑇(𝐶𝑝𝑐) ▶ Micky Mouse is not a student: (¬𝑇(Micky Mouse)) ▶ 𝑣 is a student: 𝑇(𝑣)

▶ Defjne 𝑍 (𝑦, 𝑧) to mean “𝑦 is younger than 𝑧”. (binary

predicate)

▶ Alex is younger than Sam: 𝑍 (Alex, Sam) ▶ 𝑣 is younger than 𝑤: 𝑍 (𝑣, 𝑤) CS 245 Logic and Computation Fall 2019 13 / 37

slide-14
SLIDE 14

Quantifjers

For how many objects in the domain is the statement true?

▶ The universal quantifjer ∀:

the statement is true for every object in the domain.

▶ The existential quantifjer ∃:

the statement is true for one or more objects in the domain.

CS 245 Logic and Computation Fall 2019 14 / 37

slide-15
SLIDE 15

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Interpreting the Quantifjers Why do we need functions? A Summary of Translation Idioms At least, at most, and exactly Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 15 / 37

slide-16
SLIDE 16

CQ Translating English into Predicate Logic

Let the domain be the set of animals. 𝐼(𝑦) means that 𝑦 likes honey. 𝐶(𝑦) means that 𝑦 is a bear. Are the following translations correct?

  • 1. At least one animal likes honey. (∃𝑦 𝐼(𝑦)).
  • 2. Not every animal likes honey. (¬(∀𝑦 𝐼(𝑦))).

(A) Both are correct. (B) 1 is correct and 2 is wrong. (C) 1 is wrong and 2 is correct. (D) Both are wrong.

CS 245 Logic and Computation Fall 2019 16 / 37

slide-17
SLIDE 17

Translating English into Predicate Logic

Let the domain be the set of animals. 𝐼(𝑦) means that 𝑦 likes honey. 𝐶(𝑦) means that 𝑦 is a bear. Translate the following sentences into predicate logic.

  • 1. All animals like honey.
  • 2. At least one animal likes honey.
  • 3. Not every animal likes honey.
  • 4. No animal likes honey.

CS 245 Logic and Computation Fall 2019 17 / 37

slide-18
SLIDE 18

Translating English into Predicate Logic

Let the domain be the set of animals. 𝐼(𝑦) means that 𝑦 likes honey. 𝐶(𝑦) means that 𝑦 is a bear. Translate the following sentences into predicate logic.

  • 5. No animal dislikes honey.
  • 6. Not every animal dislikes honey.
  • 7. Some animal dislikes honey.
  • 8. Every animal dislikes honey.

CS 245 Logic and Computation Fall 2019 18 / 37

slide-19
SLIDE 19

CQ Translating English into Predicate Logic

Consider this sentence: Every bear likes honey. Which one is the correct translation into predicate logic? (A) ∀𝑦 (𝐶(𝑦) ∧ 𝐼(𝑦)) (B) ∀𝑦 (𝐶(𝑦) ∨ 𝐼(𝑦)) (C) ∀𝑦 (𝐶(𝑦) → 𝐼(𝑦)) (D) ∀𝑦 (𝐼(𝑦) → 𝐶(𝑦)) Let the domain be the set of animals. 𝐼(𝑦) means that 𝑦 likes

  • honey. 𝐶(𝑦) means that 𝑦 is a bear.

CS 245 Logic and Computation Fall 2019 19 / 37

slide-20
SLIDE 20

CQ Translating English into Predicate Logic

Consider this sentence: Some bear likes honey. (At least one bear likes honey.) Which one is the correct translation into predicate logic? (A) ∃𝑦 (𝐶(𝑦) ∧ 𝐼(𝑦)) (B) ∃𝑦 (𝐶(𝑦) ∨ 𝐼(𝑦)) (C) ∃𝑦 (𝐶(𝑦) → 𝐼(𝑦)) (D) ∃𝑦 (𝐼(𝑦) → 𝐶(𝑦)) Let the domain be the set of animals. 𝐼(𝑦) means that 𝑦 likes

  • honey. 𝐶(𝑦) means that 𝑦 is a bear.

CS 245 Logic and Computation Fall 2019 20 / 37

slide-21
SLIDE 21

Multiple Quantifjers

Let the domain be the set of people. Let 𝑀(𝑦, 𝑧) mean that person 𝑦 likes person 𝑧. Translate the following formulas into English.

  • 1. ∀𝑦 (∀𝑧 𝑀(𝑦, 𝑧))
  • 2. ∃𝑦 (∃𝑧 𝑀(𝑦, 𝑧))
  • 3. ∀𝑦 (∃𝑧 𝑀(𝑦, 𝑧))
  • 4. ∃𝑧 (∀𝑦 𝑀(𝑦, 𝑧))

CS 245 Logic and Computation Fall 2019 21 / 37

slide-22
SLIDE 22

CQ Translations

Translate the sentence “every student has taken some course.” into a predicate formula. Let 𝑦 refer to a student and let 𝑧 refer to a course. What quantifjers should we use for 𝑦 and 𝑧? (A) ∀𝑦 and ∀𝑧 (B) ∀𝑦 and ∃𝑧 (C) ∃𝑦 and ∀𝑧 (D) ∃𝑦 and ∃𝑧 Let the domain contain the set of all students and courses. Defjne the following predicates: 𝑇(𝑦): 𝑦 is a student. 𝐷(𝑧): 𝑧 is a course. 𝑈(𝑦, 𝑧): student 𝑦 has taken course 𝑧.

CS 245 Logic and Computation Fall 2019 22 / 37

slide-23
SLIDE 23

CQ Translations

Translate the sentence “every student has taken some course.” into a predicate formula. Which of the following is a correct translation? (A) ∀𝑦 (𝑇(𝑦) → (∃𝑧 𝐷(𝑧) → 𝑈(𝑦, 𝑧))) (B) ∀𝑦 (𝑇(𝑦) → (∃𝑧 𝐷(𝑧) ∧ 𝑈(𝑦, 𝑧))) (C) ∀𝑦 (𝑇(𝑦) ∧ (∃𝑧 𝐷(𝑧) → 𝑈(𝑦, 𝑧))) (D) ∀𝑦 (𝑇(𝑦) ∧ (∃𝑧 𝐷(𝑧) ∧ 𝑈(𝑦, 𝑧))) Let the domain contain the set of all students and courses. Defjne the following predicates: 𝑇(𝑦): 𝑦 is a student. 𝐷(𝑧): 𝑧 is a course. 𝑈(𝑦, 𝑧): student 𝑦 has taken course 𝑧.

CS 245 Logic and Computation Fall 2019 23 / 37

slide-24
SLIDE 24

CQ Translations

Translate the sentence “some student has not taken any course.” into a predicate formula. Let 𝑦 refer to a student and let 𝑧 refer to a course. What quantifjers should we use for 𝑦 and 𝑧? (A) ∀𝑦 and ∀𝑧 (B) ∀𝑦 and ∃𝑧 (C) ∃𝑦 and ∀𝑧 (D) ∃𝑦 and ∃𝑧 Let the domain contain the set of all students and courses. Defjne the following predicates: 𝑇(𝑦): 𝑦 is a student. 𝐷(𝑧): 𝑧 is a course. 𝑈(𝑦, 𝑧): student 𝑦 has taken course 𝑧.

CS 245 Logic and Computation Fall 2019 24 / 37

slide-25
SLIDE 25

CQ Translations

Translate the sentence “some student has not taken any course.” into a predicate formula. Which of the following is a correct translation? (A) ∃𝑦 (𝑇(𝑦) → (∀𝑧 𝐷(𝑧) → ¬𝑈(𝑦, 𝑧))) (B) ∃𝑦 (𝑇(𝑦) → (∀𝑧 𝐷(𝑧) ∧ (¬𝑈(𝑦, 𝑧))) (C) ∃𝑦 (𝑇(𝑦) ∧ (∀𝑧 𝐷(𝑧) → ¬𝑈(𝑦, 𝑧))) (D) ∃𝑦 (𝑇(𝑦) ∧ (∀𝑧 𝐷(𝑧) ∧ ¬𝑈(𝑦, 𝑧))) Let the domain contain the set of all students and courses. Defjne the following predicates: 𝑇(𝑦): 𝑦 is a student. 𝐷(𝑧): 𝑧 is a course. 𝑈(𝑦, 𝑧): student 𝑦 has taken course 𝑧.

CS 245 Logic and Computation Fall 2019 25 / 37

slide-26
SLIDE 26

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Interpreting the Quantifjers Why do we need functions? A Summary of Translation Idioms At least, at most, and exactly Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 26 / 37

slide-27
SLIDE 27

CQ Interpreting the quantifjers

Let the domain be {𝐵𝑚𝑗𝑑𝑓, 𝐶𝑝𝑐, 𝐹𝑤𝑓}. Let 𝐷(𝑦) mean that person 𝑦 likes chocolates. Which of the following is equivalent to ∀𝑦 𝐷(𝑦)? (A) ((𝐷(𝐵𝑚𝑗𝑑𝑓) ∧ 𝐷(𝐶𝑝𝑐)) ∧ 𝐷(𝐹𝑤𝑓)) (B) ((𝐷(𝐵𝑚𝑗𝑑𝑓) ∨ 𝐷(𝐶𝑝𝑐)) ∨ 𝐷(𝐹𝑤𝑓)) (C) ((𝐷(𝐵𝑚𝑗𝑑𝑓) → 𝐷(𝐶𝑝𝑐)) → 𝐷(𝐹𝑤𝑓)) (D) ((𝐷(𝐵𝑚𝑗𝑑𝑓) ↔ 𝐷(𝐶𝑝𝑐)) ↔ 𝐷(𝐹𝑤𝑓)) (E) None of the above

CS 245 Logic and Computation Fall 2019 27 / 37

slide-28
SLIDE 28

CQ Interpreting the quantifjers

Let the domain be {𝐵𝑚𝑗𝑑𝑓, 𝐶𝑝𝑐, 𝐹𝑤𝑓}. Let 𝐷(𝑦) mean that person 𝑦 likes chocolates. Which of the following is equivalent to ∃𝑦 𝐷(𝑦)? (A) ((𝐷(𝐵𝑚𝑗𝑑𝑓) ∧ 𝐷(𝐶𝑝𝑐)) ∧ 𝐷(𝐹𝑤𝑓)) (B) ((𝐷(𝐵𝑚𝑗𝑑𝑓) ∨ 𝐷(𝐶𝑝𝑐)) ∨ 𝐷(𝐹𝑤𝑓)) (C) ((𝐷(𝐵𝑚𝑗𝑑𝑓) → 𝐷(𝐶𝑝𝑐)) → 𝐷(𝐹𝑤𝑓)) (D) ((𝐷(𝐵𝑚𝑗𝑑𝑓) ↔ 𝐷(𝐶𝑝𝑐)) ↔ 𝐷(𝐹𝑤𝑓)) (E) None of the above

CS 245 Logic and Computation Fall 2019 28 / 37

slide-29
SLIDE 29

Interpreting the quantifjers

Let 𝐸 = {𝑒1, 𝑒2, ..., 𝑒𝑜}. ∀ is a big AND: ∀𝑦 𝑄(𝑦) is equivalent to ...(𝑄(𝑒1) ∧ 𝑄(𝑒2)) ∧ ... ∧ 𝑄(𝑒𝑜). ∃ is a big OR: ∃𝑦 𝑄(𝑦) is equivalent to ...(𝑄(𝑒1) ∨ 𝑄(𝑒2)) ∨ ... ∨ 𝑄(𝑒𝑜).

CS 245 Logic and Computation Fall 2019 29 / 37

slide-30
SLIDE 30

Negating a quantifjed formula

“Generalized De Morgan’s Laws”

▶ ¬(∀𝑦 𝑄(𝑦)) ⊨

⊨ ∃𝑦 (¬𝑄(𝑦))

▶ ¬(∃𝑦 𝑄(𝑦)) ⊨

⊨ ∀𝑦 (¬𝑄(𝑦))

CS 245 Logic and Computation Fall 2019 30 / 37

slide-31
SLIDE 31

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Interpreting the Quantifjers Why do we need functions? A Summary of Translation Idioms At least, at most, and exactly Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 31 / 37

slide-32
SLIDE 32

Why do we need functions?

Translate the sentence. “every child is younger than their mother.”

  • 1. The domain is the set of people.

𝐷ℎ𝑗𝑚𝑒(𝑦) means 𝑦 is a child. 𝐽𝑡𝑁𝑝𝑢ℎ𝑓𝑠(𝑦, 𝑧) means 𝑦 is 𝑧’s mother. 𝐽𝑡𝑍 𝑝𝑣𝑜𝑕𝑓𝑠(𝑦, 𝑧) means 𝑦 is younger than 𝑧.

  • 2. Use the same set of defjnitions above

and the function 𝑛𝑝𝑢ℎ𝑓𝑠(𝑦) which returns 𝑦’s mother.

CS 245 Logic and Computation Fall 2019 32 / 37

slide-33
SLIDE 33

Why do we need functions?

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

CS 245 Logic and Computation Fall 2019 33 / 37

slide-34
SLIDE 34

A Summary of Translation Idioms

▶ Every/All/Each/Any

∀𝑦

▶ Some/At least one/There exists a/There is a

∃𝑦

▶ None/No x

¬(∃𝑦 … )

▶ Not every/Not all

¬(∀𝑦 … )

▶ Every P-ish x has property Q

∀𝑦 𝑄(𝑦) → 𝑅(𝑦)

▶ Some P-ish x has property Q

∃𝑦 𝑄(𝑦) ∧ 𝑅(𝑦)

CS 245 Logic and Computation Fall 2019 34 / 37

slide-35
SLIDE 35

Outline

Learning goals Introduction and Motivation Elements of Predicate Logic Translating between English and Predicate Logic Interpreting the Quantifjers Why do we need functions? A Summary of Translation Idioms At least, at most, and exactly Revisiting the learning goals

CS 245 Logic and Computation Fall 2019 35 / 37

slide-36
SLIDE 36

At least, at most, and exactly

Let the domain be the set of animals. Let 𝐶(𝑦) be that 𝑦 is a bear.

  • 1. There are at least two bears.
  • 2. There are at most one bear.
  • 3. There are exactly one bear.

CS 245 Logic and Computation Fall 2019 36 / 37

slide-37
SLIDE 37

Revisiting the learning goals

By the end of this lecture, you should be able to (Introduction to Predicate Logic)

▶ Give examples of English sentences that can be modeled using

predicate logic but cannot be modeled using propositional logic. (Translations)

▶ Translate an English sentence into a predicate formula. ▶ Translate a predicate formula into an English sentence.

CS 245 Logic and Computation Fall 2019 37 / 37