When to use the "there exists" quantifier in tuple relational calculus?

448 Views Asked by At

Let's say we're given the following relation: Sailors(sid, sname, rating)

And we have to answer the following query: The names of all sailors with a rating above 7.

What will be the tuple relational calculus query? Can it be this: $$\{P\ |\ S \in \text{Sailors}\ \land\ S.\text{rating} > 7\ \land\ S.\text{sname} = P.\text{sname} \}$$

According to my book, the correct query is:

$$\{P\ |\ \exists S \in \text{Sailors}(S.\text{rating} > 7\ \land\ S.\text{sname} = P.\text{sname})\}$$

Why is the second one correct and the first one wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

You don't introduce $S$ in the first expression. It just appears without explanation. $P$ is a dummy variable of the set-builder notation - the notation itself serves as its introduction. But $S$ has no defined meaning. If i encountered this, I would search the preceding material to see where $S$ was defined, and then consider you an idiot when I failed to find any introduction. There is nothing about set builder notation that specifies what $S$ refers to.

Other than being an object in your Sailor class, it is not clear what values $S$ could take on. Under certain formal logic systems, such an unclassified variable is considered to take on all possible values. In such a system, this would be interpreted as $$\{P\mid \forall S (S \in \text{Sailors}\land S.\text{rating} > 7 \land S.\text{sname} = P.\text{sname})\},$$ which almost certainly would be empty. But even in such systems, leaving off the $\forall S$ is considered bad form.

I personally also consider $$\{P\mid \exists S \in \text{Sailors}(S.\text{rating} > 7 \land S.\text{sname} = P.\text{sname})\}$$ to be bad form, but in a much less significant way. The mashing together of the "$S \in \text{Sailors}$" and the "$(...)$" leaves it not immediately clear whether the parenthesed portion is the predicate, or some qualifier to "$\text{Sailors}$", which makes reading it just a little more taxing. Preferable is to use punctuation to make it clear the $\in \text{Sailor}$ clause has ended, and the rest is the condition. Most commonly this is accomplished by either $$\{P\mid \exists S \in \text{Sailors}, S.\text{rating} > 7 \land S.\text{sname} = P.\text{sname}\}$$ or $$\{P\mid (\exists S \in \text{Sailors})(S.\text{rating} > 7 \land S.\text{sname} = P.\text{sname})\}$$

In any case, this expression uses $S$ as a dummy variable of the $\exists$ clause, given meaning by the clause, and not existing outside of it. How $S$ is to be quantified is now explicit. The condition has to hold only for some $S$ for $P$ to be included in the set, not for every $S$.