4 Domain Relational Calculus

Similar documents
Relational Calculus. Module 3, Lecture 2. Database Management Systems, R. Ramakrishnan 1

3. Mathematical Induction

NOTES ON LINEAR TRANSFORMATIONS

Basic Proof Techniques

Notes on Determinant

(LMCS, p. 317) V.1. First Order Logic. This is the most powerful, most expressive logic that we will examine.

Handout #1: Mathematical Reasoning

This asserts two sets are equal iff they have the same elements, that is, a set is determined by its elements.

Introduction to tuple calculus Tore Risch

Turing Degrees and Definability of the Jump. Theodore A. Slaman. University of California, Berkeley. CJuly, 2005

Rigorous Software Development CSCI-GA

Relational Databases

1 Error in Euler s Method

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

PYTHAGOREAN TRIPLES KEITH CONRAD

Lecture 16 : Relations and Functions DRAFT

5 Homogeneous systems

Solving Linear Systems, Continued and The Inverse of a Matrix

Mathematical Induction

Computability Theory

Relational Database Systems 1

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Scalar Valued Functions of Several Variables; the Gradient Vector

ON FUNCTIONAL SYMBOL-FREE LOGIC PROGRAMS

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

CHAPTER 7 GENERAL PROOF SYSTEMS

ML for the Working Programmer

A Propositional Dynamic Logic for CCS Programs

8 Divisibility and prime numbers

ON THE DEGREE OF MAXIMALITY OF DEFINITIONALLY COMPLETE LOGICS

Continued Fractions and the Euclidean Algorithm

On strong fairness in UNITY

C H A P T E R Regular Expressions regular expression

Lemma 5.2. Let S be a set. (1) Let f and g be two permutations of S. Then the composition of f and g is a permutation of S.

Winter Camp 2011 Polynomials Alexander Remorov. Polynomials. Alexander Remorov

Fixed-Point Logics and Computation

Correspondence analysis for strong three-valued logic

THE FUNDAMENTAL THEOREM OF ARBITRAGE PRICING

4.5 Linear Dependence and Linear Independence

Lecture 1: Course overview, circuits, and formulas

Monitoring Metric First-order Temporal Properties

How To Know If A Domain Is Unique In An Octempo (Euclidean) Or Not (Ecl)

MATH 289 PROBLEM SET 4: NUMBER THEORY

4.6 The Primitive Recursive Functions

Future Value of an Annuity Sinking Fund. MATH 1003 Calculus and Linear Algebra (Lecture 3)

Predicate Logic. For example, consider the following argument:

Chapter 4, Arithmetic in F [x] Polynomial arithmetic and the division algorithm.

Kevin James. MTHSC 412 Section 2.4 Prime Factors and Greatest Comm

CMCS 312: Programming Languages Lecture 3: Lambda Calculus (Syntax, Substitution, Beta Reduction) Acar & Ahmed 17 January 2008

26 Integers: Multiplication, Division, and Order

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

How To Understand The Theory Of Computer Science

INCIDENCE-BETWEENNESS GEOMETRY

Mathematical Induction

Settling a Question about Pythagorean Triples

CODING TRUE ARITHMETIC IN THE MEDVEDEV AND MUCHNIK DEGREES

def: An axiom is a statement that is assumed to be true, or in the case of a mathematical system, is used to specify the system.

The Settling Time Reducibility Ordering and 0 2 Setting

MATH10040 Chapter 2: Prime and relatively prime numbers

Reading 13 : Finite State Automata and Regular Expressions

Relations: their uses in programming and computational specifications

I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

Cyclotomic Extensions

LEARNING OBJECTIVES FOR THIS CHAPTER

WHEN DOES A CROSS PRODUCT ON R n EXIST?

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

Set theory as a foundation for mathematics

Deterministic Finite Automata

Lecture 2: Universality

Data Integration. Maurizio Lenzerini. Universitá di Roma La Sapienza

8 Primes and Modular Arithmetic

Automata on Infinite Words and Trees

Summary Last Lecture. Automated Reasoning. Outline of the Lecture. Definition sequent calculus. Theorem (Normalisation and Strong Normalisation)

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

F. ABTAHI and M. ZARRIN. (Communicated by J. Goldstein)

Linear Maps. Isaiah Lankham, Bruno Nachtergaele, Anne Schilling (February 5, 2007)

SOLUTIONS TO EXERCISES FOR. MATHEMATICS 205A Part 3. Spaces with special properties

v w is orthogonal to both v and w. the three vectors v, w and v w form a right-handed set of vectors.

o-minimality and Uniformity in n 1 Graphs

Similarity and Diagonalization. Similar Matrices

Let H and J be as in the above lemma. The result of the lemma shows that the integral

1 = (a 0 + b 0 α) (a m 1 + b m 1 α) 2. for certain elements a 0,..., a m 1, b 0,..., b m 1 of F. Multiplying out, we obtain

Real Roots of Univariate Polynomials with Real Coefficients

Lecture 22: November 10

SYSTEMS OF PYTHAGOREAN TRIPLES. Acknowledgements. I would like to thank Professor Laura Schueller for advising and guiding me

FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z

Mathematical Induction. Mary Barnes Sue Gordon

Solutions Q1, Q3, Q4.(a), Q5, Q6 to INTLOGS16 Test 1

Solving Systems of Linear Equations

Cartesian Products and Relations

1 Operational Semantics for While

Math 223 Abstract Algebra Lecture Notes

Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan

Linear Algebra Notes for Marsden and Tromba Vector Calculus

1.7 Graphs of Functions

Page 331, 38.4 Suppose a is a positive integer and p is a prime. Prove that p a if and only if the prime factorization of a contains p.

Lecture Notes on MONEY, BANKING, AND FINANCIAL MARKETS. Peter N. Ireland Department of Economics Boston College.

Transcription:

4 Domain Relational Calculus We now present two relational calculi that we will compare to RA. First, what is the difference between an algebra and a calculus? The usual story is that the algebra RA is operational a RA expression describes a step-by-step procedure for computing a result relation. A calculus, on the other hand, is declarative it is essentially a language of predicates which describe whether a tuple value (or a collection of scalar values) is contained in the result. Thus, in principle, a database management system has more freedom implementing a calculus based query language than an algebraic one. Of course, RA is a side-effect-free expression language, which in the programming languages community probably would not be considered operational. So the distinction is slightly dubious... Nevertheless, we present the first of our two calculi, the Domain Relational Calculus (DRC). Informally, this is a language of predicates whose variables range over scalar values in the data domain D. A query expression can construct a tuple and ask (with a predicate) whether it is present in a given relation in the database instance. A DRC expression has the following form: E ::= { A 1 : x 1,... A n : x n F } where FV (F ) {x 1,..., x n } All the work is done in F, which is a first-order formula (formulas are described below). With each formula F we associate a set FV (F ) of its free variables. The truth value of a formula is determined using values assigned to its free variables. The assignment of values to free variables is given by a substitution, formally a function that maps the (countably infinite) set of variable names into the data domain D. Putting this together, the meaning of a formula F is given as [F ](s, r) where r is a database instance (as in the semantics of RA) and s is a substitution (which supplies values for the free variables of F ). We define formulas, free variables, and the semantics of formulas simultaneously as follows: Atomic Formulas F ::= B 1 : x 1,..., B n : x n R i ) where R i (B 1... B n ) R 14

FV (F ) = {x 1,..., x n } [F ](s, r) = ( (t : i : B i s[x i ]) r i ) F ::= x 1 = x 2 FV (F )(s, r) = {x 1, x 2 } [F ](s, r) = (s[x 1 ] = s[x 2 ]) F ::= x = c FV (F ) = {x} [F ](s, r) = (s[x] = v) where v D is the value denoted by c. Compound Formulas F ::= F 1 FV (F ) = FV (F 1 ) [F ](s, r) = [F 1 ](s, r) F ::= F 1 F 2 FV (F ) = FV (F 1 ) FV (F 2 ) [F ](s, r) = [[F 1 ](s, r) [F 1 ](s, r) F ::= xf 1 FV (F ) = FV (F 1 ) {x} [F ](s, r) = v D ( [F 1 ](s[x v], r) The notation s[x v] denotes a substitution that agrees with s on every argument except x, and returns v on argument x. In the semantics, the value of x ranges over the infinite set D; hence x necessarily takes on values that are not in D r. Now we can give the semantics of a DRC expression E: [ { A 1 : x 1,... A n : x n F } ](r) = { t : A 1 v 1,..., A n v n [F ](s 0 [x 1 v 1,..., x n v n,...], r) = true } 15

This is the set of tuples over D for which F is true, given the proper variable bindings. Since the free variables of F are included in {x 1,..., x n }, and the initial environment s 0 is updated on all of these variables, this definition is actually independent of s 0. Just as in quantified formulas, the variables range over the infinite set D, and so can take on values that are not in D r. Thus, the result can contain values that are not in D r, and may even be an infinite relation. This is technically important, as will be seen below. 5 Tuple Relational Calculus We now describe our second relational calculus, the Tuple Relational Calculus (TRC). Here variables range over tuple values. A query expression can select attributes from a tuple and can apply predicates. Since variables represent tuples, each variable must be typed with the set of attributes over which it is defined, and uses of variables must be consistent with their types. We follow the convention that the type is part of the variable name, and write variables as x(x) or x(a 1... A k ) in the definitions below. The syntax of a TRC expression is as follows: E ::= { x(x) F } where FV (F ) = {x} As in the definition of DRC above, all the work is done in the formula F, and we give the semantics of F with respect to a substitution and a database instance: [F ](s, r) In TRC, substitutions map variables to tuple values. We require substitutions to be well typed: a substitution applied to variable x(x) yields a tuple value defined on exactly the attributes X. You can verify that this invariant holds of every substitution occurring in the semantics below. Atomic Formulas F ::= x(x) R i where R i (X) R 16

FV (F ) = {x(x)} [F ](s, r) = ( s[x(x)] r i ) F ::= x 1 (X 1 ).A 1 = x 2 (X 2 ).A 2 where A 1 X 1 and A 2 X 2 FV (F )(s, r) = {x 1 (X 1 ), x 2 (X 2 )} [F ](s, r) = ((s[x 1 (X 1 )])[A 1 ] = (s[x 2 (X 2 )])[A 2 ]) F ::= x 1 (X 1 ).A 1 = c where A 1 X 1 FV (F )(s, r) = {x 1 (X 1 )} [F ](s, r) = (s[x 1 (X 1 )])[A 1 ] = v where v D is the value denoted by c. Compound Formulas F ::= F 1 FV (F ) = FV (F 1 ) [F ](s, r) = [F 1 ](s, r) F ::= F 1 F 2 FV (F ) = FV (F 1 ) FV (F 2 ) [F ](s, r) = [[F 1 ](s, r) [F 1 ](s, r) F ::= x(x)f 1 FV (F ) = FV (F 1 ) {x(x)} [F ](s, r) = ( v U)((Attr(v) = X) ( [F 1 ](s[x(x) v], r)) Just as in DRC formulas, a quantified variable ranges over an infinite set all compatibly typed tuples over the infinite data domain D (variable x(x) ranges over all tuples with attributes X). Now we can give the semantics of a TRC expression E: [ {x(x) F } ](r) = { t U (Attr(t) = X) ([F ](s 0 [x(x) t], r) = true) } 17

As for DRC, this is the set of correctly typed tuples over D for which F is true. Since the only free variables of F is x(x), this definition is independent of s 0. Just as in quantified formulas, the variable ranges over an infinite set, and so the result can contain values that are not in D r, and can even be an infinite relation. 6 Equivalence of DRC and TRC We now show the equivalence of DRC and TRC. In the spirit of the Characterization Theorem for RA that we proved earlier, you might expect a result of the form for every DRC expression E and every instance r, there is a TRC expression E (E, r) that computes the same result: [E (E, r)](r) = [[E ](r) and vice versa. While this is true, we prove a much stronger equivalence: for every DRC expression E there is a TRC expression E (E) that computes the same function: ( r) ([E (E)](r) = [[E ](r)) and vice versa.. Recall we proved the Characterization Theorem by induction on the structure of a RA expression. We cannot quite achieve this for relational calculus, because DRC and TRC expressions are not defined recursively. A RC expression E is just some bound variables and a formula F. It is the formula that is defined recursively, not the expression. To prove equivalence of DRC and TRC, we first define a sense in which a TRC formula F and a DRC formula F can be considered equivalent, and then prove the equivalence of the expression languages by induction on the structure of formulas. Roughly, we shall say F (a TRC formula) and F (a DRC formula) are equivalent if the expressions E = { x(... A i...) F } and E = {... A i : x i... F } are equivalent (i.e. yield the same result when applied to any database instance). In more detail, suppose the free variables of F are FV (F ) = {..., x i (A i,1... A i,m,...}. and the free variables of F are FV (F ) = {..., y i,1... y i,m,...} 18

with the obvious correspondence between y i,j and x i [A i,j ]. A TRC substitution s and a DRC substitution s are similar (for F and F ) if ( i, j)( (s(x i ))[A i,j ] = s (y i,j ) That is, s and s represent the same values, reorganized to reflect the difference between the tuple-valued variables that occur free in F and the simple variables that occur free in F. Now, the sense in which F and F are equivalent is this: [F ](s, r) = [[F ](s, r) (for all rand all substitutions (s, s ) similar for (F, F )) It should be clear that a TRC expression and a DRC expression are equivalent exactly when their top-level formulas are equivalent by the above definition. So it suffices to show the following: Lemma: For every TRC formula F there is an equivalent DRC formula F. Proof: We show how to construct F by induction on the structure of F. Case F = x i (A i,1... A i,m ) R: F = A i,1 : y i,1,..., A i,m : y i,m R and the equivalence follows from the definition of similar substitutions. Case F = x i (A i,j ) = x k (A k,l ): F = y i,j = y k,l and again the equivalence follows from the definition of similar substitutions. Case F = x i (A i,j ) = c: This is similar to the previous case. 19

Case F = F 1 : F = F 1 The equivalence of F and F follows from the equivalence of F 1 and F 1, together with the observation that all substitution pairs (s, s ) that are equivalent for F and F are equivalent for F 1 and F 1 (since FV (F ) and FV (F 1 ) are identical). Case F = F 1 F 2 : F = F 1 F 2 This is similar to the previous case. Since FV (F ) = FV (F 1 ) FV (F 2 ) it again follows that all substitution pairs (s, s ) that are equivalent for F and F are equivalent for F 1 and F 1, and for F 2 and F 2. Case F = x i (X i )F 1 : F = x i,1,..., x i,m F 1 where X i = A i,1... A i,m The desired equivalence is ( v U)((Attr(v) = X i ) ( [F 1 ](s[x i (X i ) v], r ) ) iff ( v i,1,..., v i.m D) ( [[F 1 ](s [y i,j v i.j ], r) ) Since FV (F 1 ) FV (F ) {x i (A i,1,..., A i.m )} it follows that all substitution pairs (s, s ) that are equivalent for F and F generate substitution pairs that are equivalent for F 1 and F 1, as required. A similar construction works for the other direction: 20

Lemma: for every DRC formula F there is an equivalent TRC formula F. This proof is quite similar to the previous one, and is left as an exercise. Together, these two lemmas yield the promised equivalence theorem: Theorem: TRC and DRC are equivalent in expressive power. 21