Relations

Relations and Their Properties

Definition of Relations

  • Relations are formal means to specify which elements from two or more sets are related to each other.

    For example, students who takes courses, there are relations between students and courses; integers and their divisors, there are relations between integers and divisors.

  • Let and be two sets. A binary relation from to is a subset of .

  • Generally, let be sets. An n-ary relation on these sets is a subset of .

  • means that .

Complementary and Inverse of Relations

  • Let be any binary relations, the complement of , is the binary relation defined by .
  • Any binary relation , has an inverse relation , which is defined by.

Functions as relations

  • A function is a special case of a relation from to .
  • Relations are a generalization of function.
    • Relations allow unmapped elements in .
    • Relations allow one-to-many mappings.
    • Relations also allow many-to-one and many-to-many mappings.

Relations on a Set

  • A binary from a set to itself is called a relation on the set ​.
  • A relation on a set A is a subset of ​.

Properties of Relations

Reflexivity

  • A relation is reflexive if .
  • A relation is irreflexive if its complementary relation is reflexive.

Symmetry

  • A binary relation on is symmetry if , that is if
  • A binary relation is antisymmetric if

Transitivity

  • A relation is transitive if .

Examples in Mathematics:

reflexivesymmetricantisymmetrictransitive
yesyesyesyes
noyesnono
noyesyesyes

Composition

The composition of two relations and , denoted by , is the relation from to containing all pairs such that there is one with and .

Power of a Relation

Composing the Parent relation with itself

Let be a binary relation on , then the power of the relation can be defined inductively by:

  • Basic Step:
  • Inductive Step:

Theorem: The relation on a set A is transitive if for .

n-ary Relations and Their Applications

n-ary Relations

  • An n-ary relation on sets , a subset .
  • The sets are called the domains of .
  • The degree of is .

Relational Database

Database

  • A database is viewed as a collection of records, each being a tuple of the form .
  • In order to uniquely identify tuples in a database, we need to specify a field , which is the primary key.
  • Some database may not have primary key, instead they use a composite key made up of multiple fields.

Relational Database

  • A model for databases, based on relations.
  • A domain is a primary key for the database if the relation R is functional in .
  • A composite key for the database is a set of domains , such that contains at most 1 n-tuple for each composite value.

Operations on n-ary relations

  • Selection
  • Projection
  • Join

Representing of Relations

Using Zero-One Matrices

We can represent a binary relation by an 0-1 matrix , let if .

We can see some relation characteristics in the zero-one matrix.

  • Reflexive: all 1 are on diagonal
  • Irreflexive: all 0 are on diagonal
  • Symmetric: all identical across diagonal
  • Antisymmetric: all 1 are across from 0.

Using Directed Graphs

A relation can be represented as a graph .

Closures of Relations

Closures

For any property X , the "X closure" of a set A is defined as the smallest superset of A that has the given property.

For example:

  • The reflexive closure of relation on is obtained by adding to for each , as .
  • The symmetric closure of is obtained by adding to , as .
  • The transitive closure or connectivity relation of is obtained by repeatedly adding to for each in .

Paths in Digraphs

A path of length from node to in the directed graph is a sequence of ordered pairs in .

  • An empty sequence of edges is considered a path of length 0 from a to a.
  • If any path from to exists, then we say that a is connected to .
  • A path of length from a to itself is called a circuit or a cycle.
  • There exists a path of length from to in if and only if .

Let R be a relation on a set , the connectivity relation consist of their pairs such that there is a path of length at least one from to in .

As consists of the pairs such that there is a path of length from to , it follows that is the union of all the sets .

Theorem: Let be a relation on a set , then equals the transitive closure of

But in fact if is a set with , and let be a relation on . Then

which is much easier to calculate.

Warshall's Algorithm

As we have seen, using the Theorem and its lemma, it is still difficult to calculate the transitive closure, so we have a algorithm:

procedure Warshall(M, n X n zero-one matrix)
W := M
for k:=1 to n
	for j:=1 to n
		for j:=1 to n
		w[ij] = w[ij] | (W[ik] & W[ki])
return W