Definition

Let and be sets. A binary relation from to is a subset of , where denotes Cartesian product

Functions as Relations

A function from a set to a set can be seen as a binary relation from to , where every element in is related to exactly one element in

Relations on a Set

A relation on a set is a relation from to , which is simply a subset of

Properties

Reflexive

A relation on a set is called reflexive if for every element .

Symmetric

A relation on a set is called symmetric if .

A relation on a set is called antisymmetric if for all , .

A relation on a set is called asymmetric if there is no , such that .

Transitive

A relation on a set is called transitive if

PropertySet Restriction
Reflexive
Non-reflexive
Symmetric
Antisymmetric
Asymmetric
Transitive
where

Combing Relations

Composition

Let be a relation from a set to a set , and a relation from to a set . The composite of and is the relation of ordered pairs , where , and for which there exists an element such that and . We denote the composite of and by

Power

Let be a relation on the set . The powers , are defined recursively by

The relation on a set is transitive if and only if for

-ary Relations

Definition

Let be sets. An -ary relation on these sets is a subset of . The sets are called the domains of the relation, and is called its degree

Operators

Selection

Let be an -ary relation and a condition that elements in may satisfy. Then the selection operator maps the -ary relation to the -ary relation of all -tuples from that satisfy the condition .

Projection

The projection where , maps the -tuple to the -tuple , where .

Join

Let be a relation of degree and a relation of degree . The join where and , is a relation of degree that consists of all -tuples , where the -tuple belongs to and the -tuple belongs to .

Association Rules from Data Mining

Count

The count of an itemset , denoted by , in a set of transaction , where is a positive integer, is the number of transactions that contain this itemset. That is

Support

The support of an itemset is the probability that is included in a randomly selected transaction from . That is,

Association Rule

If is a set of items and is a set of transactions, an association rule is an implication of the form , where and are disjoint subsets of . Use this notation we can define

and

Representation of Relations

Matrix Representation

Suppose that is a relation from to . Then we can use a matrix to represent the matrix, where

The matrix of a relation on a set, which is a square matrix, can be used to determine whether the relation has certain properties. For example,

  • is reflexive if all the elements on the main diagonal of are equal to
  • is symmetric if and only if is a symmetric matrix, i.e.

Since is a 0-1 matrix, we can apply Boolean operations on it:

  • , where is the Boolean product of 0-1 matrix (Pay attention to the order of and ! Otherwise due to the un-match matrix dimensions you cannot perform the matrix multiplication)
  • , where the first represents the power of relation, and the second is the Boolean power of 0-1 matrix

Directed Graph Representation

The relation on a set can be represented by the directed graph that has the elements of as its vertices and order pairs , where , as edges. This assignment sets up a one-to-one correspondence between the relations on a set and their directed graphs with as their set of vertices.

Similarly, this graph can also be used to determine whether the relation has various properties.

  • A relation is reflexive if and only if there is a loop at every vertex of the directed graph
  • A relation is symmetric if and only if every edge of the graph is bi-directional.
  • A relation is antisymmetric if and only if there are never two edges in opposite directions between distinct vertices.
  • A relation is transitive if and only if whenever there is an edge from a vertex to a vertex to a vertex , there is an edge from to . (completing a triangle where each side is a directed edge with the correct direction)

Closures of Relations

Definition

If is a relation on a set , it may or may not have some property , such as reflexivity, symmetry or transitivity. When does not enjoy property , we would like to find the smallest relation on with property that contains .

If is a relation on a set , then the closure of with respect to , if it exists, is

  • The relation on with property that contains
  • A subset of every subset of containing with property . (Minimum)

If there is a relation that is a subset of every relation containing with property , it must be unique.

  • Reflexive closure of :
  • Symmetric closure of : , where
  • Transitive closure of ? See below.

Paths in Directed Graphs

A path from to in the directed graph is a sequence of edges in , where and . This path is denoted by and has length .

In particular, we view the empty set of edges as a path of length zero from to . A path of length that begins and ends at the same vertex is called a circuit or cycle.

The term path also applies to relations. There is a path from to in if there is a sequence of elements with , and . Then we have the following theorem:

Let be a relation on a set . There is a path of length , where , from to if and only if

Transitive Closures

Connectivity Relation

Let be a relation on a set . The connectivity relation consists of these pairs such that there is a path of length at least one from to in .

Because consists of the pairs such that there is a path of length from to (See the last theorem in section Paths in Directed Graphs). It follows that is the union of all the sets . In other words

Now we can see that, the transitive closure of a relation equals the connectivity relation

Optimized Algorithm

How can be compute this relation since it may include ? To tackle with this issue, we introduce the following lemma, which is a natural result from The Pigeonhole Principle

Let be a set with elements, and let be a relation on . If there is a path of length at least one in from to , then there is such a path with length not exceeding . Moreover, when , if there is a path of length at least one in from to , then there is such a path with length not exceeding .

From this lemma, we can simplify the computation of as

In practice, we usually use matrix to represents these relations, so we can compute the 0-1 matrix of the transitive closure of by

Since the computation of a Boolean product takes , a fast Boolean power algorithm takes . As we can compute the Boolean product and the matrix union in a single step in the fast power algorithm, the total time complexity to compute the transitive closure takes

Warshall's Algorithm

This is just a Boolean version of Floyd algorithm. Given the matrix of the initial relation, the algorithm outputs a new matrix indicating the connectivity relation (i.e. transitive relation) of the initial relation.

function Warshall(A): 
	n = number of vertices 
	for k from 1 to n: 
		for i from 1 to n: 
			for j from 1 to n: 
				A[i][j] = A[i][j] or (A[i][k] and A[k][j]) 
	return A

Common Relations

Equivalence Relation Partially Ordered Set