Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic....

51
Week 3 Tutorial Mathematical Logic

Transcript of Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic....

Page 1: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Week 3 TutorialMathematical Logic

Page 2: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Take-Home Exam Revision Resources

● Feedback for the frst round of Week 2 Take-Home Exam has been released – review on Gradescope ASAP

● Specifc by-problem resources linked on course website

● Videos on Canvas for Problems 2.i and 2.ii – under Course Videos where you fnd the lecture videos

● Ask for help in ofice hours or on the Q&A forum

● Special Take-Home Exam ofice hours Thursday 4/23 after PS2 deadline

● If you feel you would beneft from additional 1-on-1 support beyond these resources, please email the staf mailing list cs103-spr1920-stafflists.stanford.edu

Page 3: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Other Announcements● Updates to ofice hours – will be posted to

ofice hours page on course website once fnalized

● Please tag your pages on Gradescope

● CS103 Week 3 Pulse Check: https://forms.gle/FgDH2NzHWjParh9D6

Page 4: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Part 1: Logic Recap and Warmup

Page 5: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

yx

represents Loves(x, y) A

E

B D

F

C

Page 6: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

A

E

B D

F

CFormulas.Formulas.

Useful Resource:Useful Resource:

Go to cs103.stanford.edu and Go to cs103.stanford.edu and read the Guide to Negating read the Guide to Negating

1. Determine the minimum number of arrows that must be added to make the following statements true.

You can’t remove existing arrows. If a formula is already true, the answer will be “0”. Tell us what the arrows are and briefy explain why it’s the smallest number that need to be added.

a) Loves(A, A) → Loves(E, E) b) Loves(A, B) → Loves(C, D) c) Loves(A, C) → Loves(C, F) d) Loves(A, D) → Loves(D, E) e) Loves(A, D) ↔ Loves(B, C) f) Loves(A, C) ↔ Loves(E, C)

Fill in answer on Gradescope!

1. Determine the minimum number of arrows that must be added to make the following statements true.

You can’t remove existing arrows. If a formula is already true, the answer will be “0”. Tell us what the arrows are and briefy explain why it’s the smallest number that need to be added.

a) Loves(A, A) → Loves(E, E) b) Loves(A, B) → Loves(C, D) c) Loves(A, C) → Loves(C, F) d) Loves(A, D) → Loves(D, E) e) Loves(A, D) ↔ Loves(B, C) f) Loves(A, C) ↔ Loves(E, C)

Fill in answer on Gradescope!

Page 7: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

A

E

B D

F

CFormulas.Formulas.

Useful Resource:Useful Resource:

Go to cs103.stanford.edu and Go to cs103.stanford.edu and read the Guide to Negating read the Guide to Negating

2. Repeat the previous exercise with the following statements:

a) ∀x. ∃y. (Loves(x, y)) b) ∀x. ∃y. (x ≠ y ∧ Loves(x, y)) c) ∃x. ∀y. (Loves(x, y)) d) ∃x. ∀y. (x ≠ y → Loves(x, y))

Fill in answer on Gradescope!

2. Repeat the previous exercise with the following statements:

a) ∀x. ∃y. (Loves(x, y)) b) ∀x. ∃y. (x ≠ y ∧ Loves(x, y)) c) ∃x. ∀y. (Loves(x, y)) d) ∃x. ∀y. (x ≠ y → Loves(x, y))

Fill in answer on Gradescope!

Page 8: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Part 2: Negating Statements

Page 9: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

Page 10: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

¬∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

Page 11: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Formulas.

¬∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) Useful Resource:

Go to cs103.stanford.edu and read the Guide to Negating

Useful Resource:

Go to cs103.stanford.edu and read the Guide to Negating

Formulas.

Page 12: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

¬∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∀x. A

∃x. ¬A

Page 13: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

¬∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∀x. A

∃x. ¬A

Page 14: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

¬∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∀x. A

∃x. ¬A

Page 15: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. ¬(Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∀x. A

∃x. ¬A

Page 16: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. ¬(Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

Page 17: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. ¬(Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

Formulas.Formulas.

Useful Resource:Useful Resource:Go to cs103.stanford.edu and Go to cs103.stanford.edu and read the Guide to Negating read the Guide to Negating

3. Finish the negation of this frst-order logic formula. Your fnal formula should not have any negations in it except for direct negations of predicates.

Here is the formula so far in LaTeX:

$$\exists p. \neg (Person(p) \rightarrow \exists q. ((Person(q) \land p \neq q) \land Loves(p, q))$$

Fill in answer on Gradescope!

3. Finish the negation of this frst-order logic formula. Your fnal formula should not have any negations in it except for direct negations of predicates.

Here is the formula so far in LaTeX:

$$\exists p. \neg (Person(p) \rightarrow \exists q. ((Person(q) \land p \neq q) \land Loves(p, q))$$

Fill in answer on Gradescope!

Page 18: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. ¬(Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A → B)

A ∧ ¬B

Page 19: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. ¬(Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A → B)

A ∧ ¬B

Page 20: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. ¬(Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A → B)

A ∧ ¬B

Page 21: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧¬∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A → B)

A ∧ ¬B

Page 22: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ¬∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

Page 23: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ¬∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∃x. A

∀x. ¬A

Page 24: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ¬∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∃x. A

∀x. ¬A

Page 25: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ¬∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∃x. A

∀x. ¬A

Page 26: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ¬((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬∃x. A

∀x. ¬A

Page 27: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ¬((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

Page 28: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ¬((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A ∧ B)

A → ¬B

Page 29: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ¬((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A ∧ B)

A → ¬B

Page 30: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ¬((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

) ¬(A ∧ B)

A → ¬B

Page 31: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ((Person(q) ∧ p ≠ q) →

¬Loves(p, q))

) ¬(A ∧ B)

A → ¬B

Page 32: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∃p. (Person(p) ∧ ∀q. ((Person(q) ∧ p ≠ q) →

¬Loves(p, q))

)

Page 33: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

∀p. (Person(p) → ∃q. ((Person(q) ∧ p ≠ q) ∧

Loves(p, q))

)

∃p. (Person(p) ∧ ∀q. ((Person(q) ∧ p ≠ q) →

¬Loves(p, q))

)

Page 34: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Part 3: First-Order Logic Translations

Page 35: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Consider this statement:

“If someone is happy, then everyone is happy.”

What is the contrapositive of this statement?

Formulas.Formulas.Useful Resource:Useful Resource:Go to cs103.stanford.edu and Go to cs103.stanford.edu and read the Guide to Negating read the Guide to Negating

4. Find the contrapositive of the above statement. You may fnd it helpful to frst write out the original statement in frst order logic.

Fill in answer on Gradescope!

4. Find the contrapositive of the above statement. You may fnd it helpful to frst write out the original statement in frst order logic.

Fill in answer on Gradescope!

Page 36: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

If someone is happy, then everyone is happy

Page 37: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

someone is happy → everyone is happy

Page 38: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

someone is happy → (∀x. Happy(x))

Page 39: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

Page 40: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

Page 41: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

Page 42: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

¬(∀x. Happy(x)) → ¬(∃x. Happy(x))

Page 43: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. ¬Happy(x)) → ¬(∃x. Happy(x))

Page 44: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. ¬Happy(x)) → (∀x. ¬Happy(x))

Page 45: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. ¬Happy(x)) → (∀x. ¬Happy(x))

“If someone is not happy, then everyone is not happy.”

Page 46: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

Consider this statement:

“If someone is happy, then everyone is happy.”

What is the negation of this statement?

Formulas.Formulas.Useful Resource:Useful Resource:Go to cs103.stanford.edu and Go to cs103.stanford.edu and read the Guide to Negating read the Guide to Negating

5. Find the negation of the above statement. You may fnd it helpful to frst write out the original statement in frst order logic.

Fill in answer on Gradescope!

5. Find the negation of the above statement. You may fnd it helpful to frst write out the original statement in frst order logic.

Fill in answer on Gradescope!

Page 47: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

Page 48: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

¬((∃x. Happy(x)) → (∀x. Happy(x)))

Page 49: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

(∃x. Happy(x)) ∧ ¬(∀x. Happy(x))

Page 50: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

(∃x. Happy(x)) ∧ (∃x. ¬Happy(x))

Page 51: Week 3 Tutorial - Stanford University 3.pdf · 2020-04-22 · Week 3 Tutorial Mathematical Logic. Take-Home Exam Revision Resources Feedback for the frst round of Week 2 Take-Home

(∃x. Happy(x)) → (∀x. Happy(x))

(∃x. Happy(x)) ∧ (∃x. ¬Happy(x))

“Someone is happy and someone is not happy.”