0

It is somewhat confusing to me when to use quantifiers in tuple relational calculus (TRC). I stumbled upon following problem and I am still scratching my head thinking why not TRC query can be constructed without using existential quantifier.

The given problem reads like this:

Relations:
student (rollNo, name, degree, year, sex, deptNo, advisor)
department (deptId, name, hod, phone)
professor (empId, name, sex, startYear, deptNo, phone)
course (courseId, cname, credits, deptNo)
enrollment (rollNo, courseId, sem, year, grade)
teaching (empId, courseId, sem, year, classRoom)
preRequisite(preReqCourse, courseID)

Question: Obtain the names of courses enrolled by student named "Roger".

Given solution:

{ c.name | course(c) ^  
                   (∃s) (∃e) ( student(s) ^  
                                     enrollment(e) ^  
                                     s.name = “Roger” ^  
                                     s.rollNo= e.rollNo ^  
                                     c.courseId = e.courseId}  

Why I cant just have following? :

{c.name | course(c) ^ 
                 enrollment(e) ^ 
                 student(s) ^ 
                 c.courseId = e.courseId ^ 
                 e.rollNo = s.rollNo ^ 
                 s.name = "Roger" }           
RajS
  • 1,737
  • 5
  • 28
  • 50

1 Answers1

1

Something like { c.name | ... } is shorthand for something like

{z : (name) | (∃c) (z.name = c.name ^ ...) }.

As described on, e.g., the Wikipedia page, the fundamental form of the set comprehension (i.e. query) notation expects a variable to the left of the |. If you are familiar with anonymous functions/lambda notation, it is very similar to $\lambda z.(\dots)$. If we named it, it's like we're defining a predicate $P(z)\equiv(\dots)$. The upshot is that the notation effectively binds z (or c in the original form). But in your version without existential quantifiers, nothing is binding e or s. It's like you're referring to undeclared variables in a programming language.

Since whether the variables are bound with a universal or existential quantifier and where exactly that quantifier appears in the formula are all relevant, it would be difficult to infer which quantifiers should be added and where. (And as an additional possibility, we could just imagine that the variables are completely free and essentially become additional parameters to the anonymous predicate we're defining, but that doesn't fit in well with the Tuple Relational Calculus.) Prolog and Datalog do use a syntax that makes existential quantifiers implicit, but they are (in their basic forms) also limited to a language that 1) omits universal quantifiers, and 2) only allows formulas where existential quantifiers can always be pulled to being the outermost connective. Actually, when negation is added to Datalog, this stops being true and this implicit syntax starts to become ambiguous and confusing. Some implementations add an explicit existential and/or universal quantifier in such cases.

The upshot is, at the most fundamental level, all variables need to be bound, either by a quantifier or by the set comprehension syntax. There do exist various shorthands and conventions that are often used that can cloud this picture up, but ultimately every variable is introduced by some binding form.

Derek Elkins left SE
  • 12,179
  • 1
  • 30
  • 43