Lecture 1:a. Correctnes b. Applets c. Tables Lecture 2 a. Applets b.Tables c.Exercises Lecture 3Lecture 4a.Appletsb. ProblemsLecture 5 Lecture 6 Lecture 7 Lecture 8 Test 1 Test 2
|
Lecture 3:
Solve problems 3.4 to 3.6 form Algorithms and Data Structures : The Science of Computing available from Ebrary.
3.4 Consider the problem of making Robin the robot back up one tile. The precise preconditions and postconditions for this problem are as follows:
Preconditions: |
1. There are no obstructions within two tiles of Robin, in any direction. Postconditions: |
2. Robin is one tile behind (relative to its original direction) its original position.
|
3. Robin is facing in its original direction.
|
Prove that each of the following algorithms correctly solves this problem:
| Algorithm 1 |
|
Algorithm 2 |
|
Algorithm 3 |
| robin.turnLeft(); |
|
robin.turnLeft(); |
|
robin.turnRight(); |
| robin.turnLeft(); |
|
robin.move(); |
|
robin.turnRight(); |
| robin.move(); |
|
robin.turnLeft(); |
|
robin.move(); |
| robin.turnLeft(); |
|
robin.move(); |
|
robin.turnLeft(); |
| robin.turnLeft(); |
|
robin.turnLeft(); |
|
robin.turnLeft(); |
| |
|
robin.move(); |
|
|
| |
|
robin.turnLeft(); |
|
|
>>Solution
3.5 Explain why each of the following is or is not a valid use of modus ponens:
1. Birds have wings. Having wings implies being able to fly. Therefore, birds are able to fly.
|
2. Sue always wears sunglasses when driving. Sue is driving now. Therefore, Sue is wearing sunglasses now. |
3. Dogs do not have wings. Having wings implies being able to fly. Therefore, dogs can't fly. |
4. Birds fly. Having wings implies being able to fly. Therefore, birds have wings.
|
5. If A and B are both positive, and A < B, then 1/A > 1/B. 2 < 2.5, and 2.5 < 3. Therefore, 1/2.5 lies between 1/2 and 1/3.
|
6. Any composite number is the product of two or more prime numbers. 18 is composite. Therefore, 18 is the product of two or more prime numbers.
|
| 7. Any composite number is the product of two or more prime numbers. 18 is composite. Therefore, 18 = 3×3×2. |
8. If a baseball player drops the ball, then he or she is a bad baseball player. I once saw a college baseball player drop the ball. Therefore, all college baseball players are bad baseball players.
|
9. Any person who hand-feeds piranhas is crazy. Therefore, this book's first author is crazy.
|
>>Solution
3.6 Which steps in the correctness proof for the secondsSinceMidnight method would be invalid if hour or minute included a fractional part? What if hour were greater than 23, or minute or second greater than 59?
>>Solution |