In 3VL, predicates can change their truth values in time, but only from UNKNOWN to TRUE orfrom UNKNOWN to FALSE.. Truth Tables of Three-Valued Logic Tables D-1 through D-3 show the three
Trang 1■ 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 orfrom 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, theirtruth 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 SQLstandard 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
You’ll have to revisit all tautologies (and therefore all rewrite rules) from 2VL to checkwhether 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 theconnectives in 3VL; after all, they are different from the “corresponding” connectives in 2VL
Truth Tables of Three-Valued Logic
Tables D-1 through D-3 show the three standard truth tables for the negation, conjunction,
and disjunction connectives in 3VL
Trang 2Table D-1.Three-Valued Truth Table for NOT (Negation)
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
Trang 3Missing 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
definition 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 thesituation 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
and Equivalence Connectives
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
P ∨ ¬P
P ⇔ P
Trang 4Handling 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 nointuitive 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 CHECKconstraint
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 precedingtable 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 whenevaluated 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, andUNKNOWN
P IS TRUE (P) IS FALSE (P) IS UNKNOWN (P)
Listing D-2 shows some rewrite rules based on the operators defined in Table D-6
IS TRUE ( P ) ⇔ ( P ∧ ¬ ( IS UNKNOWN (P) ) )
IS FALSE ( P ) ⇔ (¬P ∧ ¬ ( IS UNKNOWN (P) ) )
IS TRUE ( ¬P ) ⇔ ( IS FALSE (P) )
Trang 5IS 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 bination of 3VL rewrite rules you proved before
com-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
Trang 6Note that the last two truth tables use a slightly different format from all other truth tablesyou saw so far in this book They are formatted as a matrix where the four rows represent thefour 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 sixteenrows each.
Note that introducing the two discernible values A and I also implies that you have torevisit the outcome of arithmetic operators and string concatenation; Ted Codd proposed thebehavior shown in Listing D-3, where x denotes a regular numeric attribute value and sdenotes a regular character string value
Trang 7Answers 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
Trang 8If you compare the truth tables for A ∨ B and A | B, you’ll again notice a pattern:
Trang 9Truth Table for (P ∨Q) ⇔(Q ∨P)
Trang 10The following table proves the second De Morgan law ¬(P ∧ Q) ⇔ (¬P ∨ ¬Q) by usingavailable rewrite rules.
¬(P ∧ Q) ⇔ Double negation (twice)
¬(¬¬P ∧ ¬¬Q) ⇔ First law of De Morgan (right to left)
Trang 11Exercise 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 counterexample)
Trang 12Chapter 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.
Trang 13a 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 variable 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 Thepredicate would be TRUE if you redefine set B to {3,5,7,9}
Trang 14d 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
in set A, the result of every such addition would always be 11 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 tothe empty set The inner universal quantification will then be TRUE, irrespective of theexpression (x + y = 11) As long as B has at least one element, the full predicate willthen 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
¬( ∃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) ) Now you can apply the third rewrite rule of Listing 2-15, which has thefollowing result:
( ∀x∈S: ¬R(x) )
Trang 15Substituting the expression for R(x) back into this gives the following result:
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 firstcoordinate X appears twice
Exercise 7
a { { (a;1), (b;1) }, { (a;1), (b;2) } }
Trang 16Exercise 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 isFALSE
b. This expression evaluates to { {(deptno;10)}, {(deptno;20)} }⊂{ {(deptno;10)},{(deptno;20)} , {(deptno;30)} } This proposition is TRUE; the set of two functions atthe 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}
Exercise 2
{ p | p∈∏(chr_PART) ∧ p(name)='drill' ⇒ p(price)≥400 }
Trang 17Exercise 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
E8 represents the Cartesian join of S and 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
c. If you rewrite the implication into a disjunction, you’ll see that this proposition statesthat there are six parts in PAR1 for which we either have 10 or less items in stock, or thatcost 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)))
Trang 18Exercise 5
This involves specifying three subset requirements and a few additional constraints statingthat 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} = ∅∧
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:
When designing this constraint, you might want to check with the users whether the TERMtable structure should play a role in this constraint