We finished chapter 1 and started on chapter 2 (2.1-2.3 and 2.5). Next week we will finish chapter 2 and start talking about relations and first-order logic. I suggest you read through Sections 2.1-2.3 carefully, since it contains several additional examples and exercises (some with solutions).
Submission: you can submit the homework to me either by hardcopy in class or email it to me.
1. [Check Constraints] Write complete ALTER TABLE commands for the following check constraints (see Section 1.4). Also, for each check constraint write an INSERT statement that violates the constraint. (Double-check by running them on the database.)
ALTER TABLE Student ADD CONSTRAINT career_constraint CHECK ( ... );
2. [Set Theory, 10pt] True of False? If true, give a proof, if false, find sets A, B, C that show that it is false:
A n (B u C) = (A n B) u C, for all sets A, B, C.
(u is union, n is intersection).
3. [Programming Logic, 15pt] Some programming languages (functional languages in particular) contain an if-then-else expression. That is you write
if condition then a else b,
and if condition holds, the value returned will be that of a and if not, the value of b. (In C you could write (a <= b ? a : b) to compute the minimum of a and b.)
4. [SQL Queries, 30] For each SQL query, please submit your SQL and a printout of the resulting table. Be careful writing both of these, and make sure you double-check that your output is what you expect it to be.
5. [Extra Credit] You have five jars of quarters. One jar contains all counterfeit quarters, the remaining jars contain good quarters only. The counterfeit quarters are 5 grams each, the real quarters 6 grams. You also have a scale. You can pick any number of coins from the jars and make one weighing on the scale. How do you determine which jar contains the counterfeit quarters?
6. [Extra Credit] Show that every truth-function can be written using just logical nand (see Section 1.5 for definition of nand). Hint: show that negation and logical and can be expressed just using nand.
7. [Extra Credit] An old English nursery rhyme goes as follows:
For want of a nail the shoe was lost.
For want of a shoe the horse was lost.
For want of a horse the rider was lost.
For want of a rider the battle was lost.
For want of a battle the kingdom was lost.
And all for the want of a horseshoe nail.
What is the logical structure of this nursery rhyme? Introduce appropriate atomic propositions (one for each object), and then use these propositions to describe the statements in the rhyme.
8. [Extra Credit] If you find any typos and mistakes in the lecture notes, please let me know.