Applied Mathematics for Database Professionals phần 10 doc

36 293 0
Applied Mathematics for Database Professionals phần 10 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

■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 [...]... implementing, 291–296 sample database design and violations and, 299 database design (sample), 143–181, 199, 222 database constraints and, 170–181 database predicates and, 170, 175–181 database skeleton and, 144–147 database universe and, 167–181 formal specification of, 311–331 state transition constraints for, 186, 192–196 database designs defined, 92 implementing, 241–304 specifying formally, 139–184 7451Index.qxd... 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... operator, 109 average operator (AVG), 112 binary relations, 69 cardinality of sets, 29 Cartesian product, 39 compatible functions, 77 database, 93 database design, 92 database management system (DBMS), 93 database state, 93 database universe, 92 database variable, 92 disjoint sets, 34 function composition, 83 functions, 71 generalized product of set functions, 79 headings, 96 join operator, 108 joinable... patterns of, 127–136 sample database design and, 170, 175–181 database skeleton, 100 , 139, 141 sample database design and, 144–147 specification of, 313 database state spaces, 127 database states, 79, 98, 306 constraints and, 91–93, 266 data integrity constraints and, 143 defined, 93 queries and, 199–201 specifying formally, 98 top-down view of, 141 transactions and, 221–233 database universe, 36, 77,... 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 The predicate would be TRUE if you redefine... and, 199–216 sample database design and, 167–181 specification of, 325–330 specifying formally, 141 transactions and, 221–236 database variable, defined, 92 databases defined, 93 documenting, 140 Date, Chris, 7 DBMS (database management system), 93 See also SQL DBMS dbms_lock package, 286 De Brock, Bert, 142, 229 De Morgan Laws, 19, 50 declarative sentences, 5 declarative strategy, for DI code execution,... PTIJ9 (you cannot register for offerings given at or after leave date) is involved For ETX1 the begin state should reflect that all administrators who have been hired in the past three months are still working for the company 7451AppE.qxd 5/15/07 1:43 PM Page 365 APPENDIX E s ANSWERS TO SELECTED EXERCISES PTIJ10 (you cannot register for overlapping courses) is involved For ETX1 the begin state should... code and, 245 deferred checking for, 299–303 documenting, 140 sample database design and, 158 data integrity predicates, 117–138, 306 data management, relational model for, 5, 68, 81 data manipulation, 221–237, 306 data manipulation code, 243 data retrieval, 199–220, 306 data retrieval code, 243 data values, applicability and, 337, 341 database characterizations, 170, 324 database constraints, 143, 163,... (AVG_SCORE;'B') (AVG_SCORE;'E') (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... triggers for, 249 DNF (disjunctive normal form), 60 documenting databases/data integrity constraints, 140 domain, of functions, 71 double negation (involution), 19, 50 DUAL table, 268 dyadic operators, 14, 36 dynamic constraints See state transition constraints E elements, 24 embedded procedural strategy, for DI code execution, 251, 254 employee histories (HIST), 312 attribute constraints for, 260 . 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 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. 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

Ngày đăng: 08/08/2014, 18:21

Tài liệu cùng người dùng

Tài liệu liên quan