+ All Categories
Home > Documents > Predicate Logic (continued); and on to...

Predicate Logic (continued); and on to...

Date post: 20-Mar-2018
Category:
Upload: lethuan
View: 212 times
Download: 0 times
Share this document with a friend
30
Predicate Logic (continued); and on to Induction CSCI 2824, Fall 2014 http://l3d.cs.colorado.edu/~ctg/ classes/struct14/Home.html
Transcript
Page 1: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

Predicate Logic (continued);!and on to Induction"

CSCI 2824, Fall 2014"http://l3d.cs.colorado.edu/~ctg/

classes/struct14/Home.html "

Page 2: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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!

Page 3: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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. "!!!!

Page 4: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

Predicate Logic as a Representation for Statements to

Prove FOR-ALL(n)[ Prime(n) à THERE-EXISTS(q) [Greater-than(q, n) AND Prime(q)]]

Page 5: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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)]]

Page 6: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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)]]

Page 7: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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)]

Page 8: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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) ]

Page 9: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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]

Page 10: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

A program might work like this:

Guess: Blue, Orange, Red, Yellow Response: X0

Page 11: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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.

Page 12: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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) ]

Page 13: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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)]

Page 14: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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)] ]

Page 15: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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

Page 16: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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…

Page 17: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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

Page 18: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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

Page 19: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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!...

Page 20: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody
Page 21: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

Another classic example:

1 + 2 + 3 + … n = n (n + 1)/ 2

Page 22: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

Induction as a way of creating a series:

F(0) = 0 F(1) = 1 F(n) = F(n-1) + F(n-2)

Page 23: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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

Page 24: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

Hmm. Maybe?...

F(1) + F(3) + … F(2n-1) = F(2n) We know it’s true for n = 1. F(1) = F(2) = 1

Page 25: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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))

Page 26: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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]

Page 27: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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.

Page 28: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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

Page 29: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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

Page 30: Predicate Logic (continued); and on to Inductionl3d.cs.colorado.edu/~ctg/classes/struct14/lecslides/DiscStruc2014L... · Predicate Logic (continued);! and on to Induction" ... Everybody

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.


Recommended