Tải bản đầy đủ (.pdf) (36 trang)

Applied Mathematics for Database Professionals phần 10 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (380.04 KB, 36 trang )

■Note ukasiewicz also introduced the Polish notation, which allows expressions to be written unambigu-
ously without the use of brackets. This is the basis of the
Reverse Polish Notation (RPN), which many pocket
calculators and expression compilers use.
In 3VL, predicates can change their truth values in time, but only from UNKNOWN to TRUE or
from
UNKNOWN to FALSE. This is rather slippery, because it means that in 3VL the value UNKNOWN
seems to be somewhat special. This description is too vague anyway; we need formal rules,
definitions, and truth tables. We’ll look at those details in a minute.
3VL is counterintuitive, as opposed to the classical 2-valued logic (2VL). The main reason
is that you lose the tertium non datur (the principle of the excluded middle). That is, if P is
unknown, then
¬P is unknown as well, which in turn means that P ∨¬P is unknown. Con-
sider the following famous Aristotelian example. “Tomorrow a sea battle will take place” is
neither
TRUE nor FALSE—it is unknown—yet the sentence “Either tomorrow there will be a sea
battle, or tomorrow there won’t be a sea battle” is certainly true (in reality). However, it is
unknown in 3VL, hence the counterintuitive nature.
Another problem arises from the fact that if two predicates are “possible” (that is, their
truth value could possibly be
TRUE), then their conjunction is also “possible.” However, this is
obviously wrong if one of them is a negation of the second. Ludwik Stefan Borkowski
(1914–1993) proposed to “fix” this problem by introducing a 4-valued logic (4VL); this indeed
makes the preceding problem disappear, but the solution is unsatisfactory and ad hoc.
Furthermore, 3VL does
not solve the problem of handling missing information; it does
not allow you to represent the reason why information is missing. At the end of this section,
you’ll see that Ted Codd proposed a 4VL in 1990, to distinguish between applicable and inap-
plicable values. However, a 4VL doesn’t tell you what to do if you don’t know whether a certain
attribute value is applicable or not; for example, if commission is applicable for sales reps
only, but you don’t know the job of a certain employee, what should you do with the commis-


sion attribute of that employee? One
NULL implies 3VL, two NULLs (applicable and inapplicable)
imply 4VL,
n NULLs imply (n+2)-valued logic. Using the technique of full induction, you can
prove that you’ll end up with an infinite number of (meanings of)
NULLs, and a corresponding
infinite number of truth values. To repeat part of this paragraph’s opening sentence: 3VL does
not solve the problem of handling missing information.
Even worse, 3VL is not only counterintuitive in itself; it is ill-implemented in the SQL
standard. Probably one of the biggest blunders in the SQL standard in this respect is that in
an attribute of the BOOLEAN data type, a NULL represents the logical value UNKNOWN. Wasn’t a NULL
supposed to represent the fact that you don’t know the value? There are more examples of
such mistakes in the SQL standard.
Y
ou

ll have to revisit all tautologies (and therefore all rewrite rules) from 2VL to check
whether they’re still valid in 3VL; you’ll find out that several tautologies don’t hold anymore.
Actually, you could even argue that we should use different names and symbols for the
connectiv
es in 3VL; after all, they ar
e different from the “corresponding” connectives in 2VL.
Truth Tables of Three-Valued Logic
T
ables D-1 through D-3 show the three standard truth tables for the negation, conjunction,
and disjunction connectives in 3VL.
APPENDIX D ■ NULLS AND THREE (OR MORE) VALUED LOGIC 341
7451AppD.qxd 5/16/07 12:40 PM Page 341
Table D-1. Three-Valued Truth Table for NOT (Negation)
P ¬P

T F
U U
F T
¬P is still FALSE if P is TRUE, and vice versa. However, the negation is not the complement
operator anymore, because the negation of
UNKNOWN is UNKNOWN.
Table D-2. Three-Valued Truth Table for AND (Conjunction)
PQP ∧Q
TTT
TUU
TFF
F T F
FUF
FFF
UTU
UUU
UFF
As you can see, P ∧ Q is only TRUE if both P and Q are TRUE. The result is FALSE if at least one
of the operands is
FALSE, and the three remaining combinations result in UNKNOWN.
Table D-3. Three-Valued Truth Table for OR (Disjunction)
PQP ∨Q
T T T
TUT
TFT
F
T
T
FUU
FFF

U
T
T
U
U
U
U
F
U
P
∨ Q is only FALSE if both P and Q are FALSE. The result is TRUE if at least one of the
operands is
TRUE, and there are again three combinations with result UNKNOWN.
APPENDIX D ■ NULLS AND THREE (OR MORE) VALUED LOGIC342
7451AppD.qxd 5/16/07 12:40 PM Page 342
Missing Operators
You almost never see a truth table for the implication and the equivalence in 3VL. The most
likely reason for the absence of the implication is that it is tough to come up with a good
d
efinition. It turns out that in 3VL, the implication connective is not definable in terms of
conjunction and negation, or disjunction and negation. Remember the following implication
rewrite rule from 2VL:
( P ⇒ Q ) ⇔ (¬P ∨ Q )
If you’d define the implication in 3VL according to this rewrite rule, you’d end up in the
situation that
P ⇒ P would evaluate to UNKNOWN if P is UNKNOWN; obviously, in any logic you
would like this to be
TRUE. The last row in Table D-4 shows the problem.
Table D-4. An Attempt to Define Three-Valued Implication
and Equivalence Connectives

PQP ⇒QP ⇔ Q
TTTT
T F F F
TUUU
FTTF
F F T T
FUTU
U T T U
UFUU
U U U? U?
Also, if P ⇒ Q and Q ⇒ P, you want P to be equivalent with Q. These problems are all
related to the fact that the negation is not the complement operator anymore. Actually, Jan
ukasiewicz proposed a truth table for the implication where the two
U? values in the last row
are both a
T instead—so he “fixed” the problem by sacrificing a tautology (the implication
rewrite rule).
Three-Valued Logic, Tautologies, and Rewrite Rules
If you want to use any of the rewrite rules we identified in 2VL, you’ll have to check them first
against the truth tables of 3VL; as you’ll find out, several tautologies and rewrite rules from
2VL are not necessarily also valid in 3VL. Listing D-1 shows two examples of such tautologies.
Listing D-1. E
xamples of 2VL Tautologies That Are Not Valid in 3VL
P ∨¬P
P
⇔ P
APPENDIX D ■ NULLS AND THREE (OR MORE) VALUED LOGIC 343
7451AppD.qxd 5/16/07 12:40 PM Page 343
Handling Three-Valued Logic
Consider the following two rather obvious statements (in an SQL context):

• A row shows up in a table (or in the result of a query) or it doesn’t.
• A constraint gets violated or it doesn’t.
There are no other possibilities; therefore, these are two-valued issues. However, in 3VL,
predicates have three possible outcomes:
TRUE, FALSE, or UNKNOWN. Unfortunately, there is no
intuitive interpretation for this third possible outcome. To give you an idea of the inconsisten-
cies, look at Table D-5 where you see the difference between evaluating the predicate, say
P,
of a
WHERE clause of an SQL query compared with checking the predicate of an SQL CHECK
constraint.
Table D-5. Predicate Evaluation in SQL: Queries vs. Constraints
P(row) WHERE P(row) CHECK(P(row))
T Row accepted Row satisfies constraint
F Row rejected Row violates constraint
U Row rejected Row satisfies constraint
As you can see, FALSE and UNKNOWN lead to the same result for WHERE clauses in queries,
whereas
TRUE and UNKNOWN lead to the same effect in constraints. The third line in the preceding
table shows the discrepancy; a row will violate the predicate (and therefore not be retrieved)
when the predicate is part of a
WHERE clause. However, that row will satisfy the predicate when
evaluated by a
CHECK constraint that is defined on a table that receives this row.
If you want to get control over 3VL in ISO-standard SQL, it is a good idea to think in terms
of the three SQL functions introduced in Table D-6. They allow you to create a 2VL layer on top
of 3VL, thus providing more explicit control over the three Boolean values
TRUE, FALSE, and
UNKNOWN.
Table D-6. The IS {TRUE|FALSE|UNKNOWN} Operators in SQL

P IS TRUE (P) IS FALSE (P) IS UNKNOWN (P)
T TF F
F F
T
F
U FF T
Note that UNKNOWN does not appear in the last three columns of Table D-6. Therefore, these
three operators enable you to map three-valued expressions to 2VL.
Listing D-2 shows some rewrite rules based on the operators defined in Table D-6.
Listing D-2. Some R
ewrite Rules in 4VL Using the IS Operators
IS TRUE ( P ) ⇔ ( P ∧¬( IS UNKNOWN (P) ) )
IS FALSE ( P )
⇔ (¬P ∧¬( IS UNKNOWN (P) ) )
IS TRUE (
¬P ) ⇔ ( IS FALSE (P) )
APPENDIX D ■ NULLS AND THREE (OR MORE) VALUED LOGIC344
7451AppD.qxd 5/16/07 12:40 PM Page 344
IS FALSE ( ¬P ) ⇔ ( IS TRUE (P) )
IS TRUE ( P
∧ Q ) ⇔ ( IS TRUE (P) ∧ IS TRUE (Q) )
IS TRUE ( P
∨ Q ) ⇔ ( IS TRUE (P) ∨ IS TRUE (Q) )
IS FALSE ( P
∧ Q ) ⇔ ( IS FALSE (P) ∨ IS FALSE (Q) )
IS FALSE ( P
∨ Q ) ⇔ ( IS FALSE (P) ∧ IS FALSE (Q) )
IS TRUE (
∃x∈S: P ) ⇔ ( ∃x∈S: (IS TRUE (P) ) )
IS FALSE (

∃x∈S: P ) ⇔ ( ∀x∈S: (IS FALSE (P) ) )
IS FALSE (
∀x∈S: P ) ⇔ ( ∃x∈S: (IS FALSE (P) ) )
IS UNKNOWN (
∃x∈S: P ) ⇔ ( ¬∃x∈S: ( IS TRUE (P) ) ∧∃y∈S: (IS UNKNOWN (P) ) )
IS UNKNOWN (
∀x∈S: P ) ⇔ ( ¬∃x∈S: ( IS FALSE (P) ) ∧∃y∈S: (IS UNKNOWN (P) ) )
You can prove all these tautologies by using three-valued truth tables, or by using a com-
bination of 3VL rewrite rules you proved before.
Four-Valued Logic
In E. F. Codd’s The Relational Model for Database Management:Version 2 (Addison-Wesley,
1990), he proposes a revision of the first version of the relational model, RM/V1. Earlier, in
1979, he presented a paper in Tasmania with the title “Extending the Database Relational
Model to Capture More Meaning,” naming the extended version RM/T (T for Tasmania). The
features of RM/T were supposed to be gradually incorporated into the sequence of versions
RM/V2, RM/V3, and so on.
The most debatable sections of the RM/V2 book are Chapter 8 (“Missing Information”)
and Section 12.4 (“Manipulation of Missing Information”). In these sections, Codd proposes a
4VL in an attempt to make a distinction between the two most common reasons why informa-
tion is missing: applicable and inapplicable, represented with the two discernible values
A and
I, respectively. The truth tables he provides appear in Table D-7.
Table D-7. Four-Valued Truth Tables for NOT, OR,and AND
P ¬P
T F
A A
I I
F T
∨ TAI F
T T

T
T
T
A T
AAA
I T
A
IF
F TAFF
∧ T
A
I
F
T T
A
I
F
A AAIF
I I
I
I
F
F FFFF
APPENDIX D ■ NULLS AND THREE (OR MORE) VALUED LOGIC 345
7451AppD.qxd 5/16/07 12:40 PM Page 345
Note that the last two truth tables use a slightly different format from all other truth tables
y
ou saw so far in this book. They are formatted as a matrix where the four rows represent the
four possible truth values for
P, and the four columns represent the four possible values for Q,

respectively. This can be done because the disjunction and conjunction connectives are com-
mutative; in the regular truth table format, those two truth tables would have needed sixteen
rows each.
Note that introducing the two discernible values
A and I also implies that you have to
revisit the outcome of arithmetic operators and string concatenation; Ted Codd proposed the
behavior shown in Listing D-3, where
x denotes a regular numeric attribute value and s
denotes a regular character string value.
Listing D-3. Arithmetic Operators and Concatenation Revisited in 4VL
a + a = a a || a = a
i + i = i i || i = i
x + a = a s || a = a
a + i = i a || i = i
x + i = i s || i = i
As stated before, the whole idea of introducing two discernible values (a and i) to replace
the
NULL (and the corresponding 4VL) must be considered as one of Ted Codd’s few mistakes,
in hindsight. But it is always easy to criticize afterwards; the importance of Ted Codd’s original
paper cannot be overestimated.
APPENDIX D ■ NULLS AND THREE (OR MORE) VALUED LOGIC346
7451AppD.qxd 5/16/07 12:40 PM Page 346
Answers to Selected Exercises
Chapter 1 Answers
Exercise 1
a. This is a FALSE proposition.
b. Predicate. It is equivalent to the predicate x > 0.
c. This is a FALSE proposition.
d. This is a TRUE proposition.
e. This is a FALSE proposition.

Exercise 2
If you compare the truth tables for A ∧ B and A | B, you’ll notice a pattern:
A B A ∧ B A | B
T T T F
TFFT
F
T
F
T
FFFT
Whenever expression A ∧ B is TRUE, expression A | B is FALSE, and vice versa. In other
wor
ds, the first expr
ession is the negation of the second expression. This should bring you
straight to the solution for expressing the
AND in terms of the NAND:
(A ∧ B) ⇔¬(A | B)
347
APPENDIX E
7451AppE.qxd 5/15/07 1:43 PM Page 347
If you compare the truth tables for A ∨ B and A | B, you’ll again notice a pattern:
ABA ∨ B A | B
TTTF
TFTT
FTTT
FFFT
The truth values for A ∨ B read downwards in the truth table, and equal the truth values
for
A | B, if read upwards in the truth table. So, if you were first to generate the four combina-
tions of values for

A and B the other way around and then computed the truth values for the
NAND on those, you should find the solution. Generating “the other way around” is the same as
negating the original input values of
A and B. Extending the preceding truth table with the
negations of
A and B will give you the following truth table:
ABA ∨ B A | B ¬A ¬B(¬A) | (¬B)
TTTFFFT
T F T T F T T
FTTTTFT
FFFTTTF
The third column now equals the last column, so you can conclude the following:
(A ∨ B) ⇔ ((¬A) | (¬B))
Exercise 3
Truth Table for (P ∧ P) ⇔ P
PPP ∧ P
TTT
FFF
Truth Table for (¬¬ P) ⇔ P
P ¬P ¬¬P
TFT
F
T
F
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES348
7451AppE.qxd 5/15/07 1:43 PM Page 348
Truth Table for (P ∨ Q) ⇔ (Q ∨ P)
PQP ∨ QQ ∨ P
TTTT
TFTT

FTTT
FFFF
Truth Table for ((P ∧ Q) ∧ R) ⇔ (P ∧ (Q ∧ R))
PQRP ∧ Q (P ∧ Q) ∧ RQ ∧ RP ∧ (Q ∧ R)
TTTTT TT
T T F T F F F
TFTFF FF
TFFFF FF
F TTF FTF
FTFFF FF
F F T F F FF
FFFFF FF
Truth Table for ((P ∧ Q) ∨ R) ⇔ ((P ∨ R) ∧ (Q ∨ R))
P Q R P ∧ Q (P ∧ Q) ∨ R P ∨ R Q ∨ R (P ∨ R) ∧ (Q ∨ R)
TTTTT TTT
TTFTT TTT
T FTF T TTT
TFFFF TFF
F T T F T TTT
F TFF F FTF
FFTFT TTT
FFFFF FFF
Truth Table for ¬(P ∨ Q) ⇔ (¬P ∧¬Q)
PQP ∨ Q ¬(P ∨ Q) ¬P ¬Q ¬P ∧¬Q
TTT F FFF
TFT F FTF
FTT F TFF
F
F
F

TTTT
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 349
7451AppE.qxd 5/15/07 1:43 PM Page 349
The following table proves the second De Morgan law ¬(P ∧ Q) ⇔ (¬P ∨¬Q) by using
available rewrite rules.
Derivation Comments
¬(P ∧ Q) ⇔ Double negation (twice)
¬(¬¬P ∧¬¬Q) ⇔ First law of De Morgan (right to left)
¬¬(¬P ∨¬Q) ⇔ Double negation
(¬P ∨¬Q)
Exercise 4
b. Using available rewrite rules.
Derivation Comments
P ⇒ Q ⇔ Rewrite implication into disjunction
¬P ∨ Q ⇔ Commutativity
Q ∨¬P ⇔ Double negation
¬¬Q ∨ ¬P ⇔ Rewr
ite disjunction into implication
¬Q ⇒¬P
d. ¬(P ⇒ Q) ⇔ (P ∧¬Q), using available rewrite rules.
Derivation Comments
¬(P ⇒ Q) ⇔ Rewrite implication into disjunction
¬(¬P ∨ Q) ⇔ De Morgan
¬¬P ∧ ¬Q ⇔ Double negation
P ∧¬Q
f. ( ( P ⇒ Q ) ∧ ( P ⇒
¬
Q ) ) ⇔
¬
P, using tr

uth table.
PQP ⇒ Q ¬Q P ⇒¬Q (P ⇒ Q) ∧ (P ⇒¬Q) ¬P
TTTFF F F
TFFTT F F
FTTFT T T
F
F
T
T
T
T
T
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES350
7451AppE.qxd 5/15/07 1:43 PM Page 350
Exercise 5
You can use truth tables or existing rewrite rules. Alternatively, you can bring up a valuation
for the involved variables for which the predicate evaluates to
FALSE (that is, you give a counter
e
xample).
a. P ⇒ (P ∧ Q)
Counter Example: P = TRUE and Q = FALSE
Derivation
TRUE ⇒ (TRUE ∧ FALSE) ⇔
TRUE ⇒ FALSE ⇔
FALSE
Therefore P ⇒ (P ∧ Q) is not a tautology.
b. P ⇒ (P ∨ Q)
Using Existing Rewrite Rules
Derivation Comments

P ⇒ (P ∨ Q) ⇔ Rewrite the implication into a disjunction
¬P ∨ (P ∨ Q) ⇔ Associativity
(¬P ∨ P) ∨ Q ⇔ Special case
TRUE ∨ Q ⇔ Special case
TRUE
Therefore P ⇒ (P ∨ Q) is a tautology.
f. (P ⇒ Q) ⇒ (P ∧ Q) is not a tautology.
Counter Example: P = FALSE and Q = TRUE
Derivation
(FALSE ⇒ TRUE) ⇒ (FALSE ∧ TRUE) ⇔
(TRUE) ⇒ (FALSE) ⇔
FALSE
N
ote that the value of
Q did not r
eally matter:
P = FALSE and Q = FALSE is a second
counter example
.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 351
7451AppE.qxd 5/15/07 1:43 PM Page 351
Chapter 2 Answers
Exercise 1
a. TRUE; 3 is an element of set A.
b. Meaningless; the left operand should be a set.
c. TRUE; the empty set is a subset of every set.
d. FALSE; there are only five elements in A, none of which is the empty set.
e. TRUE.
f. FALSE; again there are only five elements in A, none of which is the set {3,4}.
Exer

cise 2
a. {3, 5, 7, 9}
b. ∅
c. {0}
Exercise 3
a. { z ∈ N | sqrt(z) ∈ N }
b. { z ∈ N | mod(z,2) = 0 }
c. { p ∈ N×N | π
1
(p)+π
2
(p) < 11 }
Exercise 4
a. {3,4,5,7,9}
c. {1,8}
f. Depends on the operator precedence. If A − (B ∩ C) is meant, then {1,2,8}.
If
(A − B) ∩ C is meant, then {2}.
Exercise 6
a. TRUE.
b. TRUE.
f. TRUE.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES352
7451AppE.qxd 5/15/07 1:43 PM Page 352
g. FALSE.
n
.
T
here are ten distinct subsets of
S t

hat have two elements. You can construct these
subsets as follows. Pick a first element from
S. You have five possible choices for this.
Then pick a second element from
S, excluding the first-picked element. You have four
p
ossible choices for this. This gives a total of five times four, which equals twenty
choices of two elements from
S. However, because the order of the choices does not
matter, we have to divide twenty by two, resulting in ten possible subsets of
S with
only two elements.
Exercise 7
Expression = ≠⊂⊄∈∉

∅ TTT
∅ {∅}TTT
{
∅} {∅}T T T
{
∅} {{∅}} T T T
1 S T T
{1} S T T T
{1,2} S TT T
{1,2,3} S T T T
{1,2,{1,2}} S T TT
{1,{1}} S T T T
∅ S T T T
{
∅} S T T T

#S S T T
Chapter 3 Answers
Exercise 2
a. TRUE; all elements in set A are greater than 1.
b. TRUE; 5 is an element that exists in B for which, when chosen for var
iable
x, mod(x,5) =
0
.
c. FALSE; if you choose element 2 in A for x and choose 1 in B for y, then x + y = 3, which
is not greater than or equal to
4. Because there exists such a combination for x and y,
the given predicate does not hold for all values
x and y, and is therefore FALSE. The
predicate would be
TRUE if you redefine set B to {3,5,7,9}.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 353
7451AppE.qxd 5/15/07 1:43 PM Page 353
d. TRUE; for each element that you can choose from A, there is always an element in y
that can be picked such that x + y = 11. For x = 2, 4, 6, 8, pick y = 9, 7, 5, 3,
respectively.
e. FALSE; there is no value in set B such that if you add that value to every available value
i
n set
A,
the result of every such addition would always be
1
1
.
The predicate would be

TRUE if you redefined set A such that it only holds one element, which effectively down-
grades the inner universal quantification to an existential quantification. For
A = {2}
you can choose y = 9. For A = {4} you can choose y = 7. For A = {6} you can choose
y= 5. For A = {8} you can choose y = 3. Another option would be to redefine set A to
the empty set. The inner universal quantification will then be
TRUE, irrespective of the
expression
(x + y = 11). As long as B has at least one element, the full predicate will
then always be
TRUE.
f. TRUE; choose 2 in A for both x and y. You might think that it is not allowed to choose the
same value twice, but it is in this case. Variables
x and y are bound independently to set
A. The binding of y to (the inner) A is not influenced by the value you choose for x that
is bound to the outer
A.
Exercise 3
a. ∀x∈A: div(x,2) = 0
b. ∀x∈B: x < 9
c. ∃x∈A: ∃y∈A: ∃z∈A: x ≠ y ∧ y ≠ z ∧ z ≠ x ∧ x + y + z = 18
Exercise 4
a. ∀x∈A: x ≥ 5
b. ∃x∈B: mod(y,2) = 0
Exercise 7
To prove this equivalence you start with either the left or right side of the equivalence and
apply a ser
ies of rewrite rules such that you end up with the other side. Let’s start with the
left side:
¬( ∃x∈S: ∀y∈T: P(x,y) )

Note that you can view this expression as follows: ¬( ∃x∈S: R(x) ), where R(x) =
(
∀y∈T: P(x,y) ). N
o
w y
ou can apply the third rewrite rule of Listing 2-15, which has the
following result:
( ∀x∈S: ¬R(x) )
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES354
7451AppE.qxd 5/15/07 1:43 PM Page 354
Substituting the expression for R(x) back into this gives the following result:
( ∀x∈S
:
¬( ∀y∈T
: P(x,y) ))
N
ow you can apply the fourth rewrite rule of Listing 2-15 to the inner (negated) universal
quantification, which has the following result:
( ∀x∈S: ∃y∈T: ¬P(x,y) )
This ends the proof of the given equivalence.
Chapter 4 Answers
Ex
ercise 3
a. Function.
b. Function.
c. Function.
d. Function.
e. Specified in the enumerative method, the set is { (a;f), (b;e), (b;f) }. This is not a
function.
f. This is not a function. The first pair holds a second coordinate that is not in A. The

second pair holds a first coordinate that is not in
B.
Exercise 6
a. The expression evaluates to { (X;1), (Y;3), (Z;2), (R;1) }. This is a function.
b. The expression evaluates to { (X;1) }. This is a function.
c. The expression evaluates to { (X;1), (Y;3), (X;2) }. This is not a function; the first
coordinate
X appears twice.
Exercise 7
a. { { (a;1), (b;1) }, { (a;1), (b;2) } }
b. ∅
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 355
7451AppE.qxd 5/15/07 1:43 PM Page 355
Exercise 8
a
.
{
(ean;9786012), (price;24.99) }
c. { (descr;'A very nice book') }
Exercise 11
a. The left side evaluates to { {(empno;104)}, {(empno;106)}, {(empno;102)} }: a set
of three functions. The right side evaluates to
{ {(empno;103)}, {(empno;104)},
{(empno;105)}, {(empno;106)} }
; this is a set of four functions. The proposition is
FALSE.
b. This expression evaluates to { {(deptno;10)}, {(deptno;20)} } ⊂ { {(deptno;10)},
{(deptno;20)} , {(deptno;30)} }
. This proposition is TRUE; the set of two functions at
the left is indeed a proper subset of the set of three functions at the right.

Chapter 5 Answers
Exercise 1
a. This is not a table; not all tuples have the same domain.
b. This is a table; in fact it is the empty table.
c. This is a table over {partno}.
d. This is a table over {suppno,sname,location}.
e. This is a table over {partno,pname,price}.
Exer
cise 2
a. { p | p∈∏(chr_PART) ∧ p(name)='hammer' ⇒ p(price)>250 }
b. { p | p∈∏(chr_PART) ∧ p(price)<400 ⇒ p(name)≠'drill' }, or
{ p | p∈∏(chr_PART) ∧ p(name)='drill' ⇒ p(price)≥400 }
c. { p | p∈∏(chr_PART) ∧ p(partno) ∈ {10,15,20} ⇒ p(instock)≤42 }
Ex
ercise 3
E1 holds five tuples: the four tuples from table P and tuple {(partno;201)}. Because they do
not all share the same domain,
E1 is not a table.
E2 holds five tuples that all share the domain {partno,pname,price}; it is therefore a table.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES356
7451AppE.qxd 5/15/07 1:43 PM Page 356
Exercise 4
E6, the join of S and SP, is a table over {partno,suppno,available,reserved,sname,location}.
It holds the six tuples from
SP that have been extended with the supplier name and location.
E
8
r
epresents the Cartesian join of
S a

nd
P.
It is a table over
{
partno,pname,price,suppno,
sname,location}
, and holds eight tuples.
Exercise 5
P1 states that for all pairs of parts that can be chosen from table P, the two parts have different
part numbers. This is a
FALSE proposition because the formal specification allows a pair to
hold the same part twice.
P2 states that for all pairs of different parts (chosen from table P), the two parts have differ-
ent part numbers. This is a
TRUE proposition.
Chapter 6 Answers
Exercise 1
a. This proposition states that all even-numbered parts (in table PAR1) have a price of less
than or equal to
15. This is a TRUE proposition.
b. If you rewrite this proposition into a universal quantification, you’ll see that it
states that all parts are priced
5 and are currently in stock. Obviously this is a FALSE
proposition.
c. If you rewrite the implication into a disjunction, you’ll see that this proposition states
that there are six parts in
PAR1 for which we either have 10 or less items in stock, or that
cost
10 or less. This is a TRUE proposition; all six parts in PAR1 satisfy the implication.
Exercise 4

This involves specifying three subset requirements and one additional constraint to state that
every tuple in
EMP1 has a corresponding tuple in one of the specializations.
TRN1⇓{empno} ⊆ EMP1⇓{empno} ∧
MAN1⇓{empno} ⊆ EMP1⇓{empno} ∧
CLK1⇓{empno} ⊆ EMP1⇓{empno} ∧
(∀ e∈EMP1: e(job)='TRAINER'⇒(∃ t∈TRN1: t(empno)=e(empno)) ∧
e(job)='MANAGER'⇒(∃ m∈MAN1: m(empno)=e(empno)) ∧
e(job)='CLERK' ⇒(∃ c∈CLK1: c(empno)=e(empno)))
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 357
7451AppE.qxd 5/15/07 1:43 PM Page 357
Exercise 5
This involves specifying three subset requirements and a few additional constraints stating
that all tuples in
EMP1 are covered by exactly one tuple in one of the specializations.
TRN1⇓{empno} ⊆ EMP1⇓{empno} ∧
MAN1⇓{empno} ⊆ EMP1⇓{empno} ∧
CLK1⇓{empno} ⊆ EMP1⇓{empno} ∧
TRN1⇓{empno} ∩ MAN1⇓{empno} = ∅ ∧
TRN1⇓{empno} ∩ CLK1⇓{empno} = ∅ ∧
MAN1⇓{empno} ∩ CLK1⇓{empno} = ∅ ∧
#EMP1 = #TRN1 + #MGR1 + #CLK1
Exercise 7
This is a tuple-in-join predicate. We join EMP1 with CLK1 on the empno attribute, and then join
back to
EMP1 on the manager attribute (which requires attribute renaming).
(∀ e∈(EMP1⊗CLK1)⊗(EMP1◊◊{(manager;empno),(m_deptno;deptno)}):
e(deptno)=e(m_deptno))
This is a FALSE proposition; the managers of clerks 105 and 107 work in a different
department.

Chapter 7 Answers
Exercise 2
Predicate o(STATUS)='CONF' ⇒ o(TRAINER)≠-1 is equivalent to predicate o(TRAINER)=-1 ⇒
o(STATUS)∈{'CANC','SCHD'}. This is a manifestation of the following rewrite rule:
(A ⇒ B) ⇔ (¬B ⇒ ¬A)
Your response should therefore be that adding that tuple constraint does not add
anything.
Exercise 3
tab_MEMP :=
{ M | M
∈℘(tup_MEMP) ∧
/* EMPNO uniquely identifies a tuple */
( ∀m1,m2∈M: m1(EMPNO) = m2(EMPNO) ⇒ m1 = m2 ) ∧
( ∀m∈M: |{ e| e∈M ∧ e(MGR)=m(MGR) }| ≤ 10 )
}
When designing this constraint, you might want to check with the users whether the TERM
table structure should play a role in this constraint.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES358
7451AppE.qxd 5/15/07 1:43 PM Page 358
Exercise 6
Of the thirteen elements that are in tab_RESULT (see Listing 7-25), only the following two can
be combined with the given
LIMIT table:
{ ∅
, { { (POPULATION;'DP'), (COURSE;'set theory'), (AVG_SCORE;'C') }
, { (POPULATION;'DP'), (COURSE;'logic'), (AVG_SCORE;'B') }
, { (POPULATION;'NON-DP'), (COURSE;'set theory'), (AVG_SCORE;'E') }
, { (POPULATION;'NON-DP'), (COURSE;'logic'), (AVG_SCORE;'D') } }
}
All other result tables either have an average score of A for database pros, or an average

score of
F for non-database pros; these are prohibited by the database constraint given in
DB_U2.
Exercise 7
You can express this by stating that for every department manager, the department number of
the department that employs the manager must be an element of the set of department num-
bers of departments managed by this manager.
PTIJ5(EMP,DEPT) :=
( ∀d1∈DEPT⇓{MGR}: ↵{ e(DEPTNO)| e∈EMP ∧ e(EMPNO)=d1(MGR)} ∈
{ d2(DEPTNO)| d2∈DEPT ∧ d2(mgr)=d1(mgr) } )
Note that this is now no longer a tuple-in-join predicate.
Exercise 9
Constraints PTIJ3 and PTIJ4 prevent these cycles.
Exercise 11
The given constraint is abstractly of the following form:
(∀o∈OFFR: (P(o) ⇒ (Q(o,REG) ∧ R(o,OFFR)))
Here P, Q, and R are predicates with free variables o, o plus REG, and o plus OFFR, respec-
tively. You can rewrite this predicate form into this:
(∀o∈OFFR: (P(o) ⇒ Q(o,REG)) ∧ (P(o) ⇒ R(o,OFFR)))
Y
ou can rewr
ite this
, in tur
n, into the following conjunction:
(∀o∈OFFR: P(o) ⇒ Q(o,REG)) ∧ (∀o∈OFFR: P(o) ⇒ R(o,OFFR))
Note that the second conjunct now only involves the OFFR table structure and therefore is
a table pr
edicate
.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 359

7451AppE.qxd 5/15/07 1:43 PM Page 359
Chapter 8 Answers
Exercise 3
STC(EMPB,EMPE) :=
(
∀e1∈EMPB, e2∈EMPE: (e1(EMPNO) = e2(EMPNO) ∧ e1(MSAL) > e2(MSAL))
⇒ e1(SGRADE) < e2(SGRADE))
Exercise 4
STC2(OFFRB,OFFRE) :=
/* New offerings must start with status SCHED */
( ∀o∈(OFFRE⇓{COURSE,STARTS}-OFFRB⇓{COURSE,STARTS})⊗OFFRE: o(STATUS)='SCHD' )
Exercise 5
We assume that addition has been defined on the date data type. By adding 31 days we for-
mally specify the “one month.”
STC(EMPB,EMPE) :=
(
∀e∈(EMPE⇓{EMPNO}−EMPB⇓{EMPNO})⊗EMPE: e(HIRED)<=sysdate+31 )
Exercise 6
If you rewrite the conclusion of STC7’s quantified implication into conjunctive normal form,
you’ll end up with six conjuncts. In the same way as exercise 11 in Chapter 7, you can then
rewrite the implication into a conjunction of six implications. From that, you can rewrite the
universal quantification into a conjunction of six quantifications.
You can rewrite
STC3 into a conjunction as follows:
( ∀o1∈OFFRB, o2∈OFFRE:
(o1
↓{COURSE,STARTS} = o2↓{COURSE,STARTS} ∧ o1(STATUS) ≠ o2(STATUS))
⇒ (o1(STATUS)='SCHD' ⇒ (o2(STATUS)='CONF' ∨ o2(STATUS)='CANC') )

( ∀o1∈OFFRB, o2∈OFFRE:

(o1
↓{COURSE,STARTS} = o2↓{COURSE,STARTS} ∧ o1(STATUS) ≠ o2(STATUS))
⇒ (o1(STATUS)='CONF' ⇒ o2(STATUS)='CANC') )
Exercise 9
In the following specification, CRSE represents the CRS table in the end state. You’ll need to join
to
CRS to determine the last day of the offering.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES360
7451AppE.qxd 5/15/07 1:43 PM Page 360
STC7(REGB,REGE) :=
(
∀r1∈REGB, r2∈REGE⊗(CRSE◊◊{(COURSE;CODE),(DUR;DUR)}):
(r1
↓{STUD,STARTS} = r2↓{STUD,STARTS} ∧ r1(EVAL) ≠ r2(EVAL))

( ( r1(EVAL) = -1 ∧ r2(EVAL) = 0 ∧ r2(STARTS) ≤ sysdate ∧
r2(STARTS)+r2(DUR) ≥ sysdate )∨
( r1(EVAL) = 0 ∧ r2(EVAL) ∈ {1,2,3,4,5} ) ) )
Chapter 9 Answers
Ex
ercise 1
{ t↓{empno,name} | t∈dbs(EMP) ∧ t(deptno)=10 }
select e.EMPNO, e.NAME
from EMP e
where e.deptno=10
Exercise 3
Note that an employee belongs to exactly one department. You can try to retrieve an answer
for this question but it will always be the empty set (table).
{ t↓{empno,name} | t∈dbs(EMP) ∧ t(deptno)=10 ∧ t(deptno)=20}
select e.EMPNO, e.NAME

from EMP e
where e.DEPTNO=10 and e.DEPTNO=20
Exercise 5
{ (message;'Constraint is violated') | x∈{1} ∧
#{ e | e∈dbs(EMP) ∧ e(job)='PRESIDENT' } > 1 }

{ (message;'Constraint is satisfied') | x∈{1} ∧
#{ e | e∈dbs(EMP) ∧ e(job)='PRESIDENT' } ≤ 1 }
select 'Constraint is violated'
from DUAL
where 1
< (select count(*)
from EMP e
where e.job='PRESIDENT')
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 361
7451AppE.qxd 5/15/07 1:43 PM Page 361
union
select 'Constraint is satisfied'
from DUAL
where 1
>= (select count(*)
from EMP e
where e.job='PRESIDENT')
Exercise 7
There are a few ways to interpret “managers.” A manager is either an employee whose job
equals
MANAGER, or an employee who is managing other employees, or an employee who is
managing a department, or any combination of these. We’ll give queries for the first two
interpretations.
{ e↓{empno,name} | e∈dbs(EMP)⊗(dbs(GRD)◊◊{(sgrade;grade),(ulimit;ulimit)}) ∧

e(job)='MANAGER' ∧ e(msal)=e(ulimit) }
{ e
↓{empno,name} | e∈dbs(EMP) ∧ e(empno) ∈ { m(mgr) | m∈dbs(MEMP) } ∧
e(msal)=↵{ g(ulimit) | g∈dbs(GRD) ∧ g(grade)=e(sgrade) }
select e.EMPNO, e.NAME
from EMP e
where e.JOB='MANAGER'
and e.MSAL = (select g.ULIMIT
from GRD g
where g.GRADE = e.SGRADE)
select e.EMPNO, e.NAME
from EMP e
where e.EMPNO in (select m.MGR
from MEMP m)
and e.MSAL = (select g.ULIMIT
from GRD g
where g.GRADE = e.SGRADE)
Ex
ercise 10
The way this question has been expressed suggests the meaning of “manager” as an employee
who is managing other emplo
y
ees (
MEMP table str
uctur
e). In this case the answer to the ques-
tion is easy:
∅. No such manager exists, because there are two tuple-in-join constraints that
state that managers always earn more than the employees they manage.
You could also interpret “his employees” as the employees who work in the department(s)

that the “
manager” manages. We’ll provide the query for this case:
{ em↓{empno,name,msal} | em∈dbs(EMP)⊗(dbs(DEPT)◊◊{(empno;mgr),(mdeptno;deptno)})
∧((∃e∈dbs(EMP): e(job)≠'SALESREP' ∧
e(deptno)=em(mdeptno) ∧
e(msal)>em(msal)) ∨
(∃e∈dbs(EMP)⊗dbs(SREP):
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES362
7451AppE.qxd 5/15/07 1:43 PM Page 362
e(job)≠'SALESREP' ∧
e(deptno)=em(mdeptno) ∧
e(msal)+e(comm)/12>em(msal))) }
select distinct /* Must use distinct! */
em.EMPNO, em.NAME, em.MSAL
from EMP em
,DEPT d
where d.MGR = em.EMPNO
and (exists (select 'One of "his employees" earns more (non salesrep case)'
from EMP e
where e.job
<> 'SALESREP'
and e.DEPTNO = d.DEPTNO
and e.MSAL
> em.MSAL)
or
exists (select 'One of "his employees" earns more (salesrep case)'
from EMP e
,SREP s
where e.EMPNO = s.EMPNO
and e.DEPTNO = d.DEPTNO

and e.MSAL + s.COMM/12
> em.MSAL))
Exercise 13
{ {(empno;e(empno)),(name;e(name)),(smempno;sm(empno)),(smname;sm(name))}
| e
∈dbs(EMP) ∧ m1∈dbs(MEMP) ∧ m2∈dbs(MEMP) ∧ sm∈dbs(EMP)∧
e(empno)=m1(empno) ∧ m1(mgr)=m2(empno) ∧ m2(mgr)=sm(empno) }
select e.EMPNO, e.NAME, sm.EMPNO as SMEMPNO, sm.NAME as SMNAME
from EMP e
,MEMP m1
,MEMP m2
,EMP sm
where e.EMPNO = m1.EMPNO
and m1.MGR = m2.EMPNO
and m2.MGR = sm.EMPNO
Exercise 21
{ c↓{code,dur} ∪
{(2006_offerings; { o↓{starts,status} ∪
{(students; #{ r| r in dbs(REG) ∧
r↓{course,starts}=o↓{course,starts} })}
| o
∈dbs(OFFR) ∧ o(course)=c(code) ∧ year(o(starts))=2006 }
)}
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 363
7451AppE.qxd 5/15/07 1:43 PM Page 363
| c∈dbs(CRS) ∧ c(code) ∈ {'DB1','DB2','DB3'} }
select c.CODE, c.DUR, o.STARTS, o.STATUS
,(select count(*)
from REG e
where e.COURSE = o.COURSE

and e.STARTS = o.STARTS) as students
from CRS c
,OFFR o
where c.CODE in ('DB1','DB2','DB3')
and c.CODE = o.COURSE
and to_char(o.STARTS,'YYYY') = '2006'
Note that the SQL expression repeats CRS information.
Chapter 10 Answers
Exercise 1
First, the two table constraints are involved:
/* Attendee and begin date uniquely identify a tuple */
(
∀r1,r2∈R:
r1
↓{STARTS,STUD} = r2↓{STARTS,STUD} ⇒ r1 = r2 )
/* Offering is evaluated by all attendees, or it is too early to */
/* evaluate the offering */
(
∀r1,r2∈R:
( r1
↓{COURSE,STARTS} = r2↓{COURSE,STARTS} )

( ( r1(EVAL) = -1 ∧ r2(EVAL) = -1 ) ∨
( r1(EVAL) ≠ -1 ∧ r2(EVAL) π -1 )
) )
The first constr
aint can be violated if one of the administrators has already been regis-
tered for the offering.
The second constraint cannot be violated by transaction
ETX1 irrespective of the begin

state (assuming M
ar
ch 1 is still in the future; that is, other registrations already present still
reflect
EVAL=-1).
PTIJ8 (you cannot register for offerings in the first four weeks on the job) is involved and
cannot be violated by
ETX1 given the e.HIRED between sysdate - 91 and sysdate predicate in
the
WHERE clause
.
PTIJ9 (you cannot r
egister for offer
ings giv
en at or after leav
e date) is involved. For
ETX1
the begin state should r
eflect that all administr
ators who hav
e been hir
ed in the past thr
ee
months ar
e still working for the company.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES364
7451AppE.qxd 5/15/07 1:43 PM Page 364
PTIJ10 (you cannot register for overlapping courses) is involved. For ETX1 the begin state
should reflect that none of these administrators are already registered for another offering that
overlaps with the March 1 AM4DP offering.

PTIJ13 (trainer cannot register for offerings taught by him/herself) is involved. This one
cannot be violated because administrators cannot act as the trainer for an offering.
PTIJ15 (you cannot register for offering that overlaps with another one where you are the
trainer) is involved. For the same reason mentioned with
PTIJ13, this one cannot be violated
either.
PODC4 (offerings with more than six registrations must have status confirmed) is involved.
Depending upon the current number of registrations, the current status for the offering, and
the number of administrators that get registered for the AM4DP offering, this constraint might
well get violated by
ETX1.
PODC5 (number of registrations cannot exceed maximum capacity of offering) is involved.
This one too will get violated by
ETX1, depending on the current number of registrations and
the number added by
ETX1.
PODC6 (canceled offerings cannot have registrations) is involved; it will get violated if the
current status of the offering equals
'canceled'.
Exercise 3
The following integrity constraints are involved in the UPDATE statement of transaction ETX4:
PTIJ1, PTIJ3, PTIJ4, PTIJ6, and PTIJ7. All of these except PTIJ3 run the risk of being violated by
the statement.
APPENDIX E ■ ANSWERS TO SELECTED EXERCISES 365
7451AppE.qxd 5/15/07 1:43 PM Page 365

×