Predicate Logic (continued);!and on to Induction"
CSCI 2824, Fall 2014"http://l3d.cs.colorado.edu/~ctg/
classes/struct14/Home.html "
Mastermind Challenge Problem ���(due 9/12)
Colors: Blue, Orange, Red, Yellow, Purple, White Repeat colors in the code are allowed. Clues: “x” = “a peg in the right position” “o” = “a peg that has to be moved to be in the right position” W O B R ! ! !xo !P Y R B ! ! !xo!R R O Y ! ! !ooo!Y R R W ! ! !xx!
Assignments • To read by the end of this week: Sections 2.1-2.3
(Emsley/Crawley) • Problem Set 1 will be sent out by tomorrow
morning. "!!!!
Predicate Logic as a Representation for Statements to
Prove FOR-ALL(n)[ Prime(n) à THERE-EXISTS(q) [Greater-than(q, n) AND Prime(q)]]
Quantifiers and Dean Martin Everybody loves somebody sometime. FOR-ALL(x)[Person(x) --> THERE-EXISTS(y, t) [Person(y) and Time(t) and Loves-at-time(x,y,t)]] THERE-EXISTS(t,y)[Time(t) AND Person(y) AND FOR-ALL(x)[Person(x) --> Loves-at-time(x,y, t)]]
THERE-EXISTS(t)[Time(t) AND FOR-ALL(x) [Person(x) --> THERE-EXISTS(y) [Person(y) AND Loves-at-time(x,y,t)]} THERE-EXISTS(y)[Person(y) AND FOR-ALL(x) [Person (x) --> THERE-EXISTS(t)[Time(t) AND Loves-at-time(x, y, t)]]
Mastermind in Predicate Logic…
We’ll use the world of objects: {1, 2, 3, 4, Red, Blue, Purple, White, Yellow,
Orange} And we’ll start with the following “type predicates”
Number and Color: Number(1), Number(2), Number(3), Number(4) Color(Red), Color(Blue), etc. FOR-ALL(obj)[Color(obj) XOR Number(obj)]
Now we can introduce the In-Position predicate:
In-position(2, Blue) represents the statement: “Blue is in position 2” FOR-ALL(p, c1) [In-position(p, c) à Number(p) AND Color(c) ]
Our basic Mastermind constraint:
THERE-EXISTS(c) [In-position(1, c)] THERE-EXISTS(c) [In-position(2, c)] etc. FOR-ALL (p, c1, c2) [(In-position (p, c1) AND In-position (p, c2)) à c1 = c2]
A program might work like this:
Guess: Blue, Orange, Red, Yellow Response: X0
This part could look like our propositional logic system:
X means: In-position(1, Blue) OR In-position(2, Orange) OR In-
position(3, Red) OR In-position(4 Yellow) NOT ((In-position 1, Blue) AND (In-position(2, Orange)) NOT ((In-position 1, Blue) AND (In-position(3, Red)) Etc.
A slightly more compact version of that latter set of statements:
X means: FOR-ALL(p,c) [ (In-position(1, Blue) AND In-position(p,c)) à
NOT (p = 2 AND c = Orange) AND NOT (p = 3 AND c = Red) AND NOT (p = 4 AND c = Yellow) ]
Predicate Logic Axioms for Arithmetic (the Peano Axioms)
Number(0) FOR-ALL(n)[Number(n) à Number(Successor(n))] NOT (THERE-EXISTS(n) [0 = Successor(n)]) FOR-ALL(m, n) [(Successor(m) = Successor(n)) à (m = n)]
The Induction Axiom (where k and n are whole numbers)
FOR-ALL (Pred) [(Pred(0) AND (FOR-ALL (k) [Pred(k) à Pred(k+1)]) à FOR-ALL(n) [Pred(n)] ]
Induction: Let’s Start with an Example
We note a pattern: 1 = 1 1 + 3 = 4 1 + 3 + 5 = 9 1 + 3 + 5 + 7 = 16 This suggests a rule to us: 1 + 3 + … (2n-1) = n2
Can we show: ���1 + 3 + … (2n-1) = n2
Here’s the idea: we first show that the statement is true when n = 1:
1 = 1 Okay, that was easy…
Now we say the following: Suppose we have shown that our rule is true
up to a certain value of n (we’ll call that value k):
1 + … 2k-1 = k2 If that’s true, we can show the same statement
for k+1: 1 + … 2k-1 + (2(k+1) – 1) = (k+1)2
Now we say the following: Suppose we have shown that our rule is true
up to a certain value of n (we’ll call that value k):
1 + … 2k-1 = k2 If that’s true, we can show the same statement
for k+1: 1 + … 2k-1 + (2(k+1) – 1) = (k+1)2 1 + … 2k-1 + (2(k+1) – 1) = (k+1)2 k2 + (2(k+1) – 1) = k2 + 2k + 1 = (k+ 1)2
Here’s our reasoning:
Our statement is true for n = 1. So in that case, it must be true for n = 2. And in that case, it must be true for n = 3. And in that case, it must be true for n = 4. And so on, forever and ever!...
Another classic example:
1 + 2 + 3 + … n = n (n + 1)/ 2
Induction as a way of creating a series:
F(0) = 0 F(1) = 1 F(n) = F(n-1) + F(n-2)
A Fibonacci pattern…
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,… 1 = 1 1 + 2 = 3 1 + 2 + 5= 8 1 + 2 + 5 + 13 = 21
Hmm. Maybe?...
F(1) + F(3) + … F(2n-1) = F(2n) We know it’s true for n = 1. F(1) = F(2) = 1
Inductive Step:
For all values up to j, we know this: F(1) + … F(2j -1 ) = F(2j) So let’s show: F(1) + … F(2j – 1) + F(2j + 1) = F(2(j+1))
Inductive Step:
For all values up to j, we know this: F(1) + … F(2j -1 ) = F(2j) So let’s show: F(1) + … F(2j – 1) + F(2j + 1) = F(2(j+1)) F(2j) + F(2j+1) = F(2j+2) [from the definition of Fibonacci numbers]
The “Towers of Hanoi” Puzzle: Your goal is to transfer the stack of discs from the left peg to the right peg, using only legal moves. A legal move is one in which a topmost disc is taken from one peg and placed on another, as long as the disc is never placed on a disc smaller than itself.
A recursive solution: To solve the puzzle with 1 disc, just move the disc directly. To solve the n-disc puzzle with pegs labelled SOURCE, SPARE, TARGET:
Solve the (n-1) disc puzzle with pegs relabelled SOURCE TARGET SPARE Move the largest (bottom) disc from SOURCE to TARGET Solve the (n-1) disc puzzle with pegs relabelled SPARE SOURCE TARGET
Let’s call T(n) the number of moves to solve a tower of size n
• T(1) = 1 • T(n) = 2* T(n-1) + 1 for n > 1
T(1) = 1 T(2) = 3 T(3) = 7 T(4) = 15 T(5) = 31
All horses are the same color. • If there is only one horse, there is only one color. • Induction step: Assume as induction hypothesis that within
any set of n horses, there is only one color. Now look at any set of n + 1 horses. Number them: 1, 2, 3, ..., n, n + 1. Consider the sets {1, 2, 3, ..., n} and {2, 3, 4, ..., n + 1}. Each is a set of only n horses, therefore within each there is only one color. But the two sets overlap, so there must be only one color among all n + 1 horses.