Relational Algebra
Relational Algebra
What is Relation?
• I am sure that you are familiar with many relations such as “less than,” “is
parallel to,” “is a subset of,” and so on. In a certain sense, these relations
consider the existence or nonexistence of a certain connection between
pairs of objects taken in a definite order.
• Formally, we define a relation in terms of these “ordered pairs.”
• An ordered pair of elements a and b, where a is designated as the first
element and b as the second element, is denoted by (a, b). In particular,
• (a, b) = (c, d)
• if and only if a = c and b = d. Thus (a, b) = (b, a) unless a = b. This contrasts
with sets where the order of elements is irrelevant; for example, {3, 5} = {5,
3}.
Product Sets
• Consider two arbitrary sets A and B. The set of all ordered pairs (a, b)
where a ∈ A and b ∈ B is called the product, or Cartesian product, of A
and B. A short designation of this product is A × B, which is read “A
cross B.” By definition,
• A × B = {(a, b) | a ∈ A and b ∈ B}
• Example: Let A = {1, 2} and B = {a, b, c}. Then
• A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
• B × A = {(a, 1), (b, 1), (c, 1), (a, 2), (b, 2), (c, 2)}
• Also, A × A = {(1, 1), (1, 2), (2, 1), (2, 2)}
(Here A×B ≠ B ×A)
Number of Elements in Product Sets
In our previous example, n(A × B) = 6 = 2(3) = n(A)n(B)
• We can say n(A×B) = n(A)n(B)
Relations
• Let A and B be sets. A binary relation or, simply, relation from A to B is a
subset of A × B.
• Suppose R is a relation from A to B. Then R is a set of ordered pairs where
each first element comes from A and each second element comes from B.
That is, for each pair a ∈ A and b ∈ B, exactly one of the following is true:
1. (a, b) ∈ R; we then say “a is R-related to b”, written aRb.
2. (a, b) R; we then say “a is not R-related to b”, written aRb.
• If R is a relation from a set A to itself, that is, if R is a subset of = A×A, then
we say that R is a relation on A.
• The domain of a relation R is the set of all first elements of the ordered
pairs which belong to R, and the range is the set of second elements.
Example:
• A = {1, 2, 3} and B = {x, y, z}, and let R = {(1, y), (1, z), (3, y)}. Then R is a
relation from A to B since R is a subset of A × B. With respect to this
relation, 1Ry, 1Rz, 3Ry, but
• The domain of R is {1, 3} and the range is {y, z}
• Set inclusion ⊆ is a relation on any collection of sets. For, given any
pair of set A and B, either A ⊆ B or A B.
• A familiar relation on the set Z of integers is “m divides n.” A common
notation for this relation is to write m|n when m divides n. Thus 6 |
30 but
• Consider the set L of lines in the plane. Perpendicularity, written “⊥,”
is a relation on L. That is, given any pair of lines a and b, either a ⊥b
or . Similarly, “is parallel to,” written “||,” is a relation on L since
either
• Let A be any set. An important relation on A is that of equality, {(a, a)
| a ∈ A} which is usually denoted by “=.” This relation is also called
the identity or diagonal relation on A and it will also be denoted by A
or simply .
• Let A be any set. Then A × A and ∅ are subsets of A × A and hence are
relations on A called the universal relation and empty relation,
respectively.
Inverse Relation
• Let R be any relation from a set A to a set B. The inverse of R, denoted
by , is the relation from B to A which consists of those ordered pairs
which, when reversed, belong to R; that is,
• = {(b, a) | (a, b) ∈ R}
• For example, let A = {1, 2, 3} and B = {x, y, z}. Then the inverse of
• R = {(1, y), (1, z), (3, y)} is = {(y, 1), (z, 1), (y, 3)}
• Clearly, if R is any relation, then = R. Also, the domain and range of
are equal, respectively, to the range and domain of R. Moreover, if R is
a relation on A, then is also a relation on A.
Pictorial Representation of Relation
Directed Graph:
• Say relation R on the set A = {1, 2, 3, 4}: R = {(1, 2), (2, 2), (2, 4), (3, 2),
(3, 4), (4, 1), (4, 3)}
Pictures of Relations on Finite Sets
Suppose A and B are finite sets. There are two
ways of picturing a relation R from A to B.
1. Form a rectangular array (matrix) whose rows
are labeled by the elements of A and whose
columns are
I. labeled by the elements of B. Put a 1 or 0 in each
position of the array according as a ∈ A is or is not
II. related to b ∈ B. This array is called the matrix of
the relation.
1. Write down the elements of A and the elements of B in two disjoint
disks, and then draw an arrow from
I. a ∈ A to b ∈ B whenever a is related to b. This picture will be called the
arrow diagram of the relation.
II. A = {1, 2, 3}, B = {x, y, z} and R = {(1, y), (1, z), (3, y)}