2

In what situations would you use domain relational calculus over tuple relational calculus?

For example this problem I solved using tuple relational:

List the co-authors of John Smith (authors who co-authored an article with John Smith)

with these relations: Authors(authorID,name) And Authoring(articleID,authorID) Primary and foreign keys in bold.

{t: articleID, name | ∃ a ∈ Author ∃ au Authoring a.authorID = au.AuthorID ∧ a.name = ‘John Smith’ ∧ a.authorID = au.AuthorID}

In addition, how would you express set differences in both? I am trying to work on a problem like the following:

Which author co-authored at least 1 paper with every author (without aggregate functions).

philipxy
  • 14,867
  • 6
  • 39
  • 83
AvLerner
  • 27
  • 4
  • @philipxy, how is there a redundancy if I am setting the conditions? – AvLerner Jul 03 '14 at 00:57
  • @philipxy, Another question asked for: List the articles authored by John Smith for which I got **{t: articleID | ∃ a ∈ Author ∃ au ∈ Authoring a.authorID = au.AuthorID ∧ a.name = ‘John Smith’}** I see I missed the ∈ but if I remove the second clause wouldn't I just be stating that both questions have the same query? – AvLerner Jul 03 '14 at 15:39
  • Is AuthorID a typo for authorID or is it supposed to be different? Do you think it matters in your question to have "a.authorID = au.AuthorID" twice or not? Also in it how do you expect name to be au names not a names? And does Smith collaborate with himself? (Your calculus is wrong.) Please answer the questions. – philipxy Jul 03 '14 at 20:54
  • It may help you to read [this](https://stackoverflow.com/a/24425914/3404097) about domain calculus. But in tuple calulus we say `"t ∈ D ∧ ... t.c ..." or "D(t) ∧ ... t.c ..." for a row/tuple t rather than "D(c,...) ∧ ... c ..." for a column/attribute c. – philipxy Jul 03 '14 at 21:40
  • @philipxy, that's relational algebra, not calculus. – AvLerner Jul 04 '14 at 01:16
  • Read what I said in my last comment: The link deals with relational domain calculus (that is mapped to relational algebra) and the way you get the relational tuple calculus is the way you get the relational domain calculus (the difference is in my last comment), namely by using given table statements to say what you want. Everything you need is in these comments and that link. Until I can write an answer, I offer you that. And you have not answered my questions. – philipxy Jul 04 '14 at 02:56
  • I re-worked the title and I re-did the equation. I made a mistake translating the statement originally. The reworked equation is now: {t articleID, name| Authors(t) ˄ t.name <> ‘John Smith ∃ a1 ∈ Author ∃ b1 ∈ Authoring ∃ a2 ∈ Author ∃ b2 ∈ Authoring a1.name= ‘John Smith’ ˄ a1.authorID=b1.authorID ˄ a2.name ≠ ‘John Smith’ ˄ a2.articleID=b2.articleID ˄ a2.authorID=b2.authorID ˄ a2.name = t.name ˄ a2.authorID = t.authorID}. Likely I still did it wrong because abstract math has always given me an issue. – AvLerner Jul 06 '14 at 15:20
  • 1. Edit your post to put that formula in. 2. Do you have a *question* about it? 3. The only "set difference" I see in your last problem is the special case of difference from the empty set. 4. Give a reference to versions of the calculi you are supposed to use. – philipxy Jul 06 '14 at 22:59

1 Answers1

1

In what situations would you use domain relational calculus over tuple relational calculus?

Assuming you have access to the same operators on values of columns, any expression of the tuple relational calculus, domain predicate calculus or relational algebra can be transformed into one of the other. You can use any of them in a given situation.

The tuple calculus expression

{ t < c,... > | ∃ u ∈ U : ... t.c ... u.x ...}

describes the same set as the domain calculus expression

{ < c,... > | ∃ x,... : U(x,...) ∧ ... c ... x ...}.

"U" names a given relation and "u" names an arbitrary tuple from from it and "x,..." are its attributes. "U(x,...)" is called an atomic formula. "∃" is called a quantifier and means "there exists" or "for some".)

So to convert tuple calculus to domain calculus:

  1. Drop the name for a tuple in the result.
  2. Replace a quantified tuple name and relation name by a quantified list of its attribute names and an atomic formula using them.
  3. Drop dotted tuple names.

And to convert domain calculus to tuple calculus:

  1. Insert a name for a tuple in the result.
  2. Rearrange so that every quantified attribute list contains exactly the attributes of one relation and an atomic formula with that relation follows it.
  3. Replace a quantified list of a relation's attribute names and an atomic formula using them by some new quantified tuple name and the relation's name.
  4. Insert dotted tuple names in front of their attributes.

In addition, how would you express set differences in both?

An expression in either calculus describes a set of tuples. The set difference A \ B is the set of tuples that are in set A but that are not in set B. If relation R holds tuples where expressionR and relation S holds tuples where expressionS then R \ S = R MINUS S = tuples where expressionR ∧ ~ expressionS.

(It may help you to read this about building queries via natural language then converting to domain calculus then converting to relational algebra. It starts with a parameterized statement as the meaning of each given relation/table. Then it finds a combination of those to express a given query. Then it converts that expression to shorthand which is like domain calculus. (And like standard predicate logic aka predicate calculus but also.) To get relational tuple calculus you convert the domain calculus to tuple calculus as described above. In SQL, JOIN ON, CROSS JOIN and "," are much like tuple calculus while JOIN USING and NATURAL JOIN are like a mixture of both domain calculus and tuple calculus.)

philipxy
  • 14,867
  • 6
  • 39
  • 83