1 / 76

An Introduction to Logic

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. A TUTORIAL FOR DB PRACTITIONERS :. Assume you know something about the relational model

taima
Télécharger la présentation

An Introduction to Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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. 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: • An Introduction to Logic • An Introduction to Set Theory • The Relational Model: Logic and Set Theory Applied • Overall goal: To give you a firmer understanding of the foundations of relational theory

  3. 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. RON ROSS’S QUESTION : • I’d 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. NATURAL LANGUAGE IS OFTEN AMBIGUOUS : • From the Minutes of a Borough Council Meeting—discussed 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. 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. 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. 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. 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 it’s still ambiguous! (Right?)

  10. "A CUSTOMER MUST PLACE AN ORDER" : • Might look precise—but does it mean: • At least one customer places at least one order • There’s at least one order that every customer places • Every customer places at least one order • There’s exactly one order that every customer places • Each customer places exactly one order • Etc.

  11. 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 assessor’s parcels must have different owners • The Congress shall have power to declare war • A frammistat must grok a widget

  12. LOGIC : PROPOSITIONS • A proposition is a declarative sentence, or statement, that’s 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. POINTS ARISING : • Don’t 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 I’m mostly going to ignore): The proposition isn’t really the declarative sentence as such—rather, it’s the assertion made by that sentence ... E.g., "It’s hot" and "Il fait chaud" denote the same proposition

  14. 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. 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. A NOTE ON IMPLICATION : • Truth table not symmetric: • TRUE if p is FALSE and q is TRUE • IF p THEN qis • FALSE if p is TRUE and q is FALSE • FALSE implies anything! • IF p THEN q  ( NOT p ) OR q • Aside: This latter is a tautology ... Evaluates to • TRUE no matter what p and q stand for* • And here’s a contradiction:p AND NOT p • Tautologies of form ab are particularly important *

  17. CAVEAT : • Connectives are close but not identical to their natural • language counterparts ... because they’re 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: • I voted for a change in leadership and I was seriously disappointed • I was seriously disappointed and I voted for a change in leadership

  18. MORE CONNECTIVES : • p or q but NOT (p OR q) NOT (p AND q) • not both = neither p = not both p • nor q and q • Peirce arrow Sheffer 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. THE 4 MONADICS :

  20. THE 16 DYADICS :

  21. 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. 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. EXAMPLES : • Prove (NOT p) OR q  p IMPLIES q • Prove (NOT p) AND ( p  q) IMPLIES q is a tautology

  24. 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 p’s 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 p’s involves any ANDs, this pred is in conjunctive normal form (CNF)

  25. 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. Arguments satisfy predicate iff* resulting proposition evaluates to TRUE ... E.g., the sun satisfies "x is a star," the moon doesn’t • 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 (akapredicate calculus) = study of predicates, connectives, and logical inferences that can be made using such predicates and connectives * Iff = if and only if

  27. 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. 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. 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 values—see later

  30. 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. 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. 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. 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. 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. 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. THE TERMINOLOGY ISN’T 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 x’s !!! */ • 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. 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. 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": • I’ll leave this one to you!

  39. MORE ON THE QUANTIFIERS :1. WE DON’T 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 don’t need both ... but it’s nice to have both. E.g.:

  40. "GET SUPPLIERS WHO SUPPLY ALL PARTS" : • Compare and contrast:

  41. MORE ON THE QUANTIFIERS :2. EMPTY RANGES • EXISTS x ( p ( x ) ) NOT FORALL x ( NOT p ( x ) ) • Suppose there are no x’s; 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. SOME CONSEQUENCES : • Business rule or constraint of the form FORALL x (...) is "automatically" true if there aren’t any x’s. 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 don’t 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. 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," they’re very useful shorthand!)

  44. 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. MORE ON THE QUANTIFIERS :5. ADDITIONAL KINDS • Possibilities include: • There exist at least three x’s such that • A majority of x’s are such that • An odd number of x’s 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. "CUSTOMER MUST PLACE ORDER" REVISITED : • Two possible formulations—"It is the case that": • FORALL c EXISTS o ( places ( c, o ) ) • 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. 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 isn’t 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. BACK TO RON ROSS/* nothing ad hominem here, of course */ : • I’d 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. 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 they’re 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 don’t know which is intended"

  50. 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: There’s at least one order that every customer places

More Related