G27
Self-checkedTier 1 9 min readdbms.tuple-relational-calculus

Tuple relational calculus

The tuple relational calculus: tuple variables ranging over relations, atoms and formulas with connectives and the quantifiers there exists and for all, free and bound variables, queries of the form { t | P(t) }, translating every relational algebra operator (selection, projection, union, difference, product, join, division) into calculus, queries with negation and universal quantification, safe versus unsafe expressions, and the equivalence of safe calculus with relational algebra.

Why it exists

Relational algebra says how to compute an answer (a sequence of operators). The relational calculus says what the answer is: a logical condition that the tuples of the answer must satisfy. SQL is based on this declarative idea. GATE asks: what does this calculus expression return, write a query in calculus, which expressions are safe, translate between algebra and calculus.

Prerequisites

You need relational algebra (relational algebra) and first-order logic with quantifiers (the logic course).

Precise definitions

A tuple variable tt takes tuples as values. The range of a variable is given by an atom R(t)R(t) or t∈Rt \in R.

Atoms:

  • R(t)R(t) (or t∈Rt \in R): tt is a tuple of relation RR;
  • t.A θ s.Bt.A \,\theta\, s.B or t.A θ ct.A \,\theta\, c, where θ∈{=,≠,<,≤,>,≥}\theta \in \{=, \ne, <, \le, >, \ge\} and cc is a constant.

Formulas are built from atoms with ∧,∨,¬,⇒\wedge, \vee, \neg, \Rightarrow and the quantifiers ∃t (P)\exists t\,(P) ("there is a tuple tt such that PP") and ∀t (P)\forall t\,(P) ("for every tuple tt, PP"). The rule ⇒\Rightarrow: P⇒Q≡¬P∨QP \Rightarrow Q \equiv \neg P \vee Q. The quantifiers are related by ∀t (P)≡¬∃t (¬P)\forall t\,(P) \equiv \neg\exists t\,(\neg P).

A variable is bound if a quantifier introduces it, otherwise free. A query has the form

{ t∣P(t) }\{\, t \mid P(t) \,\}

where tt is the only free variable of the formula PP. The answer is the set of all tuples tt for which P(t)P(t) is true. To keep the answer finite the formula must be safe (see below).

How it works

Reading calculus queries

The four queries run on the sample database (their answers were computed by evaluating the formula tuple by tuple, and each was compared with the SQL query on a real engine):

Queries in tuple relational calculus: start

Computed, not typed
{ t | t ∈ Student ∧ t.dept = 'CS' }
answer (4 tuples)4 tuples
sidsnamedeptage
1AshaCS20
3ChenCS21
5EshaCS23
8HariCS20

Step 0

The simplest form: t ranges over Student and the condition selects. This is the selection σ dept='CS' (Student). The answer is every tuple t that makes the formula true.

0 / 3
computed by script: the SQL statements are executed by SQLite, the calculus formulas are evaluated over a finite domain (scripts/db_sql.py, scripts/db_lib.py). python3 scripts/gen-db2-traces.py
  1. {t∣t∈Student∧t.dept=’CS’}\{t \mid t \in \text{Student} \wedge t.\text{dept} = \text{'CS'}\}: a plain selection.
  2. {t∣∃s∈Student ∃e∈Enrolled (s.sid=e.sid∧e.cid=’C1’∧t.sname=s.sname)}\{t \mid \exists s \in \text{Student}\ \exists e \in \text{Enrolled}\ (s.\text{sid} = e.\text{sid} \wedge e.\text{cid} = \text{'C1'} \wedge t.\text{sname} = s.\text{sname})\}: the result tuple tt has a single attribute sname; the quantified variables stand for the joined tuples.
  3. {t∣t∈Student∧¬∃e∈Enrolled (e.sid=t.sid)}\{t \mid t \in \text{Student} \wedge \neg\exists e \in \text{Enrolled}\,(e.\text{sid} = t.\text{sid})\}: negation of an existential quantifier gives "no such tuple".
  4. {t∣t∈Student∧∀c∈Teaches (c.iid≠10∨∃e∈Enrolled (e.sid=t.sid∧e.cid=c.cid))}\{t \mid t \in \text{Student} \wedge \forall c \in \text{Teaches}\,(c.\text{iid} \ne 10 \vee \exists e \in \text{Enrolled}\,(e.\text{sid} = t.\text{sid} \wedge e.\text{cid} = c.\text{cid}))\}: the universal quantifier expresses "for all courses taught by instructor 10, the student is enrolled" (the part c.iid≠10∨…c.\text{iid} \ne 10 \vee \ldots is the implication "if cc is taught by 10 then ...").

Algebra to calculus

Every operator of relational algebra has a calculus counterpart (each was checked by evaluating the formula for all candidate tuples over a small domain and comparing with the operator):

algebratuple calculus
σp(R)\sigma_p(R){t∣R(t)∧p(t)}\{t \mid R(t) \wedge p(t)\}
πA,B(R)\pi_{A,B}(R){t∣∃r (R(r)∧t.A=r.A∧t.B=r.B)}\{t \mid \exists r\,(R(r) \wedge t.A = r.A \wedge t.B = r.B)\}
R∪SR \cup S{t∣R(t)∨S(t)}\{t \mid R(t) \vee S(t)\}
R−SR - S{t∣R(t)∧¬S(t)}\{t \mid R(t) \wedge \neg S(t)\}
R×SR \times S{t∣∃r ∃s (R(r)∧S(s)∧t=(r,s))}\{t \mid \exists r\,\exists s\,(R(r) \wedge S(s) \wedge t = (r, s))\} (each attribute of tt equals the matching attribute of rr or ss)
R(A,B)⋈S(B,C)R(A, B) \bowtie S(B, C){t∣∃r ∃s (R(r)∧S(s)∧r.B=s.B∧t.A=r.A∧t.B=r.B∧t.C=s.C)}\{t \mid \exists r\,\exists s\,(R(r) \wedge S(s) \wedge r.B = s.B \wedge t.A = r.A \wedge t.B = r.B \wedge t.C = s.C)\}
R(X,Y)÷S(Y)R(X, Y) \div S(Y){t∣∃r (R(r)∧t.X=r.X)∧∀s (S(s)⇒∃r′ (R(r′)∧r′.X=t.X∧r′.Y=s.Y))}\{t \mid \exists r\,(R(r) \wedge t.X = r.X) \wedge \forall s\,(S(s) \Rightarrow \exists r'\,(R(r') \wedge r'.X = t.X \wedge r'.Y = s.Y))\}

Differences in style: calculus has no order of operations, no intermediate relations and expresses "not" and "for all" directly; algebra needs set difference and division for them.

Safety

Consider {t∣¬(t∈R)}\{t \mid \neg(t \in R)\}. If RR has two tuples, the answer is "every possible tuple except those two": its size depends on how many values the attributes may take. With values from 1..k1..k the answer has k2−2k^2 - 2 tuples:

An unsafe calculus expression: start

Computed by a script, not typed
domaintuples satisfying { t | ¬(t ∈ R) }k² − |R|
domain of 3 values
domain of 4 values
domain of 5 values
domain of 6 values

Step 0

R has 2 tuples. The expression { t | ¬(t ∈ R) } asks for all tuples that are not in R; their number depends on the (unbounded) domain. Safe expressions only produce values that appear in the database.

0 / 4
computed by script: the SQL statements are executed by SQLite, the calculus formulas are evaluated over a finite domain (scripts/db_sql.py, scripts/db_lib.py). python3 scripts/gen-db2-traces.py

An expression is safe if it produces only tuples whose values come from the database (or the query), so the answer is finite and does not depend on the domain. Typical unsafe expressions: a lone negation ¬R(t)\neg R(t), a disjunction in which the two branches do not restrict the same variables, a free variable that is not bounded by a positive range atom. The practical rule: every free variable and every quantified variable must be bounded by a positive atom R(t)R(t).

Codd's theorem (quoted): the relational algebra and the safe tuple relational calculus have the same expressive power. Equivalent statements: every algebra query can be written as a safe calculus formula (the table above), and every safe calculus formula can be translated to algebra (with product, selection, projection, difference and division as needed). A language with this power is called relationally complete; SQL is relationally complete (and stronger: it has aggregates and arithmetic).

The domain relational calculus

In the domain calculus variables range over attribute values instead of tuples: {⟨a,b⟩∣⟨a,b,c⟩∈R∧c>5}\{\langle a, b \rangle \mid \langle a, b, c \rangle \in R \wedge c > 5\}. It is equivalent in power to the tuple calculus (restricted to safe expressions). It is treated, together with safety, in domain calculus and safety.

Worked examples

EX 1Read an expression

Easy

{t∣t∈Course∧t.credits>3}\{t \mid t \in \text{Course} \wedge t.\text{credits} > 3\}: the courses with more than three credits (C1 and C5 in the sample database). It is σcredits>3(Course)\sigma_{\text{credits}>3}(\text{Course}).

EX 2Free and bound variables

Easy

In {t∣t∈Student∧∃e∈Enrolled (e.sid=t.sid)}\{t \mid t \in \text{Student} \wedge \exists e \in \text{Enrolled}\,(e.\text{sid} = t.\text{sid})\} the variable tt is free (it is the answer), ee is bound by ∃\exists. The answer consists of the students that have at least one enrolment.

EX 3Translate a sentence

Medium

Names of students enrolled in no course of the CS department. {t∣∃s∈Student (t.sname=s.sname∧¬∃e∈Enrolled ∃c∈Course (e.sid=s.sid∧e.cid=c.cid∧c.dept=’CS’))}\{t \mid \exists s \in \text{Student}\,(t.\text{sname} = s.\text{sname} \wedge \neg\exists e \in \text{Enrolled}\ \exists c \in \text{Course}\,(e.\text{sid} = s.\text{sid} \wedge e.\text{cid} = c.\text{cid} \wedge c.\text{dept} = \text{'CS'}))\}. In algebra this needs a set difference between all student names and the names of those with a CS enrolment.

EX 4Universal quantifier from existential

Medium

∀c (P(c))≡¬∃c (¬P(c))\forall c\,(P(c)) \equiv \neg\exists c\,(\neg P(c)). Query 4 above can therefore be written with two nested negations: "there is no course of instructor 10 for which the student has no enrolment". This is the double NOT EXISTS pattern of SQL.

EX 5Typical questions

GATE level

(a) "Which expression is unsafe?" One that can return infinitely many tuples, for example {t∣¬R(t)}\{t \mid \neg R(t)\} or {t∣t.A>5}\{t \mid t.A > 5\} without a range for tt. (b) "What does {t∣R(t)∧∀s (S(s)⇒…)}\{t \mid R(t) \wedge \forall s\,(S(s) \Rightarrow \ldots)\} express?" A division-like 'for all' query. (c) "The calculus and the algebra are:" equivalent in power (for safe expressions). (d) "Calculus is procedural or declarative?" Declarative. (e) "Which quantifier gives 'there exists at least one'?" ∃\exists. (f) "What is the result of {t∣∃s∈R (t.A=s.A)}\{t \mid \exists s \in R\,(t.A = s.A)\}?" The projection πA(R)\pi_A(R).

Cheat box

Cheat box

  • Query {t∣P(t)}\{t \mid P(t)\}; tt is the only free variable; answer = tuples satisfying PP.
  • ∀x P≡¬∃x ¬P\forall x\,P \equiv \neg\exists x\,\neg P; P⇒Q≡¬P∨QP \Rightarrow Q \equiv \neg P \vee Q.
  • σ\sigma = range atom + condition; π\pi = ∃\exists and equalities; ∪\cup = ∨\vee; −- = ∧¬\wedge \neg; ⋈\bowtie = two ∃\exists; ÷\div = ∀\forall with implication.
  • Safe expression: every variable bounded by a positive range atom; unsafe: ¬R(t)\neg R(t), unbounded disjunction.
  • Codd: safe TRC ≡\equiv relational algebra.

Traps and GATE patterns

Connections

SQL queries with EXISTS, NOT EXISTS and IN are calculus in disguise (nested queries, SQL basics); the algebra is the operational counterpart (relational algebra).

PYQs

9 previous year questions from your book. I re-solved each one myself (2 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2026 · Set 1 · MCQ · 2 marksQ1 · page 388 of the book
Consider a relational database schema with two
relations R(P, Q) and S(X, Y)
Let E= {⟨u⟩|∃v∃w⟨u, v⟩∈R∧⟨v, w⟩∈S} be a
tuple relational calculus expression.
Which one of the following relational algebraic
expressions is equivalent to E ?
  • (a)ΠP(R⋈R.P=S.XS)
  • (b)ΠP(S⋈S.X=R.QR)
  • (c)ΠP(R⋈R.P=S.YS)
  • (d)ΠP(S⋈S.Y=R.QR)
GATE 2025 · Set 1 · MCQQ2 · page 388 of the book
Consider two relations describing teams and players in
a sports league: teams (tid,tname): tid, tname are
team-id and team-name, respectively.players(pid,
pname,tid): pid, pname, and tid denote player-id,
playername and the team-id of the player, respectively.
Which ONE of the following tuple relational calculus
queries returns the name of the players who play for the
team having name as 'MI'?
  • (a){ p. pname | p∈players∧∃t (t∈teams∧p.tid = t.tid∧t.tname = 'MI')
  • (b){ p. pname | p∈teams∧∃t (t∈players∧p.tid = t.tid∧t.tname ='MI')}
  • (c){ p. pname | p∈players∧∃t (t∈teams∧t.tname = 'MI')}
  • (d){ p. pname | p∈teams∧∃t (t∈players∧t.tname = 'MI')}
GATE 2017 · Set 1 · MCQ · 1 markQ10 · page 390 of the book
Consider a database that has the relation schemas
EMP(Empld,
EmpName,
Deptld)
and
DEPT(DeptName, Deptld). Note that the Deptldcan  be
permitted to a NULL in the relation EMP. Consider the
following queries on the database expressed in tuple
relational calculus.

(I) {t|∃u ε EMP(t[EmpName) = u[EmpName] Λ ∀

         ∨ε DEPT(t[Deptld] ≠ V[Deptld]))}

(II) {t|∃u ε EMP(t[EmpName) = u[EmpName] Λ ∃∨ ε
DEPT(t[Deptld] ≠V[Deptld]))}

(III) {t|∃u ε EMP(t[EmpNmae) = u[EmpName] Λ ∃∨ ε
DEPT(t[Deptld] =V[Deptld]))}

Which of the above queries are safe?
  • (a)I and II only
  • (b)I and III only
  • (c)II and III only
  • (d)I, II and III.
GATE 2013 · MCQ · 2 marksQ17 · page 391 of the book
Consider the following relation schema

Students(rollno:integer, sname: string)

Courses(courseno:integer,cname: string)

Registration (rollno: integer, courseno: integer, percent:
real)

Which of the following queries are equivalent to this query
in English?

"Find the distinct names of all students who score more
than 90% in the course numbered 107".

(I)  SELECT DISTINCT S.sname

FROM Students as S, Registration as R

WHERE R.rollno = S. rollno AND R.courseno = 107 AND
R.percent> 90

(II) πsname(σcourseno= 107 Λ percent> 90 (Registration ⋈Students))

(III) {T|∃S ε Students, ∃R ε Registration (S.rollno =
R.rollno Λ R.courseno = 107 Λ R.percent> 90 Λ T.sname
= S.sname)}

(IV) {<SN>|∃SR∃RP(<SR,SN>∈Students∧<SR,107,RP>∈
Registration∧ RP>90)}
  • (a)I, II, III and IV
  • (b)I, II and III only
  • (c)I, II and IV only
  • (d)II, III and IV only
GATE 2009 · MCQ · 2 marksQ21 · page 392 of the book
Let R and S be relational schemes such that R = {a, b,
c} and S = {c}. Now consider the following queries on
the database:
         1  πR-S(r) -πR-S(πR-S(r) × s-πR-S,S(r))

         2. {t|t∈πR-S(r) ∧∀u∈s(∃v∈r(u= v[S] ∧t=
v[R-S]))}

        3. {t|t∈πR-S(r) ∧∀v∈r(∃u∈s(u= v[S] ∧t=
v[R-S]))}

4. Select R.a, R.b

  From R, S
 Where R.c = S.c

Which of the above queries are equivalent?
  • (a)1 and 2
  • (b)1 and 3
  • (c)2 and 4
  • (d)3 and 4
GATE 2008 · MCQ · 1 markQ23 · page 392 of the book
Which of the following tuple relational calculus
expression(s) is/are equivalent to ∀t ∈ r (P(t))?

I. ¬∃t ∈ r (P(t))
 II. ∃t ∉ r (P(t))
 III. ¬∃t ∈ r (¬P(t))
 IV. ∃t ∉ r (¬P(t))
  • (a)I only
  • (b)II only
  • (c)III only
  • (d)III and IV only
GATE 2008 · MCQ · 2 marksQ24 · page 392 of the book
Consider the following relational schema:

• Student(school-id, sch-roll-no, sname, saddress)
 • School(school-id, sch-name, sch-address, sch-phone)
 • Enrolment(school-id, sch-roll-no, erollno, examname)
 • ExamResult(erollno, examname, marks)

Consider the following tuple relational calculus query.

DATABASE MANAGEMENT  SYSTEM

{ t | ∃E ∈ Enrolment ( t = E.school-id ∧
 |{ x | x ∈ Enrolment ∧x.school-id = t ∧
 (∃B ∈ExamResult ( B.erollno =
x.erollno∧B.examname = x.examname∧B.marks> 35 ))
}| ÷ |{ x | x ∈ Enrolment ∧x.school-id = t }| * 100 > 35
) }

If a student needs to score more than 35 marks to pass
an exam, what does the query return?
  • (a)The empty set
  • (b)schools with more than 35% of its students enrolled in some exam or the other
  • (c)Schools with a pass percentage above 35% over all exams taken together
  • (d)schools with a pass percentage above 35% over each exam
GATE 2007 · MCQ · 2 marksQ26 · page 393 of the book
Consider the relation employee(name, sex,
supervisorName) with name as the key.
supervisorName gives the name of the supervisor of the
employee under consideration. What does the following
Tuple Relational Calculus query produce?

 {e.name | employee(e) ∧ }

(∀x) [ ¬employee(x) ∨x.supervisorName ≠ e.name
∨x.sex = "male" ] }
  • (a)Names of employees with a male supervisor.
  • (b)Names of employees with no immediate male subordinates.
  • (c)Names of employees with no immediate female subordinates.
  • (d)Names of employees with a female supervisor.
GATE 2006 · MCQ · 1 markQ30 · page 394 of the book
Which of the following relational query languages have
the same expressive power?
1. Relational algebra
2. Tuple relational calculus restricted to safe
Expressions
3. Domain relational calculus restricted to safe
expressions
  • (a)II and III only
  • (b)I and II only
  • (c)I and III only
  • (d)I, II and III

Self-check

Question 1

What does {t∣t∈R∧¬∃s∈S (s.A=t.A)}\{t \mid t \in R \wedge \neg\exists s \in S\,(s.A = t.A)\} return?

Show answer

The tuples of RR whose AA-value does not occur in SS: RR minus the tuples that match SS on AA (an anti-join).

Question 2

Why is {t∣¬R(t)}\{t \mid \neg R(t)\} unsafe?

Show answer

It denotes all tuples not in RR; there are infinitely many (or as many as the domain allows), so the answer is not determined by the database.

Question 3

Which quantifier pattern expresses relational division?

Show answer

∀s (S(s)⇒∃r (…))\forall s\,(S(s) \Rightarrow \exists r\,(\ldots)): for every tuple of the divisor there is a matching tuple in the dividend.

Question 4

Is the tuple relational calculus procedural?

Show answer

No, it is declarative: it states what the answer must satisfy, not how to compute it.

Revision card

One-screen revision

  • {t∣P(t)}\{t \mid P(t)\} with free tt; atoms R(t)R(t), t.A θ s.Bt.A\,\theta\,s.B; ∃\exists, ∀\forall.
  • ∀=¬∃¬\forall = \neg\exists\neg; ⇒\Rightarrow = ¬∨\neg \vee.
  • Algebra operators map to calculus formulas; division uses ∀\forall.
  • Safe = bounded by positive range atoms; Codd's theorem: safe calculus = algebra.

References

  • ·Silberschatz, Korth, Sudarshan, Database System Concepts (7th edition), the section on the tuple relational calculus (in recent editions it is an online or appendix chapter; older editions have it in Chapter 3 or 6)
  • ·Elmasri, Navathe, Fundamentals of Database Systems (7th edition), Section 8.6 (the tuple relational calculus)

Verification

scripts/enum-checks/db_sqlcheck.py: the calculus translation of every relational algebra operator on this page (selection, projection, union, difference, product, natural join, division) was evaluated by its semantics, namely testing the formula for every candidate tuple over the finite domain {1, 2, 3}, and equals the result of the corresponding operator of scripts/db_lib.py on 300 random relations; the four example queries were evaluated by iterating over the tuples of the sample database and agree with the SQL queries run on SQLite; for the unsafe expression { t | not (t in R) } the number of satisfying tuples over a domain of k values was computed for k = 3 to 6 and equals k^2 - |R|. Codd's theorem (safe calculus and relational algebra have the same expressive power) is a textbook theorem, quoted and not machine-proved. Textbook chapter references are from memory and differ between editions. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and re-derived against the textbook definitions and the sample database. DEFECT FOUND AND FIXED: a forward reference to a page that is now built was turned into a link. Status raised to self-checked; verified needs a textbook or human check.

last verified: never