Upload
buinguyet
View
224
Download
3
Embed Size (px)
Citation preview
Logic in Problem Solving
Lecture 1: Foundations
Dr. Troy VasigaDavid R. Cheriton School of Computer Science
University of Waterloo
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Outline
• Short Biography of the Speaker
• MathCircles Ground Rules
• Upcoming Lectures
• Overview
• Logic Basics
• Sets
• Properties of Sets
• Solving Logic Problems
• Some problems
• Exercises
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Short biography of the speaker
• Academic background:• B.Math (Computer Science and Combinatorics and
Optimization, Double Degree), UW, 19• M.Math (Combinatorics and Optimization) [thesis topic:
“α-resolvable designs of block size 4”], UW, 19• B.Ed, UBC, 19• Ph.D (Computer Science) “Error detection and correction in
number-theoretic algorithms”, UW, 20
• Current Position:• Lecturer, David R. Cheriton School of Computer Science• Associate Director, Centre for Education in Mathematics and
Computing
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Short biography of the speaker
• Academic life• teach (mostly) first- and second-year CS courses (CS 115, 116,
135, 241)• coordinate the Canadian Computing Competition (organize
problem creation, publication of results, communication withteachers, select Canadian Computing Olympiad invitees, trainand supervise the Canadian IOI team)
• do lots of school visits (elementary and secondary schools inOntario, Malaysia, Singapore, China, Hong Kong)
• reviewer and grader for other math competitions (Euclid,CIMC/CSMC)
• sit on or chair various CS committees (UndergraduateRecruiting, Outreach, Scholarship committees)
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Short biography of the speaker
• Non-academic life• bicycle to work every day (yes, every day)• enjoy working out at the gym regularly• enjoy travel (through work and outside of work)• love playing Uno, Sleeping Queens, and Clue and reading with
daughter Natalie• love dinner and movies with lovely wife Krista• enjoy hanging out with neighbourhood friends
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
MathCircles Ground Rules• Be polite.
• listen while presenters are talking• ask questions in a polite manner
• Be punctual.• your instructor will be here from 6:30-8:30• so should you• some material will build on previous material: try to come
weekly• Be engaged.
• listen while presenters are talking• don’t check your phone• don’t do your other homework• work on the problems/exercises given to you• there is a waiting list of many interested students who would
like to be here: you should like to be here
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Upcoming Lectures
• Oct 18, Oct 25: Troy Vasiga, Logic
• Nov 1, 8, 15: Carmen Bruni, History of Math and NumberTheory
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Overview of Lecture
The goal of the next three lectures is to:
• develop some fundamentals about logic
• discuss how to solve logical word problems
• discuss how to solve logical set problems
• discuss how to solve logical mathematical problems
• discuss logical mathematical games
• discuss first and second order logic
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic Puzzles
In this lecture, we will study various forms of logic puzzles.
Of course, these rely on logic.
They also open up very interesting areas of mathematics,linguistics, information theory, computer science, game theory, settheory.
This topic is very deep and very broad.
Let’s begin with some basics.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic Basics
A mathematical statement is either true or false.
It can never be both true and false.
It can never be both not true and not false.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic Basics: TangentNo.
The previous slide is false.
Godel proved that axiomatic number theory (which is the basis ofmost math that you do, involving numbers) is either:
• incomplete: there are statements which are neither true norfalse;
• inconsistent: there are statements which are both true andfalse.
This is known as Godel’s Incompleteness Theorem: see CS 466.
Let’s just ignore that for now.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic Basics: TangentNo.
The previous slide is false.
Godel proved that axiomatic number theory (which is the basis ofmost math that you do, involving numbers) is either:
• incomplete: there are statements which are neither true norfalse;
• inconsistent: there are statements which are both true andfalse.
This is known as Godel’s Incompleteness Theorem: see CS 466.
Let’s just ignore that for now.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic Basics: TangentNo.
The previous slide is false.
Godel proved that axiomatic number theory (which is the basis ofmost math that you do, involving numbers) is either:
• incomplete: there are statements which are neither true norfalse;
• inconsistent: there are statements which are both true andfalse.
This is known as Godel’s Incompleteness Theorem: see CS 466.
Let’s just ignore that for now.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic: More Basics
If it is the case that if A is true, then B must be true, and if it isthe case that A is actually true, then we know that B is true.
We can write this as A⇒ B.
Often, these implications can be chained (so that A⇒ B ⇒ C andso on).
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic: More Basics
Of course, we can use the contrapositive form sometimes.
That is, if A⇒ B, then it is also the case that ¬B ⇒ ¬A.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Logic: Yet More Basics
Additionally, if we have A⇒ B and B ⇒ A, then we know that thisis an “if and only if”: meaning A is true if and only if B is true.
We sometimes write this as A⇔ B.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Sets
• a set is a collection of objects
• these objects can be anything
• Examples:• {a, b, c}• {troy, michael, john}• {α, {ℵ}, Z}
• a set can be empty: denoted as {} or ∅• a set can be infinite
• N = {0, 1, 2, . . .}• Z = {. . . ,−2,−1, 0, 1, 2, . . .}
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Subsets
We say that a set A is a subset of B if:
every element of A is alsoin B.
To state this more formally, if x ∈ A, then it follows that x ∈ B.
We denote this as A ⊆ B.
What if A ⊆ B and B ⊆ A?
Then, A = B.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Subsets
We say that a set A is a subset of B if: every element of A is alsoin B.
To state this more formally, if x ∈ A, then it follows that x ∈ B.
We denote this as A ⊆ B.
What if A ⊆ B and B ⊆ A?
Then, A = B.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Subsets
We say that a set A is a subset of B if: every element of A is alsoin B.
To state this more formally, if x ∈ A, then it follows that x ∈ B.
We denote this as A ⊆ B.
What if A ⊆ B and B ⊆ A?
Then, A = B.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Subsets
We say that a set A is a subset of B if: every element of A is alsoin B.
To state this more formally, if x ∈ A, then it follows that x ∈ B.
We denote this as A ⊆ B.
What if A ⊆ B and B ⊆ A?
Then, A = B.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Subsets
We say that a set A is a subset of B if: every element of A is alsoin B.
To state this more formally, if x ∈ A, then it follows that x ∈ B.
We denote this as A ⊆ B.
What if A ⊆ B and B ⊆ A?
Then, A = B.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Set Operations
1. Union: A ∪ B = {x : x ∈ A or x ∈ B}
2. Intersection: A ∩ B = {x : x ∈ A and x ∈ B}
3. Difference: A− B = {x : x ∈ A and x 6∈ B}
4. Complement: A = {x : x 6∈ A}
5. Cartesian Product: A× B = {(x , y) : x ∈ A and y ∈ B}
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Set ExamplesSuppose A = {a, b, c} and B = {a, c , d , t}.What are:
• A ∪ B:
• A ∩ B:
• A− B:
• B − A:
• A× B:
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A
• Commutativity:
A ∪ B = B ∪ A and A ∩ B = B ∩ A
• Associativity:
(A ∪ B) ∪ C = A ∪ (B ∪ C )
(A ∩ B) ∩ C = A ∩ (B ∩ C )
• DeMorgan’s Laws:
A− (B ∪ C ) = (A− B) ∩ (A− C )
A− (B ∩ C ) = (A− B) ∪ (A− C )
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A
• Commutativity:
A ∪ B = B ∪ A and A ∩ B = B ∩ A
• Associativity:
(A ∪ B) ∪ C = A ∪ (B ∪ C )
(A ∩ B) ∩ C = A ∩ (B ∩ C )
• DeMorgan’s Laws:
A− (B ∪ C ) = (A− B) ∩ (A− C )
A− (B ∩ C ) = (A− B) ∪ (A− C )
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A
• Commutativity:
A ∪ B = B ∪ A and A ∩ B = B ∩ A
• Associativity:
(A ∪ B) ∪ C = A ∪ (B ∪ C )
(A ∩ B) ∩ C = A ∩ (B ∩ C )
• DeMorgan’s Laws:
A− (B ∪ C ) = (A− B) ∩ (A− C )
A− (B ∩ C ) = (A− B) ∪ (A− C )
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A
• Commutativity:
A ∪ B = B ∪ A and A ∩ B = B ∩ A
• Associativity:
(A ∪ B) ∪ C = A ∪ (B ∪ C )
(A ∩ B) ∩ C = A ∩ (B ∩ C )
• DeMorgan’s Laws:
A− (B ∪ C ) = (A− B) ∩ (A− C )
A− (B ∩ C ) = (A− B) ∪ (A− C )
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Venn Diagram
In almost every problem you will ever solve, it is a good idea todraw a picture.
For sets, we often draw a Venn Diagram, which helps us visualizewhere elements of sets are located.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Some Humorous Examples
c©Tenso Graphics
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Some Humorous Examples
c©tdylf.comWWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Some Humorous Examples
c©Phil Plait, Discover Magazine, April 13, 2012
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Proof of DeMorgan’s Law
Let’s prove: A− (B ∪ C ) = (A− B) ∩ (A− C )
A picture first...
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Proof of DeMorgan’s Law
Let’s prove: A− (B ∪ C ) = (A− B) ∩ (A− C )
A formal proof second...
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Simple set problem
In a group of 60 people, 27 like cold drinks and 42 like hot drinksand each person likes at least one of the two drinks. How manylike both coffee and tea?
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Detective work
“How often have I said to you that when you have eliminated theimpossible, whatever remains, however improbable, must be thetruth?” – Sir Arthur Conan Doyle, The Sign of the Four
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Mechanics of solving logic problems
• Recording data thoroughly: write down each fact youdiscover. Even the smallest things may help later on.
• Write down your information in an orderly manner. Draw apicture or a table or grid(s) to capture relationships andknown quantities.
• Carefully consider cases. Once the list of possibilities is smallenough, tackle them one at a time, until you have either ruledthem out or have found the solution.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
A first word problem: Movies
Ali, Bill, Cleo, Dale and Elmer are all in the same house.
1. If Ali is watching a movie, then so is Bill.
2. Either Dale or Elmer, or both of them are watching a movie.
3. Either Bill or Cleo, but not both are watching a movie.
4. Dale and Cleo are either both watching or both not watchinga movie.
5. If Elmer is watching a movie, then Ali and Dale are alsowatching a movie.
Who is watching a movie and who is not?
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Solution to the “Movie” Problem
Case 1:
Case 2:
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Word Logic: Hockey Player
Albert, his sister Betty, his son Colin and his daughter Daisy allplay hockey.We know:
1. The best player’s twin and the worst player are of the oppositesex.
2. The best player and the worst player are the same age.
Who is the best player?
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Solution to the “Hockey” Problem
Let’s look at ages.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
A cute, deadly logic puzzle
You are trapped in a room with two doors. One leads to certaindeath and the other leads to freedom. You don’t know which iswhich.There are two robots guarding the doors. They will let you chooseone door but upon doing so you must go through it.You can, however, ask one robot one question. The problem is onerobot always tells the truth ,the other always lies and you don’tknow which is which.What is the question you ask? Which door would you go throughbased on the answer?
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
Robot Logic Solution
Question:
Door to go through:
Reason why that will work:Case 1:
Case 2:
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
The Math Test
Six students, A, B, C, D, E, F wrote a math test.
1. A and B received the same marks.
2. A got a higher mark than C.
3. D was lower than C.
4. E was lower than A but higher than D.
5. E was lower than C.
6. B was lower than F.
Rank the students from highest score to lowest score, explainingyour reasoning.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
A problem
Many of the “classic” logic problems involve words, scenarios orfacts that are very culturally, geographically specific.
For example, the concepts of “cousin”, “spouse”, “work”, etc.,may not translate to all possible languages with the same meaning.
Moreover, lots of people get murdered in logic problems.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
A problem
Many of the “classic” logic problems involve words, scenarios orfacts that are very culturally, geographically specific.
For example, the concepts of “cousin”, “spouse”, “work”, etc.,may not translate to all possible languages with the same meaning.
Moreover, lots of people get murdered in logic problems.
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING
A solution
To avoid all language issues, find a universal language:
WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING