Download presentation

Presentation is loading. Please wait.

Published byAstrid Myatt Modified over 2 years ago

1
Copyright © C.J. Date 2008. All rights reserved. No part of this material may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photographic, or otherwise, without the explicit written permission of the copyright owner. An Introduction to Logic a tutorial for database practitioners based on Chapter 1 The Building Blocks of Logic from the book Logic and Databases: The Roots of Relational Theory by C. J. Date

2
Copyright © C. J. Date 2008page 1 A TUTORIAL FOR DB PRACTITIONERS : Assume you know something about the relational model or at least SQL (not the same thing!) First of three interrelated presentations: 1.An Introduction to Logic 2.An Introduction to Set Theory 3.The Relational Model: Logic and Set Theory Applied Overall goal:To give you a firmer understanding of the foundations of relational theory

3
Copyright © C. J. Date 2008page 2 PREAMBLE (from the subject book, lightly edited) : In order to be able to frame business rules* in such a way as to avoid all ambiguity, you must be armed with an elementary knowledge of logic. The purpose of this chapter is to equip you with the basics of what you need in this respect... It shows how certain key concepts from elementary logic can be used to simplify the task of formulating rules whose interpretation is clear, precise, and unambiguous. The concepts in question are described and illustrated in tutorial fashion. No prior knowledge of logic is assumed. Or queries, or constraints, or... *

4
Copyright © C. J. Date 2008page 3 RON ROSSS QUESTION : Id like your opinion on a fundamental question about "rule"... Example just for illustration... It must be that: each customer places some order. Predicate? Proposition? Hybrid? Other?... I stick with my opinion so far that the closest thing in formal logic is logical implication, which can be taken to be a predicate... But the quantification does make it interesting. Just a diversion? Could you equally say: customer must place order. That sounds more like a predicate, but it may be just semantics (of course)... Any insight would be appreciated.

5
Copyright © C. J. Date 2008page 4 NATURAL LANGUAGE IS OFTEN AMBIGUOUS : From the Minutes of a Borough Council Meetingdiscussed in Ernest Nagel, "Symbolic Notation, Haddocks Eyes, and the Dog-Walking Ordinance," in James Newman (ed.), The World of Mathematics, Vol. 3 (Mineola, N.Y.: Dover Pubs., 2000): Councillor Trafford took exception to the proposed notice at the entrance of South Park: "No dogs must be brought to the Park except on a lead." He pointed out that this order would not prevent an owner from releasing his pets, or pet, from a lead when once safely inside the Park. The Chairman (Colonel Vine): What alternative wording would you propose, Councillor?

6
Copyright © C. J. Date 2008page 5 Councillor Trafford: "Dogs are not allowed in this Park without leads." Councillor Hogg: Mr. Chairman, I object. The order should be addressed to the owners, not to the dogs. Councillor Trafford: That is a nice point. Very well then: "Owners of dogs are not allowed in this Park unless they keep them on leads." Councillor Hogg: Mr. Chairman, I object. Strictly speaking, this would keep me as a dog owner from leaving my dog in the back garden at home and walking with Mrs. Hogg across the Park.

7
Copyright © C. J. Date 2008page 6 Councillor Trafford: Mr. Chairman, I suggest that our legalistic friend be asked to redraft the notice himself. Councillor Hogg: Mr. Chairman, since Councillor Trafford finds it so difficult to improve on my original wording, I accept. "Nobody without his dog on a lead is allowed in this Park." Councillor Trafford: Mr. Chairman, I object. Strictly speaking, this notice would prevent me, as a citizen, who owns no dog, from walking in the Park without first acquiring one. Councillor Hogg (with some warmth) : Very simply, then: "Dogs must be led in this Park."

8
Copyright © C. J. Date 2008page 7 Councillor Trafford: Mr. Chairman, I object. This reads as if it were a general injunction to the Borough to lead their dogs into the Park. Councillor Hogg interposed a remark for which he was called to order; upon his withdrawing it, it was directed to be expunged from the Minutes. The Chairman: Councillor Trafford, Councillor Hogg has had three tries; you have had only two... Councillor Trafford: "All dogs must be kept on leads in this Park."

9
Copyright © C. J. Date 2008page 8 The Chairman: I see Councillor Hogg rising quite rightly to raise another objection. May I anticipate him with another amendment: All dogs in this Park must be kept on the lead. This draft was put to the vote and carried unanimously, with two abstentions. But its still ambiguous! (Right?)

10
Copyright © C. J. Date 2008page 9 "A CUSTOMER MUST PLACE AN ORDER" : Might look precisebut does it mean: At least one customer places at least one order Theres at least one order that every customer places Every customer places at least one order Theres exactly one order that every customer places Each customer places exactly one order Etc.

11
Copyright © C. J. Date 2008page 10 WHAT ABOUT THESE ??? A company must hire an employee A book must have an author A passenger must purchase a ticket A speaker must have a glass of water A winetaster must not swallow Adjacent assessors parcels must have different owners The Congress shall have power to declare war A frammistat must grok a widget

12
Copyright © C. J. Date 2008page 11 LOGIC : PROPOSITIONS A proposition is a declarative sentence, or statement, thats categorically either true or false.* Examples: Every customer places at least one order The sun is a star The moon is a star The sun is further away than the moon George W. Bush won the U.S. presidential elections in 2000 and 2004 Yes, I do assume just two truth values! *

13
Copyright © C. J. Date 2008page 12 POINTS ARISING : Dont fall into the common trap of thinking propositions are always true... A false proposition is still a valid proposition Informally, P is a valid proposition if and only if the following is a valid question: "Is it true that P?" Very fine point (which Im mostly going to ignore): The proposition isnt really the declarative sentence as suchrather, its the assertion made by that sentence... E.g., "Its hot" and "Il fait chaud" denote the same proposition

14
Copyright © C. J. Date 2008page 13 LOGIC : CONNECTIVES Operators for combining propositions to make further (compound) propositions... Simple proposition = one with no connectives... Truth tables: Negation:E.g., NOT (the moon is a star): TRUE Disjunction:E.g., (the moon is a star) OR (the sun is a star): TRUE Conjunction:E.g.,(the moon is a star) AND (the sun is a star): FALSE

15
Copyright © C. J. Date 2008page 14 Bi-implication (BI-IMPLIES, also written IS EQUIVALENT TO / IF AND ONLY IF / IFF/ EQ / EQUIV / ) : E.g., (the sun is a star) IFF (the moon is a star) : FALSE Implication (IMPLIES, also written IF... THEN … ) : E.g., IF (the sun is further away than the moon) THEN (the sun is a star): TRUE /* see next page */ In practice we use symbols for the connectives (usually) and adopt precedence rules that allow us to drop parens

16
Copyright © C. J. Date 2008page 15 A NOTE ON IMPLICATION : Truth table not symmetric: TRUE if p is FALSE and q is TRUE IF p THEN q is FALSE if p is TRUE and q is FALSE FALSE implies anything! IF pTHEN q ( NOT p ) OR q Aside:This latter is a tautology... Evaluates to TRUE no matter what p and q stand for* And heres a contradiction: p AND NOT p Tautologies of form a b are particularly important *

17
Copyright © C. J. Date 2008page 16 CAVEAT : Connectives are close but not identical to their natural language counterparts... because theyre meant to be context independent E.g., p AND q q AND p /* another tautology */ But "and" is not necessarily commutative in natural language... Contrast 1 and 2: 1.I voted for a change in leadership and I was seriously disappointed 2.I was seriously disappointed and I voted for a change in leadership

18
Copyright © C. J. Date 2008page 17 MORE CONNECTIVES : p or q butNOT (p OR q)NOT (p AND q) not both= neither p= not both p nor qand q Peirce arrowSheffer stroke* p q p q Exactly 4 monadic / 16 dyadic connectives in total (not all named) Slightly unfortunate because " " is also used for OR *

19
Copyright © C. J. Date 2008page 18 THE 4 MONADICS :

20
Copyright © C. J. Date 2008page 19 THE 16 DYADICS :

21
Copyright © C. J. Date 2008page 20 COMPLETENESS : A logical system is truth functionally complete if and only if all possible connectives can be expressed in terms of the given ones The 20 possible connectives are not all primitive Primitive sets:{ NOT, OR } { NOT, AND } { NOR } { NAND }

22
Copyright © C. J. Date 2008page 21 TRUTH TABLES REVISITED : Alternative style (example): This style can be used to show truth value of arb log exp in terms of truth values of components: e.g., (NOT q) IMPLIES (NOT p)

23
Copyright © C. J. Date 2008page 22 EXAMPLES : Prove (NOT p) OR q p IMPLIES q Prove (NOT p) AND ( p q) IMPLIES q is a tautology

24
Copyright © C. J. Date 2008page 23 CONNECTIVES REVISITED : OR and AND are fundamentally dyadic... but N-adic versions can be defined (why, exactly?). Let p1, p2..., pn (n > 0) be predicates. Then: OR {p1,p2,...,pn} is equivalent to: FALSE OR (p1) OR (p2) OR... OR (pn) Note:If none of the ps involves any ORs, this pred is in disjunctive normal form (DNF) AND {p1,p2,...,pn} is equivalent to: TRUE AND (p1) AND (p2) AND... AND (pn) Note:If none of the ps involves any ANDs, this pred is in conjunctive normal form (CNF)

25
Copyright © C. J. Date 2008page 24 LOGIC : PREDICATES A predicate is a truth valued function. Examples: x is a star x is further away than the moon Every x places at least one y x won the y election in the year z Note parameters (or placeholders or free variables)... Invoking ("instantiating") predicate involves replacing parameters by arguments and yields a proposition (which evaluates to TRUE or FALSE, by definition)

26
Copyright © C. J. Date 2008page 25 Arguments satisfy predicate iff* resulting proposition evaluates to TRUE... E.g., the sun satisfies "x is a star," the moon doesnt Predicate with N parameters is N-place or N-adic (and if N = 0 the predicate is a proposition) Connectives apply to predicates as well as propositions... Simple/compound terminology applies too Terminology: Predicate logic (aka predicate calculus) = study of predicates, connectives, and logical inferences that can be made using such predicates and connectives * Iff = if and only if

27
Copyright © C. J. Date 2008page 26 LOGIC : INFERENCE Logic includes rules of inference by which new truths (theorems) can be inferred from given truths (axioms and/or previously proved theorems) Modus Ponens: If p IMPLIES q is true and p is true, we can infer that q is true ("direct reasoning") E.g., given the truth of both "If I have no money then I will have to wash dishes" and "I have no money," we can infer truth of "I will have to wash dishes" Modus Tollens: If p IMPLIES q is true and q is false, we can infer that p is false ("indirect reasoning")

28
Copyright © C. J. Date 2008page 27 LOGIC : QUANTIFICATION Another way to get a proposition from a predicate... Consider monadic predicate p(x) (parameter shown for clarity). Then these are propositions: EXISTS x ( p ( x ) )/* existential quantifier*/ /* "backward E*/ Meaning:At least one value a exists such that p(a) evaluates to TRUE FORALL x ( p ( x ) )/* universal quantifier */ /* "upside down A"*/ Meaning:All possible values a are such that p(a) evaluates to TRUE

29
Copyright © C. J. Date 2008page 28 EXAMPLES : EXISTS x ( x is a logician ) TRUE (e.g., take x to be Bertrand Russell) Single example suffices to show truth FORALL x ( x is a logician ) FALSE (e.g., take x to be George W. Bush) Single counterexample suffices to show falsity Note:Parameter x must "range over" some set of permissible valuessee later

30
Copyright © C. J. Date 2008page 29 LET x AND y RANGE OVER PERSONS : Consider dyadic predicate "x is taller than y" Quantify over x (using EXISTS, for definiteness): EXISTS x ( x is taller than y ) Monadic predicate... Invoke ("instantiate") with argument Steve: EXISTS x ( x is taller than Steve ) Proposition:TRUE iff there exists at least one person, say Arnold, taller than Steve

31
Copyright © C. J. Date 2008page 30 ALTERNATIVELY : Quantify over both parameters (using EXISTS, again for definiteness): EXISTS x ( EXISTS y ( x is taller than y ) ) Proposition:TRUE iff there are at least two persons not of the same height Given an N-adic predicate, quantifying over M parameters (M < N) yields n R-adic predicate, where R = N - M

32
Copyright © C. J. Date 2008page 31 SOME SYNTACTIC SIMPLIFICATIONS : EXISTS x ( EXISTS y ( x is taller than y ) ) EXISTS y ( EXISTS x ( x is taller than y ) ) Mean the same thing... Can simplify: EXISTS y EXISTS x ( x is taller than y ) EXISTS x, y ( x is taller than y ) Similarly for FORALL... Series of like quantifiers can be written in any sequence without changing semantics Also, redundant parens can be dropped

33
Copyright © C. J. Date 2008page 32 SIX POSSIBLE "FULL QUANTIFICATIONS" (and six distinct meanings) : Assuming at least two distinct persons: 1.EXISTS x EXISTS y ( x is taller than y ) Meaning: Somebody is taller than somebody else; TRUE, unless everybody is the same height 2.EXISTS x FORALL y ( x is taller than y ) Meaning: Somebody is taller than everybody; FALSE 3.FORALL x EXISTS y ( x is taller than y ) Meaning: Everybody is taller than somebody; FALSE

34
Copyright © C. J. Date 2008page 33 4.EXISTS y FORALL x ( x is taller than y ) Meaning: Somebody is shorter than everybody; FALSE /* But need to explain that predicates "x is taller*/ /* than y" and "y is shorter than x" are logically*/ /* equivalent!*/ 5.FORALL y EXISTS x ( x is taller than y ) Meaning: Everybody is shorter than somebody; FALSE 6.FORALL x FORALL y ( x is taller than y ) Meaning: Everybody is taller than everybody; FALSE

35
Copyright © C. J. Date 2008page 34 LOGIC : FREE AND BOUND VARIABLES Recap:A free variable is just a parameter Quantifying over a free variable makes it bound E.g.: x is taller than y/* x, y both free*/ EXISTS x ( x is taller than y)/* x bound, y free*/ EXISTS x EXISTS y ( x is taller than y) /* x, y both bound*/ So a proposition is a predicate with no free variables!

36
Copyright © C. J. Date 2008page 35 THE TERMINOLOGY ISNT VERY GOOD : Free variables = parameters; but bound variables have no exact counterpart in conventional programming terms... They serve as a kind of dummy, linking the predicate inside the parens to the quantifier outside. E.g.: EXISTS x ( x > 3 ) vs.EXISTS y ( y > 3 ) By contrast, consider: EXISTS x ( x > 3 ) AND x < 0/* two different xs !!! */ EXISTS y ( y > 3 ) AND x < 0 EXISTS y ( y > 3 ) AND y < 0 "Free" and "bound" really apply to variable occurrences in expressions, not to variables as such... (sigh)

37
Copyright © C. J. Date 2008page 36 EXERCISE (Honest Abe) : "You can fool some of the people some of the time, and some of the people all the time, but you cannot fool all the people all of the time." Is this statement unambiguous? What does it mean? Analysis: Statement involves three simple predicates (or propositions?) ANDed together: you can fool some of the people some of the time AND you can fool some of the people all the time AND /* but maps to AND */ you cannot fool all the people all of the time

38
Copyright © C. J. Date 2008page 37 EXERCISE (cont.) : Denote "you can fool person x at time y" by fool(x,y) "You can fool some of the people some of the time": EXISTS x EXISTS y ( fool (x, y ) ) easy enough "You can fool some of the people all the time": FORALL y EXISTS x ( fool (x, y ) ) ??? EXISTS x FORALL y ( fool (x, y ) ) ??? "You cannot fool all the people all the time": Ill leave this one to you!

39
Copyright © C. J. Date 2008page 38 MORE ON THE QUANTIFIERS : 1. WE DONT NEED BOTH EXISTS x ( x is taller than Steve ) NOT FORALL x ( NOT x is taller than Steve ) Say the same thing! More generally: EXISTS x ( p ( x ) ) NOT FORALL x ( NOT p ( x ) ) Likewise: FORALL x ( p ( x ) ) NOT EXISTS x ( NOT p ( x ) ) So we dont need both... but its nice to have both. E.g.:

40
Copyright © C. J. Date 2008page 39 "GET SUPPLIERS WHO SUPPLY ALL PARTS" : Compare and contrast:

41
Copyright © C. J. Date 2008page 40 MORE ON THE QUANTIFIERS : 2. EMPTY RANGES EXISTS x ( p ( x ) ) NOT FORALL x ( NOT p ( x ) ) Suppose there are no xs; then LHS evaluates to FALSE So RHS evaluates to FALSE So FORALL x ( NOT p ( x ) ) evaluates to TRUE But p was arbitrary... So FORALL x ( q ( x ) ) evaluates to TRUE: regardless of the predicate q(x) !

42
Copyright © C. J. Date 2008page 41 SOME CONSEQUENCES : Business rule or constraint of the form FORALL x (...) is "automatically" true if there arent any xs. E.g., "all citizens with taxable income in excess of one billion dollars must pay supertax" automatically true if no citizen has such a large taxable income Certain queries produce "unexpected" results (if you dont know logic). E.g., "get suppliers who supply all purple parts" s WHERE FORALL p (IF p.COLOR = COLOR(Purple) THEN EXISTS sp ( s.S# = sp.S# AND sp.P# = p.P# ) ) returns all suppliers if there are no purple parts (!)

43
Copyright © C. J. Date 2008page 42 MORE ON THE QUANTIFIERS : 3. DEFINITIONS Consider p(x); let x range over {x1,x2,...,xn}. Then: EXISTS x ( p ( x ) ) FALSE OR p ( x1 ) OR p ( x2 ) OR... OR p ( xn ) FORALL x ( p ( x ) ) TRUE AND p ( x1 ) AND p ( x2 ) AND... AND p ( xn ) E.g.:let p(x) = x has a moon; let x range over {Mercury, Venus, Earth, Mars} But foregoing definitions are valid only because the sets are all finite! (And even though the quantifiers are thus "just shorthand," theyre very useful shorthand!)

44
Copyright © C. J. Date 2008page 43 MORE ON THE QUANTIFIERS : 4. PRENEX NORMAL FORM IF FORALL x (x > 3 ) THEN EXISTS y ( y < 0 ) NOT FORALL x (x > 3 ) OR EXISTS y ( y < 0 ) NOT ( NOT EXISTS x ( NOT ( x > 3 ) ) ) OR EXISTS y ( y < 0 ) EXISTS x ( NOT ( x > 3 ) ) OR EXISTS y ( y < 0 ) EXISTS x EXISTS y ( NOT ( x > 3 ) OR y ( y < 0 ) ) Final formulation is in prenex normal form

45
Copyright © C. J. Date 2008page 44 MORE ON THE QUANTIFIERS : 5. ADDITIONAL KINDS Possibilities include: There exist at least three xs such that A majority of xs are such that An odd number of xs are such that and so on... One important one: There exists exactly one x such that ("UNIQUE") E.g.: UNIQUE x ( x has social security number y ) Meaning: Exactly one person has social security number y

46
Copyright © C. J. Date 2008page 45 "CUSTOMER MUST PLACE ORDER" REVISITED : Two possible formulations"It is the case that": 1.FORALL c EXISTS o ( places ( c, o ) ) 2.FORALL x ( IF cust ( x ) THEN EXISTS y ( order ( y ) AND places ( x, y ) ) ) First uses sorted logic... Variables "sorted" or typed: RANGE OF c IS CUSTOMER/* i.e., c is of type CUSTOMER*/ RANGE OF o IS ORDER/* i.e., o is of type ORDER*/ /* using style of QUEL or Data Sublanguage Alpha */

47
Copyright © C. J. Date 2008page 46 Or /* perhaps better */ specify ranges explicitly within the quantifiers: FORALL c CUSTOMER EXISTS o ORDER ( places ( c, o ) ) /* " " can be read as "belongs to" or "[is] in"*/ /*... Quantifiers now range coupled*/ Aside:No magic here... No suggestion that the system "understands" places(c,o)... In fact, logic isnt really about meaning, or interpretation, at all! By contrast, second formulation uses unsorted logic... just one "universe of discourse"... more conventional but less useful for our purposes

48
Copyright © C. J. Date 2008page 47 BACK TO RON ROSS /* nothing ad hominem here, of course */ : Id like your opinion on a fundamental question about "rule"... Example just for illustration... It must be that: each customer places some order. Predicate? Proposition? Hybrid? Other?... I stick with my opinion so far that the closest thing in formal logic is logical implication, which can be taken to be a predicate... But the quantification does make it interesting. Just a diversion? Could you equally say: customer must place order. That sounds more like a predicate, but it may be just semantics (of course)... Any insight would be appreciated.

49
Copyright © C. J. Date 2008page 48 HOW LOGIC HELPS : "But the quantification does make it interesting. Just a diversion?" Clearly not just a diversion!logic forces us to make the quantifiers explicit, even when theyre only implicit in the natural language formulation Natural language is often ambiguous... Rule designer says: "A customer must place an order"... and thinks this is a precise definition of a customer But a person trained in logic says: "There are many different logical expressions that could correspond to this assertion /* see next page */ and I dont know which is intended"

50
Copyright © C. J. Date 2008page 49 1.FORALL c EXISTS o ( places ( c, o ) ) Meaning: Every customer places at least one order 2.EXISTS c EXISTS o ( places ( c, o ) ) Meaning: At least one customer places at least one order 3.EXISTS o FORALL c ( places ( c, o ) ) Meaning: Theres at least one order that every customer places

51
Copyright © C. J. Date 2008page 50 4.FORALL c UNIQUE o ( places ( c, o ) ) Meaning: Each customer places exactly one order 5.UNIQUE o FORALL c ( places ( c, o ) ) Meaning: Theres exactly one order that every customer places So the logician has to ask the rule designer which of the foregoing interpretations, if any, is the one intended... How much better if the rule designer were trained in logic and expressed the rule logically in the first place! Yes, I know the counterarguments... but I dont agree with them

52
Copyright © C. J. Date 2008page 51 Reviewer:"Counterarguments to what? Surely not to the assertion that it would be better if the rule designer were trained in logic? If so, Id like to be told them, and perhaps some others would feel the same." Yes, thats what I meant... Claim is: Logic is simply too difficult for most people to deal with Might be true in general (big subject!)... but dont need to understand the whole of logic for the purpose at hand... and the benefits are so huge! Small effort up front pays for itself many times over in avoiding errors in rules, and constraints, and queries, and on and on

53
Copyright © C. J. Date 2008page 52 A FINAL REMARK : Logic is very solid !!! Began with the ancient Greeks: Aristotle 384-322 BCE Leibniz 1646-1716 laid foundations of modern logic Boole 1815-1864: Laws of Thought (1854) Frege 1848-1925: Quantifiers (1879) Wittgenstein 1889-1951: Truth tables (1922) Etc., etc., etc.

54
Copyright © C. J. Date 2008page 53 SUMMARY /* stuff to remember */ : Propositions Connectives and truth tables Predicates and instantiation Tautologies, contradictions, and rules of inference Quantifiers (existential and universal) Free and bound variables (or occurrences, rather) Sorted vs. unsorted logic

55
Copyright © C. J. Date 2008page 54 Why Three-Valued Logic Doesnt Work a technical presentation based on Chapter 18 "Why Three- and Four-Valued Logic Dont Work" from the book Date on Database: Writings 2000-2006 by C. J. Date

56
Copyright © C. J. Date 2008page 55 AN INTRODUCTION TO LOGIC (appendix) : Thesis: "3VL doesnt work" What is 3VL? Which 3VL? 3VL can be made to work (of course)... but it isnt useful /* doesnt solve "dont know" problem */ and it can be dangerous Goal:To persuade you not to touch 3VL with a ten-foot pole

57
Copyright © C. J. Date 2008page 56 2VL CONNECTIVES : REVIEW 4 monadics / 16 dyadics : total 20

58
Copyright © C. J. Date 2008page 57 TAUTOLOGIES AND CONTRADICTIONS : REVIEW Tautology: Evaluates to TRUE no matter what truth values are assigned to operands. E.g.: ( NOT ( p AND q ) ) ( ( NOT p ) OR ( NOT q ) ) ( NOT ( p OR q ) ) ( ( NOT p ) AND ( NOT q ) ) De Morgans Laws (using not IFF for clarity) No just tautologies but identities... Identities important for "query rewrite"... By system or by users (NB!) Contradiction:Evaluates to FALSE no matter what truth values are assigned to operands

59
Copyright © C. J. Date 2008page 58 CODDS 3VL /* from "Extending... RM" (1979) */ : Basic idea /* which incidentally is impossible to state in any precise and coherent way... */ : If you dont know what value given attrib should have in given tuple, dont give a value!mark it null instead Define truth valued expressions involving null to return UNKNOWN instead of TRUE or FALSE ("third truth value") Note: Codd subsequently used a instead of u (meaning "applicable but unknown")

60
Copyright © C. J. Date 2008page 59 "EXAMPLE" (sort of) : Consider: /* tuples returned iff WHERE cond is TRUE */ S WHERE CITY = London : S1 S WHERE CITY London : S3 S WHERE STATUS = 10 OR CITY = London : S1, S2

61
Copyright © C. J. Date 2008page 60 S WHERE CITY = London OR CITY London : S1, S3 /* hmmm... */ S WHERE CITY = null : empty /* hmmmmm... */ S WHERE CITY = CITY : S1, S3 /* hmmmmmmm... */ Nulls superficially attractive but problems surface very quickly In particular we need a way of testing for null since, e.g., CITY = null doesnt work (see later)

62
Copyright © C. J. Date 2008page 61 WHAT ABOUT IMPLICATION AND EQUIVALENCE ??? Both Codd and SQL (which allegedly supports 3VL) are silent on this issue... but if as in 2VL : Implication ( NOT p ) OR q Equivalence ( IF p THEN q ) AND ( IF q THEN p ) Then we have:

63
Copyright © C. J. Date 2008page 62 SOME (serious!) PROBLEMS : Implication (IF p THEN q) : In 2VL and natural language, IF p THEN p is a tautology... But not with implication as just defined! Equivalence (p IFF q) : In 2VL and natural language, p IFF p is a tautology... But not with equivalence as just defined!

64
Copyright © C. J. Date 2008page 63 WHY ARE THE PROBLEMS SERIOUS ??? 2VL tautologies / contradictions arent necessarily 3VL tautologies / contradictions !!! Optimizers can make mistakes (and theres some history here) Users can make mistakes... because inferences that seem intuitively valid (i.e. are valid in ordinary discourse), and are valid in 2VL, arent necessarily valid in the system...... meaning wrong answers !!!

65
Copyright © C. J. Date 2008page 64 WRONG ANSWERS ??? I.e., answers that are correct in the logic but incorrect in the real world This is why 3VL isnt useful and can be dangerous Example: type CHAR for simplicity

66
Copyright © C. J. Date 2008page 65 SQL QUERY : SELECTEMP# FROM DEPT, EMP WHERE NOT ( DEPT. DEPT# = EMP.DEPT# AND EMP.DEPT# = D1 ) Result : empty But a "good" optimizer will rewrite the query: SELECTEMP# FROM DEPT, EMP WHERE NOT ( DEPT. DEPT# = EMP.DEPT# AND EMP.DEPT# = D1 AND DEPT.DEPT# = D1 ) /* using "tautology" (?) transitivity of "=" */ /* (p = q AND q = r) (p = q AND q = r AND p = r) */ Result : E1 (!)

67
Copyright © C. J. Date 2008page 66 JUST AN OPTIMIZER BUG ??? WELL... The null in EMP.DEPT# means "Some value exists, we just dont know what it is" That value either IS or IS NOT D1 If it IS, orig expDEPT.DEPT# = D1 AND D1 = D1 FALSE AND TRUE FALSE If it IS NOT, expDEPT.DEPT# = (¬D1) AND (¬D1) = D1... AND FALSE FALSE FALSE is right answer... 3VL DOES NOT MATCH REALITY !!! (well, we already knew this)

68
Copyright © C. J. Date 2008page 67 DEFINE THE CONNECTIVES DIFFERENTLY ??? Now these are tautologies: IF p THEN p p IFF p ( p IFF q ) ( ( IF p THEN q ) AND ( IF q THEN p ) ) But this one isnt: /* so same old problems */ ( IF p THEN q ) ( ( NOT p ) OR q )

69
Copyright © C. J. Date 2008page 68 HOW MANY 3VLs ARE THERE ??? No. of connectives = no. of truth tables... Hence, 27 monadic ops and 19,683 dyadic ops (!)... All 3VLs have all of these connectives But which do we call NOT, and which OR, and which AND,... and which implication and which equivalence? Different choices "different 3VLs" In some, IF p THEN q ( NOT p ) OR q but IF p THEN p not a tautology In others IF p THEN p is a tautology but IF p THEN q ( NOT p ) OR q No 3VL preserves all desirable properties of 2VL (see paper by David McGoveran referenced later)... No universally accepted unique 3VL

70
Copyright © C. J. Date 2008page 69 NUMBER OF CONNECTIVES : monadic connectives dyadic connectives 2VL 4 16 3VL 27 19,683 4VL 256 4,294,967,296.................... nVL (n)**(n) (n)**(n 2 )

71
Copyright © C. J. Date 2008page 70 A FEW REMARKS ON 4VL : Many possible 4VLs... Codd proposed one (and then another, and then another) for dealing with two kinds of "missing information"... But 3VL tautologies / contradictions arent necessarily 4VL ditto !!! First proposal: IF p THEN p TRUE p IFF p TRUE IF p THEN q ( NOT p ) OR q p IFF q ( ( NOT p ) OR q ) AND ( ( NOT q ) OR p )

72
Copyright © C. J. Date 2008page 71 A FEW REMARKS ON 4VL (cont.) : De Morgans Laws fail (regardless of how we define implication and equivalence) FORALL x ( p ) NOT EXISTS x ( NOT p ) Second proposal: Foregoing problems remain Third proposal: De Morgans Laws now work... but: This 4VL doesnt reduce to 3VL !!!

73
Copyright © C. J. Date 2008page 72 A CLASSIFICATION SCHEME : In Chapter 6 "Why Relational DBMS Logic Must Not Be Many-Valued" in C. J. Date, Logic and Databases: The Roots of Relational Theory, David McGoveran shows that all nVLs for n > 2 fall into one of three categories: Fragments Reduce set of truth values that can be assigned to propositional variables to just TRUE or FALSE result is proper subset of 2VL (i.e., some connectives or inferences or theorems or tautologies missing) : Clearly undesirable

74
Copyright © C. J. Date 2008page 73 Extensions Reduce set of truth values that can be assigned to propositional variables to just TRUE or FALSE result is full 2VL : Clearly desirable... but impossible, if "2VL" means 2VL as conventionally understood and nVL is truth functionally complete... Connective that maps everything to "third truth value" cant be expressed in terms of 2VL connectives Deviants Neither of the above... Entirely different from conventional 2VL! Either not truth functionally complete or semantics very hard to understand or both /* see the paper */

75
Copyright © C. J. Date 2008page 74 FINAL REMARKS : Much more that could be said (see presentation "The Problem of Missing Information")... How many kinds of null are there? How "test for null"?... MAYBE connective Problems of intuition... Not is not NOT! Logical difference null vs. unknown How many legs does a dog have, if we call a tail a leg? nVL for n > 2 breaks the relational model !!!

76
Copyright © C. J. Date 2008page 75 So what should we do about "missing information" ??? Representation: David McGoveran and Hugh Darwen both have proposals for "designing to avoid nulls" Manipulation: How get "dont know" answers out of a 2VL database?... See Chapter 4 "The Closed World Assumption" in Logic and Databases: The Roots of Relational Theory Implementation: See The TransRelational Model (but dont hold your breath) Bottom line: We dont need nulls, and we dont need nVL for any n > 2 !!!

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google