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

Slides:



Advertisements
Similar presentations
The Logic of Quantified Statements
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Chapter 1: The Foundations: Logic and Proofs 1.1 Propositional Logic 1.2 Propositional Equivalences 1.3 Predicates and Quantifiers 1.4 Nested Quantifiers.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Chapter Modeling Theory Allow modeling to be done ontologically (high level of abstraction) Then, systematically transform the application model.
Chapter Relational Calculus Queries are open predicate-calculus formulas General form: { | F(x 1, …, x n ) } –Standard set-builder notation (i.e.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
Chapter Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages.
Relational Calculus CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth   We will occasionally use this arrow notation unless there is danger of.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 6 Limitations of propositional logic Introduction to predicate logic Symbols, terms and formulae, Parse.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Calculus R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion. Ronald Graham Elements of Ramsey.
Introduction to Database Systems 1 Relational Calculus Relational Model : Topic 2.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
Relational Calculus CS 186, Fall 2003, Lecture 6 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
Rutgers University Relational Calculus 198:541 Rutgers University.
Predicates and Quantifiers
Chapter 1: The Foundations: Logic and Proofs
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Lecture 3 [Self Study] Relational Calculus
Discussion #141/20 Discussion #14 Predicate Calculus.
The Relational Model: Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus.
1st-order Predicate Logic (FOL)
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
Chapter 1, Part II: Predicate Logic With Question/Answer Animations.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
Chapter 1, Part II: Predicate Logic With Question/Answer Animations.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
Relational Calculus CS 186, Spring 2005, Lecture 9 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
1 Introduction to Abstract Mathematics Predicate Logic Instructor: Hayk Melikya Purpose of Section: To introduce predicate logic (or.
Fall 2008/2009 I. Arwa Linjawi & I. Asma’a Ashenkity 1 The Foundations: Logic and Proofs Predicates and Quantifiers.
CS 285- Discrete Mathematics Lecture 4. Section 1.3 Predicate logic Predicate logic is an extension of propositional logic that permits concisely reasoning.
LDK R Logics for Data and Knowledge Representation First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
SQL: 1 SQL Correspondence with Relational Algebra select A from r where B = 1 Assume r(AB) and s(BC). select B from r except select B from s select A as.
Section 1.4. Propositional Functions Propositional functions become propositions (and have truth values) when their variables are each replaced by a value.
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
3. The Logic of Quantified Statements Summary
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Relational Calculus Chapter 4, Part B
Predicate Calculus Discussion #14 Chapter 2, Section 1 1/20.
Discussion #14 Predicate Calculus
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Predicate Calculus Discussion #14 Chapter 2, Section 1.
1st-order Predicate Logic (FOL)
Chapter 6: Formal Relational Query Languages
Predicates and Quantifiers
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Predicate Calculus. Predicate Calculus Topics Predicates Variables and instantiation Quantifiers Logical expressions Bound and free variables.
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4 – Part II.
1st-order Predicate Logic (FOL)
Relational Calculus Chapter 4, Part B
Presentation transcript:

Chapter 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)

Chapter 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

Chapter 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).

Chapter 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

Chapter 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}

Chapter 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)

Chapter 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) 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))

Chapter 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) R Mark R ,000 Drachma R Mark ,000 Drachma

Chapter 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

Chapter Relational Calculus Queries are open formulas, General form: { | F(x 1, …, x n ) } Examples: List $80 rooms. { | Room(x) has Cost(80) } Room R2 R3 List room costs in Marks. { |  z(Room(x) has Cost(z)  Cost(z) is equivalent to Amount(y) in Currency(Mark)) } Room Amount R1 150 R2 133 R3 133

Chapter Relational Calculus Basic Project-Select-Join Examples Get room information. { | r(x, y,z, w) } Get room number and room name of rooms that cost less than $85 and have 2 beds. { |  z(r(x, y, 2, z)  z < 85) } Get name and address of guests arriving on 10 May. { |  u  v  w(g(u, x, y, z)  s(u, v, 10 May, w)) }

Chapter Relational Calculus Join, Renaming & Union Examples Get name and address of guests who have a reservation for a room whose name is the same as the guest’s name. { |  a  b  c  d  e  f(g(a, x, y, z)  r(b, x, c, d)  s(a, b, e, f)) } Get name and address of guests who have reservations for more than two days or reservations for two-bed rooms. { |  a  b  c  d  e  f( g(a, x, y, z)  s(a, b, c, d)  (d > 2  r(b, e, 2, f))) }

Chapter Relational Calculus Negation Get guest number and name of guests not from Boston. { |  z  w(g(x, y, z, w)  w  Boston) } Get guest number of guests who do not have a reservation for room 1. The following is not correct. { |  y  z  w(s(x, y, z, w)  y  1) }

Chapter Relational Calculus Negation and Universal Quantification Get guest number of guests who do not have a reservation for room 1. (continuation of example) Find those who do and negate. { |  y  z  w(s(x, y, z, w)  y = 1) } = { |  y  z  w  (s(x, y, z, w)  y = 1) } = { |  y  z  w(  s(x, y, z, w)  y  1) } Almost correct, but yields universal complement. Restrict by using relative complement. { |  t  u  v(g(x, t, u, v)   y  z  w(s(x, y, z,w)  y = 1)) }

Chapter Relational Calculus Universal Quantification Get name and address of guests who have reservations for all presidential suites (rooms with two beds). { |  w(g(w, x, y, z)   a  b  c(r(a, b, 2, c)   d  e(s(w, a, d, e)))) }

Chapter Universal Quantification and SQL Queries { |  w(g(w, x, y, z)   a  b  c(r(a, b, 2, c)   d  e(s(w, a, d, e)))) } = { |  w(g(w, x, y, z)   a  b  c(  r(a, b, 2, c)   d  e(s(w, a, d, e)))) } = { |  w(g(w, x, y, z)   a  b  c(r(a, b, 2, c)   d  e(s(w, a, d, e)))) } = select Name, StreetNr, City from Guest g where not exists (select * from Room r where NrBeds = 2 and not exists (select * from Reservation s where g.GuestNr = s.GuestNr and r.RoomNr = s.RoomNr))