Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 - 1 Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages.

Similar presentations


Presentation on theme: "Chapter 5 - 1 Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages."— Presentation transcript:

1 Chapter 5 - 1 Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages “what” rather than “how” SQL (helps with formulation of some harder queries) Prolog –Model theory (basis for design theory, techniques & tools)

2 Chapter 5 - 2 Syntax – Symbols Truth Values: T F Constants Variables Functions: return a value Predicates: return T or F Logical Connectors Quantifiers:   –  xP(x) = P(x 1 )  P(x 2 )  … –  xP(x) = P(x 1 )  P(x 2 ) ... Parentheses P Q  P P  Q P  Q P  Q P  Q F F T F F T T F T T F T T F T F F F T F F T T F T T T T

3 Chapter 5 - 3 Syntax – Terms & Atoms Terms: yield a value –Each variable and constant is a term. –Each function is a term (e.g., f(t 1, t 2 ) where t 1 and t 2 are terms). Atoms: yield T or F –T –F –Each predicate is an atom (e.g., p(t 1, t 2 ) where t 1 and t 2 are terms).

4 Chapter 5 - 4 Syntax – Formulas Formulas –An atom is a formula. –If P & Q are formulas, so are (  P), (P  Q), (P  Q), (P  Q), (P  Q) –If P is a formula and x is a variable,  x(P) and  x(P) are formulas Example:  x(x+y = 10   z  x(x > z)) –bound and free variables –scope of a variable –closed and open formulas

5 Chapter 5 - 5 Semantics Interpretation –Specify domain D –Assign values in D to: Constants (unique name assumption: literals denote themselves & constant symbols like  have only one value) n-ary functions: f:D n  D (e.g., +, -, …) n-ary predicates: p:D n  {T, F} (e.g., <, =, …) Evaluation –Closed formulas: evaluation yields T or F –Open formulas: evaluation yields set of domain elements Examples –D = {0, …, 99} –  x(2x mod 100 > 95) evaluates to T –  x(2x mod 100 > 95) evaluates to F –2x mod 100 > 95 yields {48, 49, 98, 99}

6 Chapter 5 - 6 Counting Quantifiers Notational shorthand –  1 x(P(x)) T if there is exactly 1 value for which P is true –  2 x(P(x)) … exactly 2 … –   5 x(P(x)) … 5 or more … –  <3 x(P(x)) … less than 3 … Equivalent expressions –  0 x(P(x))   x(P(x))   x(  P(x)) –  1 x(P(x))   x(P(x))   x  y(P(x)  P(y)  x = y)

7 Chapter 5 - 7 Model Theory & Relational DBs Let relation names be predicates with a place for each attribute. Write integrity constraints as closed formulas. Example: r(A, B, C) 1 2 3 2 2 2 A is a Key. Interpretation: Domain = {1,2,3} r(1, 2, 3) = T r(2, 2, 2) = T r(x, y, z) = F (for all others)  x   1 (r(x, y, z))

8 Chapter 5 - 8 Model Theory, OSM, & Rel. DBs Relations: Integrity Constraints: –Key Constraints  x   1 y(Room(x) has Cost(y))  x  y   1 z(Cost(x) is equivalent to Amount(z) in Currency(y))  x  y   1 z(Cost(z) is equivalent to Amount(x) in Currency(y)) –Referential-Integrity Constraints  x  y  z(Cost(x) is equivalent to Amount(y) in Currency(z)   w(Room(w) has Cost(x))) –Attribute-Domain Constraints  x(  y  z(Cost(y) is equivalent to Amount(z) in Currency(x)  x  {Mark, Drachma, …})... Room(x) has Cost(y) Cost(x) is equivalent to Amount(y) in Currency(z) R1 90 90 150 Mark R2 80 90 225,000 Drachma R3 80 80 133 Mark 80 200,000 Drachma

9 Chapter 5 - 9 Valid Interpretations Interpretation –Domain all values in the current DB domain-closure assumption: these are the only elements that can be substituted for variables –Value Assignments assign constants to themselves use the closed-world assumption (tuple substitutions for predicates yield T, and all other substitutions yield F) Valid Interpretation –All closed formulas evaluate to T –DB integrity: the constraints of the DB are satisfied –Examples: the previous two examples show valid interpretations


Download ppt "Chapter 5 - 1 Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages."

Similar presentations


Ads by Google